##// END OF EJS Templates
remove trailing white-spaces from test/functional/watchers_controller_test.rb....
Toshi MARUYAMA -
r6506:e5ccceae184d
parent child
Show More
@@ -1,89 +1,89
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'watchers_controller'
19 require 'watchers_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class WatchersController; def rescue_action(e) raise e end; end
22 class WatchersController; def rescue_action(e) raise e end; end
23
23
24 class WatchersControllerTest < ActionController::TestCase
24 class WatchersControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
26 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
27
27
28 def setup
28 def setup
29 @controller = WatchersController.new
29 @controller = WatchersController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 User.current = nil
32 User.current = nil
33 end
33 end
34
34
35 def test_get_watch_should_be_invalid
35 def test_get_watch_should_be_invalid
36 @request.session[:user_id] = 3
36 @request.session[:user_id] = 3
37 get :watch, :object_type => 'issue', :object_id => '1'
37 get :watch, :object_type => 'issue', :object_id => '1'
38 assert_response 405
38 assert_response 405
39 end
39 end
40
40
41 def test_watch
41 def test_watch
42 @request.session[:user_id] = 3
42 @request.session[:user_id] = 3
43 assert_difference('Watcher.count') do
43 assert_difference('Watcher.count') do
44 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
44 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
45 assert_response :success
45 assert_response :success
46 assert @response.body.include?('$$(".issue-1-watcher")')
46 assert @response.body.include?('$$(".issue-1-watcher")')
47 end
47 end
48 assert Issue.find(1).watched_by?(User.find(3))
48 assert Issue.find(1).watched_by?(User.find(3))
49 end
49 end
50
50
51 def test_watch_should_be_denied_without_permission
51 def test_watch_should_be_denied_without_permission
52 Role.find(2).remove_permission! :view_issues
52 Role.find(2).remove_permission! :view_issues
53 @request.session[:user_id] = 3
53 @request.session[:user_id] = 3
54 assert_no_difference('Watcher.count') do
54 assert_no_difference('Watcher.count') do
55 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
55 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
56 assert_response 403
56 assert_response 403
57 end
57 end
58 end
58 end
59
59
60 def test_unwatch
60 def test_unwatch
61 @request.session[:user_id] = 3
61 @request.session[:user_id] = 3
62 assert_difference('Watcher.count', -1) do
62 assert_difference('Watcher.count', -1) do
63 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
63 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
64 assert_response :success
64 assert_response :success
65 assert @response.body.include?('$$(".issue-2-watcher")')
65 assert @response.body.include?('$$(".issue-2-watcher")')
66 end
66 end
67 assert !Issue.find(1).watched_by?(User.find(3))
67 assert !Issue.find(1).watched_by?(User.find(3))
68 end
68 end
69
69
70 def test_new_watcher
70 def test_new_watcher
71 @request.session[:user_id] = 2
71 @request.session[:user_id] = 2
72 assert_difference('Watcher.count') do
72 assert_difference('Watcher.count') do
73 xhr :post, :new, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
73 xhr :post, :new, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
74 assert_response :success
74 assert_response :success
75 assert_select_rjs :replace_html, 'watchers'
75 assert_select_rjs :replace_html, 'watchers'
76 end
76 end
77 assert Issue.find(2).watched_by?(User.find(4))
77 assert Issue.find(2).watched_by?(User.find(4))
78 end
78 end
79
79
80 def test_remove_watcher
80 def test_remove_watcher
81 @request.session[:user_id] = 2
81 @request.session[:user_id] = 2
82 assert_difference('Watcher.count', -1) do
82 assert_difference('Watcher.count', -1) do
83 xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
83 xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
84 assert_response :success
84 assert_response :success
85 assert_select_rjs :replace_html, 'watchers'
85 assert_select_rjs :replace_html, 'watchers'
86 end
86 end
87 assert !Issue.find(2).watched_by?(User.find(3))
87 assert !Issue.find(2).watched_by?(User.find(3))
88 end
88 end
89 end
89 end
General Comments 0
You need to be logged in to leave comments. Login now