Mercurial > hg > soundsoftware-site
comparison .svn/pristine/2f/2f84c0e762bf35955a1559bdc6fbe56124b4f457.svn-base @ 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 | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class WatchersControllerTest < ActionController::TestCase | |
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, | |
22 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers | |
23 | |
24 def setup | |
25 User.current = nil | |
26 end | |
27 | |
28 def test_watch_a_single_object | |
29 @request.session[:user_id] = 3 | |
30 assert_difference('Watcher.count') do | |
31 xhr :post, :watch, :object_type => 'issue', :object_id => '1' | |
32 assert_response :success | |
33 assert_include '$(".issue-1-watcher")', response.body | |
34 end | |
35 assert Issue.find(1).watched_by?(User.find(3)) | |
36 end | |
37 | |
38 def test_watch_a_collection_with_a_single_object | |
39 @request.session[:user_id] = 3 | |
40 assert_difference('Watcher.count') do | |
41 xhr :post, :watch, :object_type => 'issue', :object_id => ['1'] | |
42 assert_response :success | |
43 assert_include '$(".issue-1-watcher")', response.body | |
44 end | |
45 assert Issue.find(1).watched_by?(User.find(3)) | |
46 end | |
47 | |
48 def test_watch_a_collection_with_multiple_objects | |
49 @request.session[:user_id] = 3 | |
50 assert_difference('Watcher.count', 2) do | |
51 xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3'] | |
52 assert_response :success | |
53 assert_include '$(".issue-bulk-watcher")', response.body | |
54 end | |
55 assert Issue.find(1).watched_by?(User.find(3)) | |
56 assert Issue.find(3).watched_by?(User.find(3)) | |
57 end | |
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 | |
80 def test_watch_should_be_denied_without_permission | |
81 Role.find(2).remove_permission! :view_issues | |
82 @request.session[:user_id] = 3 | |
83 assert_no_difference('Watcher.count') do | |
84 xhr :post, :watch, :object_type => 'issue', :object_id => '1' | |
85 assert_response 403 | |
86 end | |
87 end | |
88 | |
89 def test_watch_invalid_class_should_respond_with_404 | |
90 @request.session[:user_id] = 3 | |
91 assert_no_difference('Watcher.count') do | |
92 xhr :post, :watch, :object_type => 'foo', :object_id => '1' | |
93 assert_response 404 | |
94 end | |
95 end | |
96 | |
97 def test_watch_invalid_object_should_respond_with_404 | |
98 @request.session[:user_id] = 3 | |
99 assert_no_difference('Watcher.count') do | |
100 xhr :post, :watch, :object_type => 'issue', :object_id => '999' | |
101 assert_response 404 | |
102 end | |
103 end | |
104 | |
105 def test_unwatch | |
106 @request.session[:user_id] = 3 | |
107 assert_difference('Watcher.count', -1) do | |
108 xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2' | |
109 assert_response :success | |
110 assert_include '$(".issue-2-watcher")', response.body | |
111 end | |
112 assert !Issue.find(1).watched_by?(User.find(3)) | |
113 end | |
114 | |
115 def test_unwatch_a_collection_with_multiple_objects | |
116 @request.session[:user_id] = 3 | |
117 Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) | |
118 Watcher.create!(:user_id => 3, :watchable => Issue.find(3)) | |
119 | |
120 assert_difference('Watcher.count', -2) do | |
121 xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3'] | |
122 assert_response :success | |
123 assert_include '$(".issue-bulk-watcher")', response.body | |
124 end | |
125 assert !Issue.find(1).watched_by?(User.find(3)) | |
126 assert !Issue.find(3).watched_by?(User.find(3)) | |
127 end | |
128 | |
129 def test_new | |
130 @request.session[:user_id] = 2 | |
131 xhr :get, :new, :object_type => 'issue', :object_id => '2' | |
132 assert_response :success | |
133 assert_match /ajax-modal/, response.body | |
134 end | |
135 | |
136 def test_new_for_new_record_with_project_id | |
137 @request.session[:user_id] = 2 | |
138 xhr :get, :new, :project_id => 1 | |
139 assert_response :success | |
140 assert_equal Project.find(1), assigns(:project) | |
141 assert_match /ajax-modal/, response.body | |
142 end | |
143 | |
144 def test_new_for_new_record_with_project_identifier | |
145 @request.session[:user_id] = 2 | |
146 xhr :get, :new, :project_id => 'ecookbook' | |
147 assert_response :success | |
148 assert_equal Project.find(1), assigns(:project) | |
149 assert_match /ajax-modal/, response.body | |
150 end | |
151 | |
152 def test_create | |
153 @request.session[:user_id] = 2 | |
154 assert_difference('Watcher.count') do | |
155 xhr :post, :create, :object_type => 'issue', :object_id => '2', | |
156 :watcher => {:user_id => '4'} | |
157 assert_response :success | |
158 assert_match /watchers/, response.body | |
159 assert_match /ajax-modal/, response.body | |
160 end | |
161 assert Issue.find(2).watched_by?(User.find(4)) | |
162 end | |
163 | |
164 def test_create_multiple | |
165 @request.session[:user_id] = 2 | |
166 assert_difference('Watcher.count', 2) do | |
167 xhr :post, :create, :object_type => 'issue', :object_id => '2', | |
168 :watcher => {:user_ids => ['4', '7']} | |
169 assert_response :success | |
170 assert_match /watchers/, response.body | |
171 assert_match /ajax-modal/, response.body | |
172 end | |
173 assert Issue.find(2).watched_by?(User.find(4)) | |
174 assert Issue.find(2).watched_by?(User.find(7)) | |
175 end | |
176 | |
177 def test_autocomplete_on_watchable_creation | |
178 @request.session[:user_id] = 2 | |
179 xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook' | |
180 assert_response :success | |
181 assert_select 'input', :count => 4 | |
182 assert_select 'input[name=?][value=1]', 'watcher[user_ids][]' | |
183 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | |
184 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | |
185 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | |
186 end | |
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 | |
199 def test_autocomplete_on_watchable_update | |
200 @request.session[:user_id] = 2 | |
201 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2', | |
202 :object_type => 'issue', :project_id => 'ecookbook' | |
203 assert_response :success | |
204 assert_select 'input', :count => 3 | |
205 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | |
206 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | |
207 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | |
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) | |
228 end | |
229 | |
230 def test_append | |
231 @request.session[:user_id] = 2 | |
232 assert_no_difference 'Watcher.count' do | |
233 xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook' | |
234 assert_response :success | |
235 assert_include 'watchers_inputs', response.body | |
236 assert_include 'issue[watcher_user_ids][]', response.body | |
237 end | |
238 end | |
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 | |
247 def test_remove_watcher | |
248 @request.session[:user_id] = 2 | |
249 assert_difference('Watcher.count', -1) do | |
250 xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |
251 assert_response :success | |
252 assert_match /watchers/, response.body | |
253 end | |
254 assert !Issue.find(2).watched_by?(User.find(3)) | |
255 end | |
256 end |