##// END OF EJS Templates
code format clean up WatchersControllerTest...
Toshi MARUYAMA -
r12120:424393c28cd3
parent child
Show More
@@ -1,195 +1,197
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class WatchersControllerTest < ActionController::TestCase
21 21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
22 22 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
23 23
24 24 def setup
25 25 User.current = nil
26 26 end
27 27
28 28 def test_watch_a_single_object
29 29 @request.session[:user_id] = 3
30 30 assert_difference('Watcher.count') do
31 31 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
32 32 assert_response :success
33 33 assert_include '$(".issue-1-watcher")', response.body
34 34 end
35 35 assert Issue.find(1).watched_by?(User.find(3))
36 36 end
37 37
38 38 def test_watch_a_collection_with_a_single_object
39 39 @request.session[:user_id] = 3
40 40 assert_difference('Watcher.count') do
41 41 xhr :post, :watch, :object_type => 'issue', :object_id => ['1']
42 42 assert_response :success
43 43 assert_include '$(".issue-1-watcher")', response.body
44 44 end
45 45 assert Issue.find(1).watched_by?(User.find(3))
46 46 end
47 47
48 48 def test_watch_a_collection_with_multiple_objects
49 49 @request.session[:user_id] = 3
50 50 assert_difference('Watcher.count', 2) do
51 51 xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3']
52 52 assert_response :success
53 53 assert_include '$(".issue-bulk-watcher")', response.body
54 54 end
55 55 assert Issue.find(1).watched_by?(User.find(3))
56 56 assert Issue.find(3).watched_by?(User.find(3))
57 57 end
58 58
59 59 def test_watch_should_be_denied_without_permission
60 60 Role.find(2).remove_permission! :view_issues
61 61 @request.session[:user_id] = 3
62 62 assert_no_difference('Watcher.count') do
63 63 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
64 64 assert_response 403
65 65 end
66 66 end
67 67
68 68 def test_watch_invalid_class_should_respond_with_404
69 69 @request.session[:user_id] = 3
70 70 assert_no_difference('Watcher.count') do
71 71 xhr :post, :watch, :object_type => 'foo', :object_id => '1'
72 72 assert_response 404
73 73 end
74 74 end
75 75
76 76 def test_watch_invalid_object_should_respond_with_404
77 77 @request.session[:user_id] = 3
78 78 assert_no_difference('Watcher.count') do
79 79 xhr :post, :watch, :object_type => 'issue', :object_id => '999'
80 80 assert_response 404
81 81 end
82 82 end
83 83
84 84 def test_unwatch
85 85 @request.session[:user_id] = 3
86 86 assert_difference('Watcher.count', -1) do
87 87 xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2'
88 88 assert_response :success
89 89 assert_include '$(".issue-2-watcher")', response.body
90 90 end
91 91 assert !Issue.find(1).watched_by?(User.find(3))
92 92 end
93 93
94 94 def test_unwatch_a_collection_with_multiple_objects
95 95 @request.session[:user_id] = 3
96 96 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
97 97 Watcher.create!(:user_id => 3, :watchable => Issue.find(3))
98 98
99 99 assert_difference('Watcher.count', -2) do
100 100 xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3']
101 101 assert_response :success
102 102 assert_include '$(".issue-bulk-watcher")', response.body
103 103 end
104 104 assert !Issue.find(1).watched_by?(User.find(3))
105 105 assert !Issue.find(3).watched_by?(User.find(3))
106 106 end
107 107
108 108 def test_new
109 109 @request.session[:user_id] = 2
110 110 xhr :get, :new, :object_type => 'issue', :object_id => '2'
111 111 assert_response :success
112 112 assert_match /ajax-modal/, response.body
113 113 end
114 114
115 115 def test_new_for_new_record_with_project_id
116 116 @request.session[:user_id] = 2
117 117 xhr :get, :new, :project_id => 1
118 118 assert_response :success
119 119 assert_equal Project.find(1), assigns(:project)
120 120 assert_match /ajax-modal/, response.body
121 121 end
122 122
123 123 def test_new_for_new_record_with_project_identifier
124 124 @request.session[:user_id] = 2
125 125 xhr :get, :new, :project_id => 'ecookbook'
126 126 assert_response :success
127 127 assert_equal Project.find(1), assigns(:project)
128 128 assert_match /ajax-modal/, response.body
129 129 end
130 130
131 131 def test_create
132 132 @request.session[:user_id] = 2
133 133 assert_difference('Watcher.count') do
134 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
134 xhr :post, :create, :object_type => 'issue', :object_id => '2',
135 :watcher => {:user_id => '4'}
135 136 assert_response :success
136 137 assert_match /watchers/, response.body
137 138 assert_match /ajax-modal/, response.body
138 139 end
139 140 assert Issue.find(2).watched_by?(User.find(4))
140 141 end
141 142
142 143 def test_create_multiple
143 144 @request.session[:user_id] = 2
144 145 assert_difference('Watcher.count', 2) do
145 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
146 xhr :post, :create, :object_type => 'issue', :object_id => '2',
147 :watcher => {:user_ids => ['4', '7']}
146 148 assert_response :success
147 149 assert_match /watchers/, response.body
148 150 assert_match /ajax-modal/, response.body
149 151 end
150 152 assert Issue.find(2).watched_by?(User.find(4))
151 153 assert Issue.find(2).watched_by?(User.find(7))
152 154 end
153 155
154 156 def test_autocomplete_on_watchable_creation
155 157 @request.session[:user_id] = 2
156 158 xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook'
157 159 assert_response :success
158 160 assert_select 'input', :count => 4
159 161 assert_select 'input[name=?][value=1]', 'watcher[user_ids][]'
160 162 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
161 163 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
162 164 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
163 165 end
164 166
165 167 def test_autocomplete_on_watchable_update
166 168 @request.session[:user_id] = 2
167 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue', :project_id => 'ecookbook'
169 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2',
170 :object_type => 'issue', :project_id => 'ecookbook'
168 171 assert_response :success
169 172 assert_select 'input', :count => 3
170 173 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
171 174 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
172 175 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
173
174 176 end
175 177
176 178 def test_append
177 179 @request.session[:user_id] = 2
178 180 assert_no_difference 'Watcher.count' do
179 181 xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook'
180 182 assert_response :success
181 183 assert_include 'watchers_inputs', response.body
182 184 assert_include 'issue[watcher_user_ids][]', response.body
183 185 end
184 186 end
185 187
186 188 def test_remove_watcher
187 189 @request.session[:user_id] = 2
188 190 assert_difference('Watcher.count', -1) do
189 191 xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
190 192 assert_response :success
191 193 assert_match /watchers/, response.body
192 194 end
193 195 assert !Issue.find(2).watched_by?(User.find(3))
194 196 end
195 197 end
General Comments 0
You need to be logged in to leave comments. Login now