@@ -1,347 +1,347 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 'pp' |
|
19 | require 'pp' | |
20 | class ApiTest::UsersTest < ActionController::IntegrationTest |
|
20 | class ApiTest::UsersTest < ActionController::IntegrationTest | |
21 | fixtures :users |
|
21 | fixtures :users, :members, :member_roles, :roles, :projects | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | Setting.rest_api_enabled = '1' |
|
24 | Setting.rest_api_enabled = '1' | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | context "GET /users" do |
|
27 | context "GET /users" do | |
28 | should_allow_api_authentication(:get, "/users.xml") |
|
28 | should_allow_api_authentication(:get, "/users.xml") | |
29 | should_allow_api_authentication(:get, "/users.json") |
|
29 | should_allow_api_authentication(:get, "/users.json") | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | context "GET /users/2" do |
|
32 | context "GET /users/2" do | |
33 | context ".xml" do |
|
33 | context ".xml" do | |
34 | should "return requested user" do |
|
34 | should "return requested user" do | |
35 | get '/users/2.xml' |
|
35 | get '/users/2.xml' | |
36 |
|
36 | |||
37 | assert_response :success |
|
37 | assert_response :success | |
38 | assert_tag :tag => 'user', |
|
38 | assert_tag :tag => 'user', | |
39 | :child => {:tag => 'id', :content => '2'} |
|
39 | :child => {:tag => 'id', :content => '2'} | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | context "with include=memberships" do |
|
42 | context "with include=memberships" do | |
43 | should "include memberships" do |
|
43 | should "include memberships" do | |
44 | get '/users/2.xml?include=memberships' |
|
44 | get '/users/2.xml?include=memberships' | |
45 |
|
45 | |||
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_tag :tag => 'memberships', |
|
47 | assert_tag :tag => 'memberships', | |
48 | :parent => {:tag => 'user'}, |
|
48 | :parent => {:tag => 'user'}, | |
49 | :children => {:count => 1} |
|
49 | :children => {:count => 1} | |
50 | end |
|
50 | end | |
51 | end |
|
51 | end | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | context ".json" do |
|
54 | context ".json" do | |
55 | should "return requested user" do |
|
55 | should "return requested user" do | |
56 | get '/users/2.json' |
|
56 | get '/users/2.json' | |
57 |
|
57 | |||
58 | assert_response :success |
|
58 | assert_response :success | |
59 | json = ActiveSupport::JSON.decode(response.body) |
|
59 | json = ActiveSupport::JSON.decode(response.body) | |
60 | assert_kind_of Hash, json |
|
60 | assert_kind_of Hash, json | |
61 | assert_kind_of Hash, json['user'] |
|
61 | assert_kind_of Hash, json['user'] | |
62 | assert_equal 2, json['user']['id'] |
|
62 | assert_equal 2, json['user']['id'] | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | context "with include=memberships" do |
|
65 | context "with include=memberships" do | |
66 | should "include memberships" do |
|
66 | should "include memberships" do | |
67 | get '/users/2.json?include=memberships' |
|
67 | get '/users/2.json?include=memberships' | |
68 |
|
68 | |||
69 | assert_response :success |
|
69 | assert_response :success | |
70 | json = ActiveSupport::JSON.decode(response.body) |
|
70 | json = ActiveSupport::JSON.decode(response.body) | |
71 | assert_kind_of Array, json['user']['memberships'] |
|
71 | assert_kind_of Array, json['user']['memberships'] | |
72 | assert_equal [{ |
|
72 | assert_equal [{ | |
73 | "id"=>1, |
|
73 | "id"=>1, | |
74 | "project"=>{"name"=>"eCookbook", "id"=>1}, |
|
74 | "project"=>{"name"=>"eCookbook", "id"=>1}, | |
75 | "roles"=>[{"name"=>"Manager", "id"=>1}] |
|
75 | "roles"=>[{"name"=>"Manager", "id"=>1}] | |
76 | }], json['user']['memberships'] |
|
76 | }], json['user']['memberships'] | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | context "GET /users/current" do |
|
82 | context "GET /users/current" do | |
83 | context ".xml" do |
|
83 | context ".xml" do | |
84 | should "require authentication" do |
|
84 | should "require authentication" do | |
85 | get '/users/current.xml' |
|
85 | get '/users/current.xml' | |
86 |
|
86 | |||
87 | assert_response 401 |
|
87 | assert_response 401 | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | should "return current user" do |
|
90 | should "return current user" do | |
91 | get '/users/current.xml', {}, credentials('jsmith') |
|
91 | get '/users/current.xml', {}, credentials('jsmith') | |
92 |
|
92 | |||
93 | assert_tag :tag => 'user', |
|
93 | assert_tag :tag => 'user', | |
94 | :child => {:tag => 'id', :content => '2'} |
|
94 | :child => {:tag => 'id', :content => '2'} | |
95 | end |
|
95 | end | |
96 | end |
|
96 | end | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | context "POST /users" do |
|
99 | context "POST /users" do | |
100 | context "with valid parameters" do |
|
100 | context "with valid parameters" do | |
101 | setup do |
|
101 | setup do | |
102 | @parameters = { |
|
102 | @parameters = { | |
103 | :user => { |
|
103 | :user => { | |
104 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
104 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |
105 | :mail => 'foo@example.net', :password => 'secret', |
|
105 | :mail => 'foo@example.net', :password => 'secret', | |
106 | :mail_notification => 'only_assigned' |
|
106 | :mail_notification => 'only_assigned' | |
107 | } |
|
107 | } | |
108 | } |
|
108 | } | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | context ".xml" do |
|
111 | context ".xml" do | |
112 | should_allow_api_authentication(:post, |
|
112 | should_allow_api_authentication(:post, | |
113 | '/users.xml', |
|
113 | '/users.xml', | |
114 | {:user => { |
|
114 | {:user => { | |
115 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
115 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |
116 | :mail => 'foo@example.net', :password => 'secret' |
|
116 | :mail => 'foo@example.net', :password => 'secret' | |
117 | }}, |
|
117 | }}, | |
118 | {:success_code => :created}) |
|
118 | {:success_code => :created}) | |
119 |
|
119 | |||
120 | should "create a user with the attributes" do |
|
120 | should "create a user with the attributes" do | |
121 | assert_difference('User.count') do |
|
121 | assert_difference('User.count') do | |
122 | post '/users.xml', @parameters, credentials('admin') |
|
122 | post '/users.xml', @parameters, credentials('admin') | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | user = User.first(:order => 'id DESC') |
|
125 | user = User.first(:order => 'id DESC') | |
126 | assert_equal 'foo', user.login |
|
126 | assert_equal 'foo', user.login | |
127 | assert_equal 'Firstname', user.firstname |
|
127 | assert_equal 'Firstname', user.firstname | |
128 | assert_equal 'Lastname', user.lastname |
|
128 | assert_equal 'Lastname', user.lastname | |
129 | assert_equal 'foo@example.net', user.mail |
|
129 | assert_equal 'foo@example.net', user.mail | |
130 | assert_equal 'only_assigned', user.mail_notification |
|
130 | assert_equal 'only_assigned', user.mail_notification | |
131 | assert !user.admin? |
|
131 | assert !user.admin? | |
132 | assert user.check_password?('secret') |
|
132 | assert user.check_password?('secret') | |
133 |
|
133 | |||
134 | assert_response :created |
|
134 | assert_response :created | |
135 | assert_equal 'application/xml', @response.content_type |
|
135 | assert_equal 'application/xml', @response.content_type | |
136 | assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s} |
|
136 | assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s} | |
137 | end |
|
137 | end | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | context ".json" do |
|
140 | context ".json" do | |
141 | should_allow_api_authentication(:post, |
|
141 | should_allow_api_authentication(:post, | |
142 | '/users.json', |
|
142 | '/users.json', | |
143 | {:user => { |
|
143 | {:user => { | |
144 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
144 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |
145 | :mail => 'foo@example.net' |
|
145 | :mail => 'foo@example.net' | |
146 | }}, |
|
146 | }}, | |
147 | {:success_code => :created}) |
|
147 | {:success_code => :created}) | |
148 |
|
148 | |||
149 | should "create a user with the attributes" do |
|
149 | should "create a user with the attributes" do | |
150 | assert_difference('User.count') do |
|
150 | assert_difference('User.count') do | |
151 | post '/users.json', @parameters, credentials('admin') |
|
151 | post '/users.json', @parameters, credentials('admin') | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | user = User.first(:order => 'id DESC') |
|
154 | user = User.first(:order => 'id DESC') | |
155 | assert_equal 'foo', user.login |
|
155 | assert_equal 'foo', user.login | |
156 | assert_equal 'Firstname', user.firstname |
|
156 | assert_equal 'Firstname', user.firstname | |
157 | assert_equal 'Lastname', user.lastname |
|
157 | assert_equal 'Lastname', user.lastname | |
158 | assert_equal 'foo@example.net', user.mail |
|
158 | assert_equal 'foo@example.net', user.mail | |
159 | assert !user.admin? |
|
159 | assert !user.admin? | |
160 |
|
160 | |||
161 | assert_response :created |
|
161 | assert_response :created | |
162 | assert_equal 'application/json', @response.content_type |
|
162 | assert_equal 'application/json', @response.content_type | |
163 | json = ActiveSupport::JSON.decode(response.body) |
|
163 | json = ActiveSupport::JSON.decode(response.body) | |
164 | assert_kind_of Hash, json |
|
164 | assert_kind_of Hash, json | |
165 | assert_kind_of Hash, json['user'] |
|
165 | assert_kind_of Hash, json['user'] | |
166 | assert_equal user.id, json['user']['id'] |
|
166 | assert_equal user.id, json['user']['id'] | |
167 | end |
|
167 | end | |
168 | end |
|
168 | end | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | context "with invalid parameters" do |
|
171 | context "with invalid parameters" do | |
172 | setup do |
|
172 | setup do | |
173 | @parameters = {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}} |
|
173 | @parameters = {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}} | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | context ".xml" do |
|
176 | context ".xml" do | |
177 | should "return errors" do |
|
177 | should "return errors" do | |
178 | assert_no_difference('User.count') do |
|
178 | assert_no_difference('User.count') do | |
179 | post '/users.xml', @parameters, credentials('admin') |
|
179 | post '/users.xml', @parameters, credentials('admin') | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | assert_response :unprocessable_entity |
|
182 | assert_response :unprocessable_entity | |
183 | assert_equal 'application/xml', @response.content_type |
|
183 | assert_equal 'application/xml', @response.content_type | |
184 | assert_tag 'errors', :child => { |
|
184 | assert_tag 'errors', :child => { | |
185 | :tag => 'error', |
|
185 | :tag => 'error', | |
186 | :content => "First name can't be blank" |
|
186 | :content => "First name can't be blank" | |
187 | } |
|
187 | } | |
188 | end |
|
188 | end | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | context ".json" do |
|
191 | context ".json" do | |
192 | should "return errors" do |
|
192 | should "return errors" do | |
193 | assert_no_difference('User.count') do |
|
193 | assert_no_difference('User.count') do | |
194 | post '/users.json', @parameters, credentials('admin') |
|
194 | post '/users.json', @parameters, credentials('admin') | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | assert_response :unprocessable_entity |
|
197 | assert_response :unprocessable_entity | |
198 | assert_equal 'application/json', @response.content_type |
|
198 | assert_equal 'application/json', @response.content_type | |
199 | json = ActiveSupport::JSON.decode(response.body) |
|
199 | json = ActiveSupport::JSON.decode(response.body) | |
200 | assert_kind_of Hash, json |
|
200 | assert_kind_of Hash, json | |
201 | assert json.has_key?('errors') |
|
201 | assert json.has_key?('errors') | |
202 | assert_kind_of Array, json['errors'] |
|
202 | assert_kind_of Array, json['errors'] | |
203 | end |
|
203 | end | |
204 | end |
|
204 | end | |
205 | end |
|
205 | end | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | context "PUT /users/2" do |
|
208 | context "PUT /users/2" do | |
209 | context "with valid parameters" do |
|
209 | context "with valid parameters" do | |
210 | setup do |
|
210 | setup do | |
211 | @parameters = { |
|
211 | @parameters = { | |
212 | :user => { |
|
212 | :user => { | |
213 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', |
|
213 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |
214 | :mail => 'jsmith@somenet.foo' |
|
214 | :mail => 'jsmith@somenet.foo' | |
215 | } |
|
215 | } | |
216 | } |
|
216 | } | |
217 | end |
|
217 | end | |
218 |
|
218 | |||
219 | context ".xml" do |
|
219 | context ".xml" do | |
220 | should_allow_api_authentication(:put, |
|
220 | should_allow_api_authentication(:put, | |
221 | '/users/2.xml', |
|
221 | '/users/2.xml', | |
222 | {:user => { |
|
222 | {:user => { | |
223 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', |
|
223 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |
224 | :mail => 'jsmith@somenet.foo' |
|
224 | :mail => 'jsmith@somenet.foo' | |
225 | }}, |
|
225 | }}, | |
226 | {:success_code => :ok}) |
|
226 | {:success_code => :ok}) | |
227 |
|
227 | |||
228 | should "update user with the attributes" do |
|
228 | should "update user with the attributes" do | |
229 | assert_no_difference('User.count') do |
|
229 | assert_no_difference('User.count') do | |
230 | put '/users/2.xml', @parameters, credentials('admin') |
|
230 | put '/users/2.xml', @parameters, credentials('admin') | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | user = User.find(2) |
|
233 | user = User.find(2) | |
234 | assert_equal 'jsmith', user.login |
|
234 | assert_equal 'jsmith', user.login | |
235 | assert_equal 'John', user.firstname |
|
235 | assert_equal 'John', user.firstname | |
236 | assert_equal 'Renamed', user.lastname |
|
236 | assert_equal 'Renamed', user.lastname | |
237 | assert_equal 'jsmith@somenet.foo', user.mail |
|
237 | assert_equal 'jsmith@somenet.foo', user.mail | |
238 | assert !user.admin? |
|
238 | assert !user.admin? | |
239 |
|
239 | |||
240 | assert_response :ok |
|
240 | assert_response :ok | |
241 | assert_equal '', @response.body |
|
241 | assert_equal '', @response.body | |
242 | end |
|
242 | end | |
243 | end |
|
243 | end | |
244 |
|
244 | |||
245 | context ".json" do |
|
245 | context ".json" do | |
246 | should_allow_api_authentication(:put, |
|
246 | should_allow_api_authentication(:put, | |
247 | '/users/2.json', |
|
247 | '/users/2.json', | |
248 | {:user => { |
|
248 | {:user => { | |
249 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', |
|
249 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |
250 | :mail => 'jsmith@somenet.foo' |
|
250 | :mail => 'jsmith@somenet.foo' | |
251 | }}, |
|
251 | }}, | |
252 | {:success_code => :ok}) |
|
252 | {:success_code => :ok}) | |
253 |
|
253 | |||
254 | should "update user with the attributes" do |
|
254 | should "update user with the attributes" do | |
255 | assert_no_difference('User.count') do |
|
255 | assert_no_difference('User.count') do | |
256 | put '/users/2.json', @parameters, credentials('admin') |
|
256 | put '/users/2.json', @parameters, credentials('admin') | |
257 | end |
|
257 | end | |
258 |
|
258 | |||
259 | user = User.find(2) |
|
259 | user = User.find(2) | |
260 | assert_equal 'jsmith', user.login |
|
260 | assert_equal 'jsmith', user.login | |
261 | assert_equal 'John', user.firstname |
|
261 | assert_equal 'John', user.firstname | |
262 | assert_equal 'Renamed', user.lastname |
|
262 | assert_equal 'Renamed', user.lastname | |
263 | assert_equal 'jsmith@somenet.foo', user.mail |
|
263 | assert_equal 'jsmith@somenet.foo', user.mail | |
264 | assert !user.admin? |
|
264 | assert !user.admin? | |
265 |
|
265 | |||
266 | assert_response :ok |
|
266 | assert_response :ok | |
267 | assert_equal '', @response.body |
|
267 | assert_equal '', @response.body | |
268 | end |
|
268 | end | |
269 | end |
|
269 | end | |
270 | end |
|
270 | end | |
271 |
|
271 | |||
272 | context "with invalid parameters" do |
|
272 | context "with invalid parameters" do | |
273 | setup do |
|
273 | setup do | |
274 | @parameters = { |
|
274 | @parameters = { | |
275 | :user => { |
|
275 | :user => { | |
276 | :login => 'jsmith', :firstname => '', :lastname => 'Lastname', |
|
276 | :login => 'jsmith', :firstname => '', :lastname => 'Lastname', | |
277 | :mail => 'foo' |
|
277 | :mail => 'foo' | |
278 | } |
|
278 | } | |
279 | } |
|
279 | } | |
280 | end |
|
280 | end | |
281 |
|
281 | |||
282 | context ".xml" do |
|
282 | context ".xml" do | |
283 | should "return errors" do |
|
283 | should "return errors" do | |
284 | assert_no_difference('User.count') do |
|
284 | assert_no_difference('User.count') do | |
285 | put '/users/2.xml', @parameters, credentials('admin') |
|
285 | put '/users/2.xml', @parameters, credentials('admin') | |
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | assert_response :unprocessable_entity |
|
288 | assert_response :unprocessable_entity | |
289 | assert_equal 'application/xml', @response.content_type |
|
289 | assert_equal 'application/xml', @response.content_type | |
290 | assert_tag 'errors', :child => { |
|
290 | assert_tag 'errors', :child => { | |
291 | :tag => 'error', |
|
291 | :tag => 'error', | |
292 | :content => "First name can't be blank" |
|
292 | :content => "First name can't be blank" | |
293 | } |
|
293 | } | |
294 | end |
|
294 | end | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | context ".json" do |
|
297 | context ".json" do | |
298 | should "return errors" do |
|
298 | should "return errors" do | |
299 | assert_no_difference('User.count') do |
|
299 | assert_no_difference('User.count') do | |
300 | put '/users/2.json', @parameters, credentials('admin') |
|
300 | put '/users/2.json', @parameters, credentials('admin') | |
301 | end |
|
301 | end | |
302 |
|
302 | |||
303 | assert_response :unprocessable_entity |
|
303 | assert_response :unprocessable_entity | |
304 | assert_equal 'application/json', @response.content_type |
|
304 | assert_equal 'application/json', @response.content_type | |
305 | json = ActiveSupport::JSON.decode(response.body) |
|
305 | json = ActiveSupport::JSON.decode(response.body) | |
306 | assert_kind_of Hash, json |
|
306 | assert_kind_of Hash, json | |
307 | assert json.has_key?('errors') |
|
307 | assert json.has_key?('errors') | |
308 | assert_kind_of Array, json['errors'] |
|
308 | assert_kind_of Array, json['errors'] | |
309 | end |
|
309 | end | |
310 | end |
|
310 | end | |
311 | end |
|
311 | end | |
312 | end |
|
312 | end | |
313 |
|
313 | |||
314 | context "DELETE /users/2" do |
|
314 | context "DELETE /users/2" do | |
315 | context ".xml" do |
|
315 | context ".xml" do | |
316 | should_allow_api_authentication(:delete, |
|
316 | should_allow_api_authentication(:delete, | |
317 | '/users/2.xml', |
|
317 | '/users/2.xml', | |
318 | {}, |
|
318 | {}, | |
319 | {:success_code => :ok}) |
|
319 | {:success_code => :ok}) | |
320 |
|
320 | |||
321 | should "delete user" do |
|
321 | should "delete user" do | |
322 | assert_difference('User.count', -1) do |
|
322 | assert_difference('User.count', -1) do | |
323 | delete '/users/2.xml', {}, credentials('admin') |
|
323 | delete '/users/2.xml', {}, credentials('admin') | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | assert_response :ok |
|
326 | assert_response :ok | |
327 | assert_equal '', @response.body |
|
327 | assert_equal '', @response.body | |
328 | end |
|
328 | end | |
329 | end |
|
329 | end | |
330 |
|
330 | |||
331 | context ".json" do |
|
331 | context ".json" do | |
332 | should_allow_api_authentication(:delete, |
|
332 | should_allow_api_authentication(:delete, | |
333 | '/users/2.xml', |
|
333 | '/users/2.xml', | |
334 | {}, |
|
334 | {}, | |
335 | {:success_code => :ok}) |
|
335 | {:success_code => :ok}) | |
336 |
|
336 | |||
337 | should "delete user" do |
|
337 | should "delete user" do | |
338 | assert_difference('User.count', -1) do |
|
338 | assert_difference('User.count', -1) do | |
339 | delete '/users/2.json', {}, credentials('admin') |
|
339 | delete '/users/2.json', {}, credentials('admin') | |
340 | end |
|
340 | end | |
341 |
|
341 | |||
342 | assert_response :ok |
|
342 | assert_response :ok | |
343 | assert_equal '', @response.body |
|
343 | assert_equal '', @response.body | |
344 | end |
|
344 | end | |
345 | end |
|
345 | end | |
346 | end |
|
346 | end | |
347 | end |
|
347 | end |
@@ -1,228 +1,229 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 IssuesTest < ActionController::IntegrationTest |
|
20 | class IssuesTest < ActionController::IntegrationTest | |
21 | fixtures :projects, |
|
21 | fixtures :projects, | |
22 | :users, |
|
22 | :users, | |
23 | :roles, |
|
23 | :roles, | |
24 | :members, |
|
24 | :members, | |
|
25 | :member_roles, | |||
25 | :trackers, |
|
26 | :trackers, | |
26 | :projects_trackers, |
|
27 | :projects_trackers, | |
27 | :enabled_modules, |
|
28 | :enabled_modules, | |
28 | :issue_statuses, |
|
29 | :issue_statuses, | |
29 | :issues, |
|
30 | :issues, | |
30 | :enumerations, |
|
31 | :enumerations, | |
31 | :custom_fields, |
|
32 | :custom_fields, | |
32 | :custom_values, |
|
33 | :custom_values, | |
33 | :custom_fields_trackers |
|
34 | :custom_fields_trackers | |
34 |
|
35 | |||
35 | # create an issue |
|
36 | # create an issue | |
36 | def test_add_issue |
|
37 | def test_add_issue | |
37 | log_user('jsmith', 'jsmith') |
|
38 | log_user('jsmith', 'jsmith') | |
38 | get 'projects/1/issues/new', :tracker_id => '1' |
|
39 | get 'projects/1/issues/new', :tracker_id => '1' | |
39 | assert_response :success |
|
40 | assert_response :success | |
40 | assert_template 'issues/new' |
|
41 | assert_template 'issues/new' | |
41 |
|
42 | |||
42 | post 'projects/1/issues', :tracker_id => "1", |
|
43 | post 'projects/1/issues', :tracker_id => "1", | |
43 | :issue => { :start_date => "2006-12-26", |
|
44 | :issue => { :start_date => "2006-12-26", | |
44 | :priority_id => "4", |
|
45 | :priority_id => "4", | |
45 | :subject => "new test issue", |
|
46 | :subject => "new test issue", | |
46 | :category_id => "", |
|
47 | :category_id => "", | |
47 | :description => "new issue", |
|
48 | :description => "new issue", | |
48 | :done_ratio => "0", |
|
49 | :done_ratio => "0", | |
49 | :due_date => "", |
|
50 | :due_date => "", | |
50 | :assigned_to_id => "" }, |
|
51 | :assigned_to_id => "" }, | |
51 | :custom_fields => {'2' => 'Value for field 2'} |
|
52 | :custom_fields => {'2' => 'Value for field 2'} | |
52 | # find created issue |
|
53 | # find created issue | |
53 | issue = Issue.find_by_subject("new test issue") |
|
54 | issue = Issue.find_by_subject("new test issue") | |
54 | assert_kind_of Issue, issue |
|
55 | assert_kind_of Issue, issue | |
55 |
|
56 | |||
56 | # check redirection |
|
57 | # check redirection | |
57 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
58 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
58 | follow_redirect! |
|
59 | follow_redirect! | |
59 | assert_equal issue, assigns(:issue) |
|
60 | assert_equal issue, assigns(:issue) | |
60 |
|
61 | |||
61 | # check issue attributes |
|
62 | # check issue attributes | |
62 | assert_equal 'jsmith', issue.author.login |
|
63 | assert_equal 'jsmith', issue.author.login | |
63 | assert_equal 1, issue.project.id |
|
64 | assert_equal 1, issue.project.id | |
64 | assert_equal 1, issue.status.id |
|
65 | assert_equal 1, issue.status.id | |
65 | end |
|
66 | end | |
66 |
|
67 | |||
67 | def test_update_issue_form |
|
68 | def test_update_issue_form | |
68 | log_user('jsmith', 'jsmith') |
|
69 | log_user('jsmith', 'jsmith') | |
69 | post 'projects/ecookbook/issues/new', :issue => { :tracker_id => "2"} |
|
70 | post 'projects/ecookbook/issues/new', :issue => { :tracker_id => "2"} | |
70 | assert_response :success |
|
71 | assert_response :success | |
71 | assert_tag 'select', |
|
72 | assert_tag 'select', | |
72 | :attributes => {:name => 'issue[tracker_id]'}, |
|
73 | :attributes => {:name => 'issue[tracker_id]'}, | |
73 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}} |
|
74 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}} | |
74 | end |
|
75 | end | |
75 |
|
76 | |||
76 | # add then remove 2 attachments to an issue |
|
77 | # add then remove 2 attachments to an issue | |
77 | def test_issue_attachments |
|
78 | def test_issue_attachments | |
78 | log_user('jsmith', 'jsmith') |
|
79 | log_user('jsmith', 'jsmith') | |
79 | set_tmp_attachments_directory |
|
80 | set_tmp_attachments_directory | |
80 |
|
81 | |||
81 | put 'issues/1', |
|
82 | put 'issues/1', | |
82 | :notes => 'Some notes', |
|
83 | :notes => 'Some notes', | |
83 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}} |
|
84 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}} | |
84 | assert_redirected_to "/issues/1" |
|
85 | assert_redirected_to "/issues/1" | |
85 |
|
86 | |||
86 | # make sure attachment was saved |
|
87 | # make sure attachment was saved | |
87 | attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") |
|
88 | attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") | |
88 | assert_kind_of Attachment, attachment |
|
89 | assert_kind_of Attachment, attachment | |
89 | assert_equal Issue.find(1), attachment.container |
|
90 | assert_equal Issue.find(1), attachment.container | |
90 | assert_equal 'This is an attachment', attachment.description |
|
91 | assert_equal 'This is an attachment', attachment.description | |
91 | # verify the size of the attachment stored in db |
|
92 | # verify the size of the attachment stored in db | |
92 | #assert_equal file_data_1.length, attachment.filesize |
|
93 | #assert_equal file_data_1.length, attachment.filesize | |
93 | # verify that the attachment was written to disk |
|
94 | # verify that the attachment was written to disk | |
94 | assert File.exist?(attachment.diskfile) |
|
95 | assert File.exist?(attachment.diskfile) | |
95 |
|
96 | |||
96 | # remove the attachments |
|
97 | # remove the attachments | |
97 | Issue.find(1).attachments.each(&:destroy) |
|
98 | Issue.find(1).attachments.each(&:destroy) | |
98 | assert_equal 0, Issue.find(1).attachments.length |
|
99 | assert_equal 0, Issue.find(1).attachments.length | |
99 | end |
|
100 | end | |
100 |
|
101 | |||
101 | def test_other_formats_links_on_index |
|
102 | def test_other_formats_links_on_index | |
102 | get '/projects/ecookbook/issues' |
|
103 | get '/projects/ecookbook/issues' | |
103 |
|
104 | |||
104 | %w(Atom PDF CSV).each do |format| |
|
105 | %w(Atom PDF CSV).each do |format| | |
105 | assert_tag :a, :content => format, |
|
106 | assert_tag :a, :content => format, | |
106 | :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}", |
|
107 | :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}", | |
107 | :rel => 'nofollow' } |
|
108 | :rel => 'nofollow' } | |
108 | end |
|
109 | end | |
109 | end |
|
110 | end | |
110 |
|
111 | |||
111 | def test_other_formats_links_on_index_without_project_id_in_url |
|
112 | def test_other_formats_links_on_index_without_project_id_in_url | |
112 | get '/issues', :project_id => 'ecookbook' |
|
113 | get '/issues', :project_id => 'ecookbook' | |
113 |
|
114 | |||
114 | %w(Atom PDF CSV).each do |format| |
|
115 | %w(Atom PDF CSV).each do |format| | |
115 | assert_tag :a, :content => format, |
|
116 | assert_tag :a, :content => format, | |
116 | :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}", |
|
117 | :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}", | |
117 | :rel => 'nofollow' } |
|
118 | :rel => 'nofollow' } | |
118 | end |
|
119 | end | |
119 | end |
|
120 | end | |
120 |
|
121 | |||
121 | def test_pagination_links_on_index |
|
122 | def test_pagination_links_on_index | |
122 | Setting.per_page_options = '2' |
|
123 | Setting.per_page_options = '2' | |
123 | get '/projects/ecookbook/issues' |
|
124 | get '/projects/ecookbook/issues' | |
124 |
|
125 | |||
125 | assert_tag :a, :content => '2', |
|
126 | assert_tag :a, :content => '2', | |
126 | :attributes => { :href => '/projects/ecookbook/issues?page=2' } |
|
127 | :attributes => { :href => '/projects/ecookbook/issues?page=2' } | |
127 |
|
128 | |||
128 | end |
|
129 | end | |
129 |
|
130 | |||
130 | def test_pagination_links_on_index_without_project_id_in_url |
|
131 | def test_pagination_links_on_index_without_project_id_in_url | |
131 | Setting.per_page_options = '2' |
|
132 | Setting.per_page_options = '2' | |
132 | get '/issues', :project_id => 'ecookbook' |
|
133 | get '/issues', :project_id => 'ecookbook' | |
133 |
|
134 | |||
134 | assert_tag :a, :content => '2', |
|
135 | assert_tag :a, :content => '2', | |
135 | :attributes => { :href => '/projects/ecookbook/issues?page=2' } |
|
136 | :attributes => { :href => '/projects/ecookbook/issues?page=2' } | |
136 |
|
137 | |||
137 | end |
|
138 | end | |
138 |
|
139 | |||
139 | def test_issue_with_user_custom_field |
|
140 | def test_issue_with_user_custom_field | |
140 | @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all) |
|
141 | @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all) | |
141 | Role.anonymous.add_permission! :add_issues, :edit_issues |
|
142 | Role.anonymous.add_permission! :add_issues, :edit_issues | |
142 | users = Project.find(1).users |
|
143 | users = Project.find(1).users | |
143 | tester = users.first |
|
144 | tester = users.first | |
144 |
|
145 | |||
145 | # Issue form |
|
146 | # Issue form | |
146 | get '/projects/ecookbook/issues/new' |
|
147 | get '/projects/ecookbook/issues/new' | |
147 | assert_response :success |
|
148 | assert_response :success | |
148 | assert_tag :select, |
|
149 | assert_tag :select, | |
149 | :attributes => {:name => "issue[custom_field_values][#{@field.id}]"}, |
|
150 | :attributes => {:name => "issue[custom_field_values][#{@field.id}]"}, | |
150 | :children => {:count => (users.size + 1)}, # +1 for blank value |
|
151 | :children => {:count => (users.size + 1)}, # +1 for blank value | |
151 | :child => { |
|
152 | :child => { | |
152 | :tag => 'option', |
|
153 | :tag => 'option', | |
153 | :attributes => {:value => tester.id.to_s}, |
|
154 | :attributes => {:value => tester.id.to_s}, | |
154 | :content => tester.name |
|
155 | :content => tester.name | |
155 | } |
|
156 | } | |
156 |
|
157 | |||
157 | # Create issue |
|
158 | # Create issue | |
158 | assert_difference 'Issue.count' do |
|
159 | assert_difference 'Issue.count' do | |
159 | post '/projects/ecookbook/issues', |
|
160 | post '/projects/ecookbook/issues', | |
160 | :issue => { |
|
161 | :issue => { | |
161 | :tracker_id => '1', |
|
162 | :tracker_id => '1', | |
162 | :priority_id => '4', |
|
163 | :priority_id => '4', | |
163 | :subject => 'Issue with user custom field', |
|
164 | :subject => 'Issue with user custom field', | |
164 | :custom_field_values => {@field.id.to_s => users.first.id.to_s} |
|
165 | :custom_field_values => {@field.id.to_s => users.first.id.to_s} | |
165 | } |
|
166 | } | |
166 | end |
|
167 | end | |
167 | issue = Issue.first(:order => 'id DESC') |
|
168 | issue = Issue.first(:order => 'id DESC') | |
168 | assert_response 302 |
|
169 | assert_response 302 | |
169 |
|
170 | |||
170 | # Issue view |
|
171 | # Issue view | |
171 | follow_redirect! |
|
172 | follow_redirect! | |
172 | assert_tag :th, |
|
173 | assert_tag :th, | |
173 | :content => /Tester/, |
|
174 | :content => /Tester/, | |
174 | :sibling => { |
|
175 | :sibling => { | |
175 | :tag => 'td', |
|
176 | :tag => 'td', | |
176 | :content => tester.name |
|
177 | :content => tester.name | |
177 | } |
|
178 | } | |
178 | assert_tag :select, |
|
179 | assert_tag :select, | |
179 | :attributes => {:name => "issue[custom_field_values][#{@field.id}]"}, |
|
180 | :attributes => {:name => "issue[custom_field_values][#{@field.id}]"}, | |
180 | :children => {:count => (users.size + 1)}, # +1 for blank value |
|
181 | :children => {:count => (users.size + 1)}, # +1 for blank value | |
181 | :child => { |
|
182 | :child => { | |
182 | :tag => 'option', |
|
183 | :tag => 'option', | |
183 | :attributes => {:value => tester.id.to_s, :selected => 'selected'}, |
|
184 | :attributes => {:value => tester.id.to_s, :selected => 'selected'}, | |
184 | :content => tester.name |
|
185 | :content => tester.name | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | # Update issue |
|
188 | # Update issue | |
188 | new_tester = users[1] |
|
189 | new_tester = users[1] | |
189 | assert_difference 'Journal.count' do |
|
190 | assert_difference 'Journal.count' do | |
190 | put "/issues/#{issue.id}", |
|
191 | put "/issues/#{issue.id}", | |
191 | :notes => 'Updating custom field', |
|
192 | :notes => 'Updating custom field', | |
192 | :issue => { |
|
193 | :issue => { | |
193 | :custom_field_values => {@field.id.to_s => new_tester.id.to_s} |
|
194 | :custom_field_values => {@field.id.to_s => new_tester.id.to_s} | |
194 | } |
|
195 | } | |
195 | end |
|
196 | end | |
196 | assert_response 302 |
|
197 | assert_response 302 | |
197 |
|
198 | |||
198 | # Issue view |
|
199 | # Issue view | |
199 | follow_redirect! |
|
200 | follow_redirect! | |
200 | assert_tag :content => 'Tester', |
|
201 | assert_tag :content => 'Tester', | |
201 | :ancestor => {:tag => 'ul', :attributes => {:class => /details/}}, |
|
202 | :ancestor => {:tag => 'ul', :attributes => {:class => /details/}}, | |
202 | :sibling => { |
|
203 | :sibling => { | |
203 | :content => tester.name, |
|
204 | :content => tester.name, | |
204 | :sibling => { |
|
205 | :sibling => { | |
205 | :content => new_tester.name |
|
206 | :content => new_tester.name | |
206 | } |
|
207 | } | |
207 | } |
|
208 | } | |
208 | end |
|
209 | end | |
209 |
|
210 | |||
210 | def test_update_using_invalid_http_verbs |
|
211 | def test_update_using_invalid_http_verbs | |
211 | subject = 'Updated by an invalid http verb' |
|
212 | subject = 'Updated by an invalid http verb' | |
212 |
|
213 | |||
213 | get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith') |
|
214 | get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith') | |
214 | assert_response 404 |
|
215 | assert_response 404 | |
215 | assert_not_equal subject, Issue.find(1).subject |
|
216 | assert_not_equal subject, Issue.find(1).subject | |
216 |
|
217 | |||
217 | post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith') |
|
218 | post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith') | |
218 | assert_response 404 |
|
219 | assert_response 404 | |
219 | assert_not_equal subject, Issue.find(1).subject |
|
220 | assert_not_equal subject, Issue.find(1).subject | |
220 | end |
|
221 | end | |
221 |
|
222 | |||
222 | def test_get_watch_should_be_invalid |
|
223 | def test_get_watch_should_be_invalid | |
223 | assert_no_difference 'Watcher.count' do |
|
224 | assert_no_difference 'Watcher.count' do | |
224 | get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith') |
|
225 | get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith') | |
225 | assert_response 404 |
|
226 | assert_response 404 | |
226 | end |
|
227 | end | |
227 | end |
|
228 | end | |
228 | end |
|
229 | end |
General Comments 0
You need to be logged in to leave comments.
Login now