Mercurial > hg > soundsoftware-site
comparison test/functional/watchers_controller_test.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
54 end | 54 end |
55 assert Issue.find(1).watched_by?(User.find(3)) | 55 assert Issue.find(1).watched_by?(User.find(3)) |
56 assert Issue.find(3).watched_by?(User.find(3)) | 56 assert Issue.find(3).watched_by?(User.find(3)) |
57 end | 57 end |
58 | 58 |
59 def test_watch_a_news_module_should_add_watcher | |
60 @request.session[:user_id] = 7 | |
61 assert_not_nil m = Project.find(1).enabled_module('news') | |
62 | |
63 assert_difference 'Watcher.count' do | |
64 xhr :post, :watch, :object_type => 'enabled_module', :object_id => m.id.to_s | |
65 assert_response :success | |
66 end | |
67 assert m.reload.watched_by?(User.find(7)) | |
68 end | |
69 | |
70 def test_watch_a_private_news_module_without_permission_should_fail | |
71 @request.session[:user_id] = 7 | |
72 assert_not_nil m = Project.find(2).enabled_module('news') | |
73 | |
74 assert_no_difference 'Watcher.count' do | |
75 xhr :post, :watch, :object_type => 'enabled_module', :object_id => m.id.to_s | |
76 assert_response 403 | |
77 end | |
78 end | |
79 | |
59 def test_watch_should_be_denied_without_permission | 80 def test_watch_should_be_denied_without_permission |
60 Role.find(2).remove_permission! :view_issues | 81 Role.find(2).remove_permission! :view_issues |
61 @request.session[:user_id] = 3 | 82 @request.session[:user_id] = 3 |
62 assert_no_difference('Watcher.count') do | 83 assert_no_difference('Watcher.count') do |
63 xhr :post, :watch, :object_type => 'issue', :object_id => '1' | 84 xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
129 end | 150 end |
130 | 151 |
131 def test_create | 152 def test_create |
132 @request.session[:user_id] = 2 | 153 @request.session[:user_id] = 2 |
133 assert_difference('Watcher.count') do | 154 assert_difference('Watcher.count') do |
134 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} | 155 xhr :post, :create, :object_type => 'issue', :object_id => '2', |
156 :watcher => {:user_id => '4'} | |
135 assert_response :success | 157 assert_response :success |
136 assert_match /watchers/, response.body | 158 assert_match /watchers/, response.body |
137 assert_match /ajax-modal/, response.body | 159 assert_match /ajax-modal/, response.body |
138 end | 160 end |
139 assert Issue.find(2).watched_by?(User.find(4)) | 161 assert Issue.find(2).watched_by?(User.find(4)) |
140 end | 162 end |
141 | 163 |
142 def test_create_multiple | 164 def test_create_multiple |
143 @request.session[:user_id] = 2 | 165 @request.session[:user_id] = 2 |
144 assert_difference('Watcher.count', 2) do | 166 assert_difference('Watcher.count', 2) do |
145 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']} | 167 xhr :post, :create, :object_type => 'issue', :object_id => '2', |
168 :watcher => {:user_ids => ['4', '7']} | |
146 assert_response :success | 169 assert_response :success |
147 assert_match /watchers/, response.body | 170 assert_match /watchers/, response.body |
148 assert_match /ajax-modal/, response.body | 171 assert_match /ajax-modal/, response.body |
149 end | 172 end |
150 assert Issue.find(2).watched_by?(User.find(4)) | 173 assert Issue.find(2).watched_by?(User.find(4)) |
160 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | 183 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' |
161 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | 184 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' |
162 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | 185 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' |
163 end | 186 end |
164 | 187 |
188 def test_search_non_member_on_create | |
189 @request.session[:user_id] = 2 | |
190 project = Project.find_by_name("ecookbook") | |
191 user = User.generate!(:firstname => 'issue15622') | |
192 membership = user.membership(project) | |
193 assert_nil membership | |
194 xhr :get, :autocomplete_for_user, :q => 'issue15622', :project_id => 'ecookbook' | |
195 assert_response :success | |
196 assert_select 'input', :count => 1 | |
197 end | |
198 | |
165 def test_autocomplete_on_watchable_update | 199 def test_autocomplete_on_watchable_update |
166 @request.session[:user_id] = 2 | 200 @request.session[:user_id] = 2 |
167 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue', :project_id => 'ecookbook' | 201 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2', |
202 :object_type => 'issue', :project_id => 'ecookbook' | |
168 assert_response :success | 203 assert_response :success |
169 assert_select 'input', :count => 3 | 204 assert_select 'input', :count => 3 |
170 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | 205 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' |
171 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | 206 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' |
172 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | 207 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' |
173 | 208 end |
209 | |
210 def test_search_and_add_non_member_on_update | |
211 @request.session[:user_id] = 2 | |
212 project = Project.find_by_name("ecookbook") | |
213 user = User.generate!(:firstname => 'issue15622') | |
214 membership = user.membership(project) | |
215 assert_nil membership | |
216 xhr :get, :autocomplete_for_user, :q => 'issue15622', :object_id => '2', | |
217 :object_type => 'issue', :project_id => 'ecookbook' | |
218 assert_response :success | |
219 assert_select 'input', :count => 1 | |
220 assert_difference('Watcher.count', 1) do | |
221 xhr :post, :create, :object_type => 'issue', :object_id => '2', | |
222 :watcher => {:user_ids => ["#{user.id}"]} | |
223 assert_response :success | |
224 assert_match /watchers/, response.body | |
225 assert_match /ajax-modal/, response.body | |
226 end | |
227 assert Issue.find(2).watched_by?(user) | |
174 end | 228 end |
175 | 229 |
176 def test_append | 230 def test_append |
177 @request.session[:user_id] = 2 | 231 @request.session[:user_id] = 2 |
178 assert_no_difference 'Watcher.count' do | 232 assert_no_difference 'Watcher.count' do |
181 assert_include 'watchers_inputs', response.body | 235 assert_include 'watchers_inputs', response.body |
182 assert_include 'issue[watcher_user_ids][]', response.body | 236 assert_include 'issue[watcher_user_ids][]', response.body |
183 end | 237 end |
184 end | 238 end |
185 | 239 |
240 def test_append_without_user_should_render_nothing | |
241 @request.session[:user_id] = 2 | |
242 xhr :post, :append, :project_id => 'ecookbook' | |
243 assert_response :success | |
244 assert response.body.blank? | |
245 end | |
246 | |
186 def test_remove_watcher | 247 def test_remove_watcher |
187 @request.session[:user_id] = 2 | 248 @request.session[:user_id] = 2 |
188 assert_difference('Watcher.count', -1) do | 249 assert_difference('Watcher.count', -1) do |
189 xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | 250 xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' |
190 assert_response :success | 251 assert_response :success |