@@ -1,197 +1,228 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 |
|
19 | |||
20 | class WatchersControllerTest < ActionController::TestCase |
|
20 | class WatchersControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, |
|
21 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, | |
22 | :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers |
|
22 | :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers | |
23 |
|
23 | |||
24 | def setup |
|
24 | def setup | |
25 | User.current = nil |
|
25 | User.current = nil | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_watch_a_single_object |
|
28 | def test_watch_a_single_object | |
29 | @request.session[:user_id] = 3 |
|
29 | @request.session[:user_id] = 3 | |
30 | assert_difference('Watcher.count') do |
|
30 | assert_difference('Watcher.count') do | |
31 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
|
31 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' | |
32 | assert_response :success |
|
32 | assert_response :success | |
33 | assert_include '$(".issue-1-watcher")', response.body |
|
33 | assert_include '$(".issue-1-watcher")', response.body | |
34 | end |
|
34 | end | |
35 | assert Issue.find(1).watched_by?(User.find(3)) |
|
35 | assert Issue.find(1).watched_by?(User.find(3)) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_watch_a_collection_with_a_single_object |
|
38 | def test_watch_a_collection_with_a_single_object | |
39 | @request.session[:user_id] = 3 |
|
39 | @request.session[:user_id] = 3 | |
40 | assert_difference('Watcher.count') do |
|
40 | assert_difference('Watcher.count') do | |
41 | xhr :post, :watch, :object_type => 'issue', :object_id => ['1'] |
|
41 | xhr :post, :watch, :object_type => 'issue', :object_id => ['1'] | |
42 | assert_response :success |
|
42 | assert_response :success | |
43 | assert_include '$(".issue-1-watcher")', response.body |
|
43 | assert_include '$(".issue-1-watcher")', response.body | |
44 | end |
|
44 | end | |
45 | assert Issue.find(1).watched_by?(User.find(3)) |
|
45 | assert Issue.find(1).watched_by?(User.find(3)) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_watch_a_collection_with_multiple_objects |
|
48 | def test_watch_a_collection_with_multiple_objects | |
49 | @request.session[:user_id] = 3 |
|
49 | @request.session[:user_id] = 3 | |
50 | assert_difference('Watcher.count', 2) do |
|
50 | assert_difference('Watcher.count', 2) do | |
51 | xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3'] |
|
51 | xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3'] | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_include '$(".issue-bulk-watcher")', response.body |
|
53 | assert_include '$(".issue-bulk-watcher")', response.body | |
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_should_be_denied_without_permission |
|
59 | def test_watch_should_be_denied_without_permission | |
60 | Role.find(2).remove_permission! :view_issues |
|
60 | Role.find(2).remove_permission! :view_issues | |
61 | @request.session[:user_id] = 3 |
|
61 | @request.session[:user_id] = 3 | |
62 | assert_no_difference('Watcher.count') do |
|
62 | assert_no_difference('Watcher.count') do | |
63 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
|
63 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' | |
64 | assert_response 403 |
|
64 | assert_response 403 | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_watch_invalid_class_should_respond_with_404 |
|
68 | def test_watch_invalid_class_should_respond_with_404 | |
69 | @request.session[:user_id] = 3 |
|
69 | @request.session[:user_id] = 3 | |
70 | assert_no_difference('Watcher.count') do |
|
70 | assert_no_difference('Watcher.count') do | |
71 | xhr :post, :watch, :object_type => 'foo', :object_id => '1' |
|
71 | xhr :post, :watch, :object_type => 'foo', :object_id => '1' | |
72 | assert_response 404 |
|
72 | assert_response 404 | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_watch_invalid_object_should_respond_with_404 |
|
76 | def test_watch_invalid_object_should_respond_with_404 | |
77 | @request.session[:user_id] = 3 |
|
77 | @request.session[:user_id] = 3 | |
78 | assert_no_difference('Watcher.count') do |
|
78 | assert_no_difference('Watcher.count') do | |
79 | xhr :post, :watch, :object_type => 'issue', :object_id => '999' |
|
79 | xhr :post, :watch, :object_type => 'issue', :object_id => '999' | |
80 | assert_response 404 |
|
80 | assert_response 404 | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_unwatch |
|
84 | def test_unwatch | |
85 | @request.session[:user_id] = 3 |
|
85 | @request.session[:user_id] = 3 | |
86 | assert_difference('Watcher.count', -1) do |
|
86 | assert_difference('Watcher.count', -1) do | |
87 | xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2' |
|
87 | xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2' | |
88 | assert_response :success |
|
88 | assert_response :success | |
89 | assert_include '$(".issue-2-watcher")', response.body |
|
89 | assert_include '$(".issue-2-watcher")', response.body | |
90 | end |
|
90 | end | |
91 | assert !Issue.find(1).watched_by?(User.find(3)) |
|
91 | assert !Issue.find(1).watched_by?(User.find(3)) | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def test_unwatch_a_collection_with_multiple_objects |
|
94 | def test_unwatch_a_collection_with_multiple_objects | |
95 | @request.session[:user_id] = 3 |
|
95 | @request.session[:user_id] = 3 | |
96 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) |
|
96 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) | |
97 | Watcher.create!(:user_id => 3, :watchable => Issue.find(3)) |
|
97 | Watcher.create!(:user_id => 3, :watchable => Issue.find(3)) | |
98 |
|
98 | |||
99 | assert_difference('Watcher.count', -2) do |
|
99 | assert_difference('Watcher.count', -2) do | |
100 | xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3'] |
|
100 | xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3'] | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_include '$(".issue-bulk-watcher")', response.body |
|
102 | assert_include '$(".issue-bulk-watcher")', response.body | |
103 | end |
|
103 | end | |
104 | assert !Issue.find(1).watched_by?(User.find(3)) |
|
104 | assert !Issue.find(1).watched_by?(User.find(3)) | |
105 | assert !Issue.find(3).watched_by?(User.find(3)) |
|
105 | assert !Issue.find(3).watched_by?(User.find(3)) | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_new |
|
108 | def test_new | |
109 | @request.session[:user_id] = 2 |
|
109 | @request.session[:user_id] = 2 | |
110 | xhr :get, :new, :object_type => 'issue', :object_id => '2' |
|
110 | xhr :get, :new, :object_type => 'issue', :object_id => '2' | |
111 | assert_response :success |
|
111 | assert_response :success | |
112 | assert_match /ajax-modal/, response.body |
|
112 | assert_match /ajax-modal/, response.body | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_new_for_new_record_with_project_id |
|
115 | def test_new_for_new_record_with_project_id | |
116 | @request.session[:user_id] = 2 |
|
116 | @request.session[:user_id] = 2 | |
117 | xhr :get, :new, :project_id => 1 |
|
117 | xhr :get, :new, :project_id => 1 | |
118 | assert_response :success |
|
118 | assert_response :success | |
119 | assert_equal Project.find(1), assigns(:project) |
|
119 | assert_equal Project.find(1), assigns(:project) | |
120 | assert_match /ajax-modal/, response.body |
|
120 | assert_match /ajax-modal/, response.body | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | def test_new_for_new_record_with_project_identifier |
|
123 | def test_new_for_new_record_with_project_identifier | |
124 | @request.session[:user_id] = 2 |
|
124 | @request.session[:user_id] = 2 | |
125 | xhr :get, :new, :project_id => 'ecookbook' |
|
125 | xhr :get, :new, :project_id => 'ecookbook' | |
126 | assert_response :success |
|
126 | assert_response :success | |
127 | assert_equal Project.find(1), assigns(:project) |
|
127 | assert_equal Project.find(1), assigns(:project) | |
128 | assert_match /ajax-modal/, response.body |
|
128 | assert_match /ajax-modal/, response.body | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def test_create |
|
131 | def test_create | |
132 | @request.session[:user_id] = 2 |
|
132 | @request.session[:user_id] = 2 | |
133 | assert_difference('Watcher.count') do |
|
133 | assert_difference('Watcher.count') do | |
134 | xhr :post, :create, :object_type => 'issue', :object_id => '2', |
|
134 | xhr :post, :create, :object_type => 'issue', :object_id => '2', | |
135 | :watcher => {:user_id => '4'} |
|
135 | :watcher => {:user_id => '4'} | |
136 | assert_response :success |
|
136 | assert_response :success | |
137 | assert_match /watchers/, response.body |
|
137 | assert_match /watchers/, response.body | |
138 | assert_match /ajax-modal/, response.body |
|
138 | assert_match /ajax-modal/, response.body | |
139 | end |
|
139 | end | |
140 | assert Issue.find(2).watched_by?(User.find(4)) |
|
140 | assert Issue.find(2).watched_by?(User.find(4)) | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_create_multiple |
|
143 | def test_create_multiple | |
144 | @request.session[:user_id] = 2 |
|
144 | @request.session[:user_id] = 2 | |
145 | assert_difference('Watcher.count', 2) do |
|
145 | assert_difference('Watcher.count', 2) do | |
146 | xhr :post, :create, :object_type => 'issue', :object_id => '2', |
|
146 | xhr :post, :create, :object_type => 'issue', :object_id => '2', | |
147 | :watcher => {:user_ids => ['4', '7']} |
|
147 | :watcher => {:user_ids => ['4', '7']} | |
148 | assert_response :success |
|
148 | assert_response :success | |
149 | assert_match /watchers/, response.body |
|
149 | assert_match /watchers/, response.body | |
150 | assert_match /ajax-modal/, response.body |
|
150 | assert_match /ajax-modal/, response.body | |
151 | end |
|
151 | end | |
152 | assert Issue.find(2).watched_by?(User.find(4)) |
|
152 | assert Issue.find(2).watched_by?(User.find(4)) | |
153 | assert Issue.find(2).watched_by?(User.find(7)) |
|
153 | assert Issue.find(2).watched_by?(User.find(7)) | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def test_autocomplete_on_watchable_creation |
|
156 | def test_autocomplete_on_watchable_creation | |
157 | @request.session[:user_id] = 2 |
|
157 | @request.session[:user_id] = 2 | |
158 | xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook' |
|
158 | xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook' | |
159 | assert_response :success |
|
159 | assert_response :success | |
160 | assert_select 'input', :count => 4 |
|
160 | assert_select 'input', :count => 4 | |
161 | assert_select 'input[name=?][value=1]', 'watcher[user_ids][]' |
|
161 | assert_select 'input[name=?][value=1]', 'watcher[user_ids][]' | |
162 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' |
|
162 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | |
163 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' |
|
163 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | |
164 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' |
|
164 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
|
167 | def test_search_non_member_on_create | |||
|
168 | @request.session[:user_id] = 2 | |||
|
169 | project = Project.find_by_name("ecookbook") | |||
|
170 | user = User.generate!(:firstname => 'issue15622') | |||
|
171 | membership = user.membership(project) | |||
|
172 | assert_nil membership | |||
|
173 | xhr :get, :autocomplete_for_user, :q => 'issue15622', :project_id => 'ecookbook' | |||
|
174 | assert_response :success | |||
|
175 | assert_select 'input', :count => 1 | |||
|
176 | end | |||
|
177 | ||||
167 | def test_autocomplete_on_watchable_update |
|
178 | def test_autocomplete_on_watchable_update | |
168 | @request.session[:user_id] = 2 |
|
179 | @request.session[:user_id] = 2 | |
169 | xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2', |
|
180 | xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2', | |
170 | :object_type => 'issue', :project_id => 'ecookbook' |
|
181 | :object_type => 'issue', :project_id => 'ecookbook' | |
171 | assert_response :success |
|
182 | assert_response :success | |
172 | assert_select 'input', :count => 3 |
|
183 | assert_select 'input', :count => 3 | |
173 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' |
|
184 | assert_select 'input[name=?][value=2]', 'watcher[user_ids][]' | |
174 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' |
|
185 | assert_select 'input[name=?][value=8]', 'watcher[user_ids][]' | |
175 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' |
|
186 | assert_select 'input[name=?][value=9]', 'watcher[user_ids][]' | |
176 | end |
|
187 | end | |
177 |
|
188 | |||
|
189 | def test_search_and_add_non_member_on_update | |||
|
190 | @request.session[:user_id] = 2 | |||
|
191 | project = Project.find_by_name("ecookbook") | |||
|
192 | user = User.generate!(:firstname => 'issue15622') | |||
|
193 | membership = user.membership(project) | |||
|
194 | assert_nil membership | |||
|
195 | xhr :get, :autocomplete_for_user, :q => 'issue15622', :object_id => '2', | |||
|
196 | :object_type => 'issue', :project_id => 'ecookbook' | |||
|
197 | assert_response :success | |||
|
198 | assert_select 'input', :count => 1 | |||
|
199 | assert_difference('Watcher.count', 1) do | |||
|
200 | xhr :post, :create, :object_type => 'issue', :object_id => '2', | |||
|
201 | :watcher => {:user_ids => ["#{user.id}"]} | |||
|
202 | assert_response :success | |||
|
203 | assert_match /watchers/, response.body | |||
|
204 | assert_match /ajax-modal/, response.body | |||
|
205 | end | |||
|
206 | assert Issue.find(2).watched_by?(user) | |||
|
207 | end | |||
|
208 | ||||
178 | def test_append |
|
209 | def test_append | |
179 | @request.session[:user_id] = 2 |
|
210 | @request.session[:user_id] = 2 | |
180 | assert_no_difference 'Watcher.count' do |
|
211 | assert_no_difference 'Watcher.count' do | |
181 | xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook' |
|
212 | xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook' | |
182 | assert_response :success |
|
213 | assert_response :success | |
183 | assert_include 'watchers_inputs', response.body |
|
214 | assert_include 'watchers_inputs', response.body | |
184 | assert_include 'issue[watcher_user_ids][]', response.body |
|
215 | assert_include 'issue[watcher_user_ids][]', response.body | |
185 | end |
|
216 | end | |
186 | end |
|
217 | end | |
187 |
|
218 | |||
188 | def test_remove_watcher |
|
219 | def test_remove_watcher | |
189 | @request.session[:user_id] = 2 |
|
220 | @request.session[:user_id] = 2 | |
190 | assert_difference('Watcher.count', -1) do |
|
221 | assert_difference('Watcher.count', -1) do | |
191 | xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' |
|
222 | xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |
192 | assert_response :success |
|
223 | assert_response :success | |
193 | assert_match /watchers/, response.body |
|
224 | assert_match /watchers/, response.body | |
194 | end |
|
225 | end | |
195 | assert !Issue.find(2).watched_by?(User.find(3)) |
|
226 | assert !Issue.find(2).watched_by?(User.find(3)) | |
196 | end |
|
227 | end | |
197 | end |
|
228 | end |
General Comments 0
You need to be logged in to leave comments.
Login now