@@ -27,271 +27,209 class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base | |||||
27 | set_tmp_attachments_directory |
|
27 | set_tmp_attachments_directory | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | context "GET /projects" do |
|
30 | # TODO: A private project is needed because should_allow_api_authentication | |
31 | context ".xml" do |
|
31 | # actually tests that authentication is *required*, not just allowed | |
32 | should "return projects" do |
|
32 | should_allow_api_authentication(:get, "/projects/2.xml") | |
33 | get '/projects.xml' |
|
33 | should_allow_api_authentication(:get, "/projects/2.json") | |
34 | assert_response :success |
|
34 | should_allow_api_authentication(:post, | |
35 | assert_equal 'application/xml', @response.content_type |
|
35 | '/projects.xml', | |
36 |
|
36 | {:project => {:name => 'API test', :identifier => 'api-test'}}, | ||
37 | assert_tag :tag => 'projects', |
|
37 | {:success_code => :created}) | |
38 | :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}} |
|
38 | should_allow_api_authentication(:put, | |
39 | end |
|
39 | '/projects/2.xml', | |
40 | end |
|
40 | {:project => {:name => 'API update'}}, | |
|
41 | {:success_code => :ok}) | |||
|
42 | should_allow_api_authentication(:delete, | |||
|
43 | '/projects/2.xml', | |||
|
44 | {}, | |||
|
45 | {:success_code => :ok}) | |||
|
46 | ||||
|
47 | test "GET /projects.xml should return projects" do | |||
|
48 | get '/projects.xml' | |||
|
49 | assert_response :success | |||
|
50 | assert_equal 'application/xml', @response.content_type | |||
|
51 | ||||
|
52 | assert_tag :tag => 'projects', | |||
|
53 | :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}} | |||
|
54 | end | |||
|
55 | ||||
|
56 | test "GET /projects.json should return projects" do | |||
|
57 | get '/projects.json' | |||
|
58 | assert_response :success | |||
|
59 | assert_equal 'application/json', @response.content_type | |||
|
60 | ||||
|
61 | json = ActiveSupport::JSON.decode(response.body) | |||
|
62 | assert_kind_of Hash, json | |||
|
63 | assert_kind_of Array, json['projects'] | |||
|
64 | assert_kind_of Hash, json['projects'].first | |||
|
65 | assert json['projects'].first.has_key?('id') | |||
|
66 | end | |||
|
67 | ||||
|
68 | test "GET /projects/:id.xml should return the project" do | |||
|
69 | get '/projects/1.xml' | |||
|
70 | assert_response :success | |||
|
71 | assert_equal 'application/xml', @response.content_type | |||
|
72 | ||||
|
73 | assert_tag :tag => 'project', | |||
|
74 | :child => {:tag => 'id', :content => '1'} | |||
|
75 | assert_tag :tag => 'custom_field', | |||
|
76 | :attributes => {:name => 'Development status'}, :content => 'Stable' | |||
|
77 | ||||
|
78 | assert_no_tag 'trackers' | |||
|
79 | assert_no_tag 'issue_categories' | |||
|
80 | end | |||
|
81 | ||||
|
82 | test "GET /projects/:id.json should return the project" do | |||
|
83 | get '/projects/1.json' | |||
|
84 | ||||
|
85 | json = ActiveSupport::JSON.decode(response.body) | |||
|
86 | assert_kind_of Hash, json | |||
|
87 | assert_kind_of Hash, json['project'] | |||
|
88 | assert_equal 1, json['project']['id'] | |||
|
89 | end | |||
|
90 | ||||
|
91 | test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do | |||
|
92 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false | |||
|
93 | ||||
|
94 | get '/projects/1.xml' | |||
|
95 | assert_response :success | |||
|
96 | assert_equal 'application/xml', @response.content_type | |||
|
97 | ||||
|
98 | assert_no_tag 'custom_field', | |||
|
99 | :attributes => {:name => 'Development status'} | |||
|
100 | end | |||
41 |
|
101 | |||
42 | context ".json" do |
|
102 | test "GET /projects/:id.xml with include=issue_categories should return categories" do | |
43 | should "return projects" do |
|
103 | get '/projects/1.xml?include=issue_categories' | |
44 | get '/projects.json' |
|
104 | assert_response :success | |
45 | assert_response :success |
|
105 | assert_equal 'application/xml', @response.content_type | |
46 | assert_equal 'application/json', @response.content_type |
|
106 | ||
47 |
|
107 | assert_tag 'issue_categories', | ||
48 | json = ActiveSupport::JSON.decode(response.body) |
|
108 | :attributes => {:type => 'array'}, | |
49 | assert_kind_of Hash, json |
|
109 | :child => { | |
50 | assert_kind_of Array, json['projects'] |
|
110 | :tag => 'issue_category', | |
51 | assert_kind_of Hash, json['projects'].first |
|
111 | :attributes => { | |
52 | assert json['projects'].first.has_key?('id') |
|
112 | :id => '2', | |
53 | end |
|
113 | :name => 'Recipes' | |
|
114 | } | |||
|
115 | } | |||
|
116 | end | |||
|
117 | ||||
|
118 | test "GET /projects/:id.xml with include=trackers should return trackers" do | |||
|
119 | get '/projects/1.xml?include=trackers' | |||
|
120 | assert_response :success | |||
|
121 | assert_equal 'application/xml', @response.content_type | |||
|
122 | ||||
|
123 | assert_tag 'trackers', | |||
|
124 | :attributes => {:type => 'array'}, | |||
|
125 | :child => { | |||
|
126 | :tag => 'tracker', | |||
|
127 | :attributes => { | |||
|
128 | :id => '2', | |||
|
129 | :name => 'Feature request' | |||
|
130 | } | |||
|
131 | } | |||
|
132 | end | |||
|
133 | ||||
|
134 | test "POST /projects.xml with valid parameters should create the project" do | |||
|
135 | Setting.default_projects_modules = ['issue_tracking', 'repository'] | |||
|
136 | ||||
|
137 | assert_difference('Project.count') do | |||
|
138 | post '/projects.xml', | |||
|
139 | {:project => {:name => 'API test', :identifier => 'api-test'}}, | |||
|
140 | credentials('admin') | |||
54 | end |
|
141 | end | |
|
142 | ||||
|
143 | project = Project.first(:order => 'id DESC') | |||
|
144 | assert_equal 'API test', project.name | |||
|
145 | assert_equal 'api-test', project.identifier | |||
|
146 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort | |||
|
147 | assert_equal Tracker.all.size, project.trackers.size | |||
|
148 | ||||
|
149 | assert_response :created | |||
|
150 | assert_equal 'application/xml', @response.content_type | |||
|
151 | assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} | |||
55 | end |
|
152 | end | |
56 |
|
153 | |||
57 | context "GET /projects/:id" do |
|
154 | test "POST /projects.xml should accept enabled_module_names attribute" do | |
58 | context ".xml" do |
|
155 | assert_difference('Project.count') do | |
59 | # TODO: A private project is needed because should_allow_api_authentication |
|
156 | post '/projects.xml', | |
60 | # actually tests that authentication is *required*, not just allowed |
|
157 | {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, | |
61 | should_allow_api_authentication(:get, "/projects/2.xml") |
|
158 | credentials('admin') | |
62 |
|
||||
63 | should "return requested project" do |
|
|||
64 | get '/projects/1.xml' |
|
|||
65 | assert_response :success |
|
|||
66 | assert_equal 'application/xml', @response.content_type |
|
|||
67 |
|
||||
68 | assert_tag :tag => 'project', |
|
|||
69 | :child => {:tag => 'id', :content => '1'} |
|
|||
70 | assert_tag :tag => 'custom_field', |
|
|||
71 | :attributes => {:name => 'Development status'}, :content => 'Stable' |
|
|||
72 |
|
||||
73 | assert_no_tag 'trackers' |
|
|||
74 | assert_no_tag 'issue_categories' |
|
|||
75 | end |
|
|||
76 |
|
||||
77 | context "with hidden custom fields" do |
|
|||
78 | setup do |
|
|||
79 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false |
|
|||
80 | end |
|
|||
81 |
|
||||
82 | should "not display hidden custom fields" do |
|
|||
83 | get '/projects/1.xml' |
|
|||
84 | assert_response :success |
|
|||
85 | assert_equal 'application/xml', @response.content_type |
|
|||
86 |
|
||||
87 | assert_no_tag 'custom_field', |
|
|||
88 | :attributes => {:name => 'Development status'} |
|
|||
89 | end |
|
|||
90 | end |
|
|||
91 |
|
||||
92 | should "return categories with include=issue_categories" do |
|
|||
93 | get '/projects/1.xml?include=issue_categories' |
|
|||
94 | assert_response :success |
|
|||
95 | assert_equal 'application/xml', @response.content_type |
|
|||
96 |
|
||||
97 | assert_tag 'issue_categories', |
|
|||
98 | :attributes => {:type => 'array'}, |
|
|||
99 | :child => { |
|
|||
100 | :tag => 'issue_category', |
|
|||
101 | :attributes => { |
|
|||
102 | :id => '2', |
|
|||
103 | :name => 'Recipes' |
|
|||
104 | } |
|
|||
105 | } |
|
|||
106 | end |
|
|||
107 |
|
||||
108 | should "return trackers with include=trackers" do |
|
|||
109 | get '/projects/1.xml?include=trackers' |
|
|||
110 | assert_response :success |
|
|||
111 | assert_equal 'application/xml', @response.content_type |
|
|||
112 |
|
||||
113 | assert_tag 'trackers', |
|
|||
114 | :attributes => {:type => 'array'}, |
|
|||
115 | :child => { |
|
|||
116 | :tag => 'tracker', |
|
|||
117 | :attributes => { |
|
|||
118 | :id => '2', |
|
|||
119 | :name => 'Feature request' |
|
|||
120 | } |
|
|||
121 | } |
|
|||
122 | end |
|
|||
123 | end |
|
159 | end | |
124 |
|
160 | |||
125 | context ".json" do |
|
161 | project = Project.first(:order => 'id DESC') | |
126 | should_allow_api_authentication(:get, "/projects/2.json") |
|
162 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort | |
|
163 | end | |||
127 |
|
164 | |||
128 | should "return requested project" do |
|
165 | test "POST /projects.xml should accept tracker_ids attribute" do | |
129 | get '/projects/1.json' |
|
166 | assert_difference('Project.count') do | |
|
167 | post '/projects.xml', | |||
|
168 | {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}}, | |||
|
169 | credentials('admin') | |||
|
170 | end | |||
|
171 | ||||
|
172 | project = Project.first(:order => 'id DESC') | |||
|
173 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
174 | end | |||
130 |
|
175 | |||
131 | json = ActiveSupport::JSON.decode(response.body) |
|
176 | test "POST /projects.xml with invalid parameters should return errors" do | |
132 | assert_kind_of Hash, json |
|
177 | assert_no_difference('Project.count') do | |
133 | assert_kind_of Hash, json['project'] |
|
178 | post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin') | |
134 | assert_equal 1, json['project']['id'] |
|
|||
135 | end |
|
|||
136 | end |
|
179 | end | |
|
180 | ||||
|
181 | assert_response :unprocessable_entity | |||
|
182 | assert_equal 'application/xml', @response.content_type | |||
|
183 | assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"} | |||
137 | end |
|
184 | end | |
138 |
|
185 | |||
139 | context "POST /projects" do |
|
186 | test "PUT /projects/:id.xml with valid parameters should update the project" do | |
140 | context "with valid parameters" do |
|
187 | assert_no_difference 'Project.count' do | |
141 | setup do |
|
188 | put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith') | |
142 | Setting.default_projects_modules = ['issue_tracking', 'repository'] |
|
|||
143 | @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}} |
|
|||
144 | end |
|
|||
145 |
|
||||
146 | context ".xml" do |
|
|||
147 | should_allow_api_authentication(:post, |
|
|||
148 | '/projects.xml', |
|
|||
149 | {:project => {:name => 'API test', :identifier => 'api-test'}}, |
|
|||
150 | {:success_code => :created}) |
|
|||
151 |
|
||||
152 |
|
||||
153 | should "create a project with the attributes" do |
|
|||
154 | assert_difference('Project.count') do |
|
|||
155 | post '/projects.xml', @parameters, credentials('admin') |
|
|||
156 | end |
|
|||
157 |
|
||||
158 | project = Project.first(:order => 'id DESC') |
|
|||
159 | assert_equal 'API test', project.name |
|
|||
160 | assert_equal 'api-test', project.identifier |
|
|||
161 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort |
|
|||
162 | assert_equal Tracker.all.size, project.trackers.size |
|
|||
163 |
|
||||
164 | assert_response :created |
|
|||
165 | assert_equal 'application/xml', @response.content_type |
|
|||
166 | assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} |
|
|||
167 | end |
|
|||
168 |
|
||||
169 | should "accept enabled_module_names attribute" do |
|
|||
170 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) |
|
|||
171 |
|
||||
172 | assert_difference('Project.count') do |
|
|||
173 | post '/projects.xml', @parameters, credentials('admin') |
|
|||
174 | end |
|
|||
175 |
|
||||
176 | project = Project.first(:order => 'id DESC') |
|
|||
177 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort |
|
|||
178 | end |
|
|||
179 |
|
||||
180 | should "accept tracker_ids attribute" do |
|
|||
181 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) |
|
|||
182 |
|
||||
183 | assert_difference('Project.count') do |
|
|||
184 | post '/projects.xml', @parameters, credentials('admin') |
|
|||
185 | end |
|
|||
186 |
|
||||
187 | project = Project.first(:order => 'id DESC') |
|
|||
188 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
|||
189 | end |
|
|||
190 | end |
|
|||
191 | end |
|
189 | end | |
|
190 | assert_response :ok | |||
|
191 | assert_equal '', @response.body | |||
|
192 | assert_equal 'application/xml', @response.content_type | |||
|
193 | project = Project.find(2) | |||
|
194 | assert_equal 'API update', project.name | |||
|
195 | end | |||
192 |
|
196 | |||
193 | context "with invalid parameters" do |
|
197 | test "PUT /projects/:id.xml should accept enabled_module_names attribute" do | |
194 | setup do |
|
198 | assert_no_difference 'Project.count' do | |
195 | @parameters = {:project => {:name => 'API test'}} |
|
199 | put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin') | |
196 | end |
|
|||
197 |
|
||||
198 | context ".xml" do |
|
|||
199 | should "return errors" do |
|
|||
200 | assert_no_difference('Project.count') do |
|
|||
201 | post '/projects.xml', @parameters, credentials('admin') |
|
|||
202 | end |
|
|||
203 |
|
||||
204 | assert_response :unprocessable_entity |
|
|||
205 | assert_equal 'application/xml', @response.content_type |
|
|||
206 | assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"} |
|
|||
207 | end |
|
|||
208 | end |
|
|||
209 | end |
|
200 | end | |
|
201 | assert_response :ok | |||
|
202 | assert_equal '', @response.body | |||
|
203 | project = Project.find(2) | |||
|
204 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort | |||
210 | end |
|
205 | end | |
211 |
|
206 | |||
212 | context "PUT /projects/:id" do |
|
207 | test "PUT /projects/:id.xml should accept tracker_ids attribute" do | |
213 | context "with valid parameters" do |
|
208 | assert_no_difference 'Project.count' do | |
214 | setup do |
|
209 | put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin') | |
215 | @parameters = {:project => {:name => 'API update'}} |
|
|||
216 | end |
|
|||
217 |
|
||||
218 | context ".xml" do |
|
|||
219 | should_allow_api_authentication(:put, |
|
|||
220 | '/projects/2.xml', |
|
|||
221 | {:project => {:name => 'API update'}}, |
|
|||
222 | {:success_code => :ok}) |
|
|||
223 |
|
||||
224 | should "update the project" do |
|
|||
225 | assert_no_difference 'Project.count' do |
|
|||
226 | put '/projects/2.xml', @parameters, credentials('jsmith') |
|
|||
227 | end |
|
|||
228 | assert_response :ok |
|
|||
229 | assert_equal '', @response.body |
|
|||
230 | assert_equal 'application/xml', @response.content_type |
|
|||
231 | project = Project.find(2) |
|
|||
232 | assert_equal 'API update', project.name |
|
|||
233 | end |
|
|||
234 |
|
||||
235 | should "accept enabled_module_names attribute" do |
|
|||
236 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) |
|
|||
237 |
|
||||
238 | assert_no_difference 'Project.count' do |
|
|||
239 | put '/projects/2.xml', @parameters, credentials('admin') |
|
|||
240 | end |
|
|||
241 | assert_response :ok |
|
|||
242 | assert_equal '', @response.body |
|
|||
243 | project = Project.find(2) |
|
|||
244 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort |
|
|||
245 | end |
|
|||
246 |
|
||||
247 | should "accept tracker_ids attribute" do |
|
|||
248 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) |
|
|||
249 |
|
||||
250 | assert_no_difference 'Project.count' do |
|
|||
251 | put '/projects/2.xml', @parameters, credentials('admin') |
|
|||
252 | end |
|
|||
253 | assert_response :ok |
|
|||
254 | assert_equal '', @response.body |
|
|||
255 | project = Project.find(2) |
|
|||
256 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
|||
257 | end |
|
|||
258 | end |
|
|||
259 | end |
|
210 | end | |
|
211 | assert_response :ok | |||
|
212 | assert_equal '', @response.body | |||
|
213 | project = Project.find(2) | |||
|
214 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
215 | end | |||
260 |
|
216 | |||
261 | context "with invalid parameters" do |
|
217 | test "PUT /projects/:id.xml with invalid parameters should return errors" do | |
262 | setup do |
|
218 | assert_no_difference('Project.count') do | |
263 | @parameters = {:project => {:name => ''}} |
|
219 | put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin') | |
264 | end |
|
|||
265 |
|
||||
266 | context ".xml" do |
|
|||
267 | should "return errors" do |
|
|||
268 | assert_no_difference('Project.count') do |
|
|||
269 | put '/projects/2.xml', @parameters, credentials('admin') |
|
|||
270 | end |
|
|||
271 |
|
||||
272 | assert_response :unprocessable_entity |
|
|||
273 | assert_equal 'application/xml', @response.content_type |
|
|||
274 | assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} |
|
|||
275 | end |
|
|||
276 | end |
|
|||
277 | end |
|
220 | end | |
|
221 | ||||
|
222 | assert_response :unprocessable_entity | |||
|
223 | assert_equal 'application/xml', @response.content_type | |||
|
224 | assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} | |||
278 | end |
|
225 | end | |
279 |
|
226 | |||
280 |
|
|
227 | test "DELETE /projects/:id.xml should delete the project" do | |
281 | context ".xml" do |
|
228 | assert_difference('Project.count',-1) do | |
282 | should_allow_api_authentication(:delete, |
|
229 | delete '/projects/2.xml', {}, credentials('admin') | |
283 | '/projects/2.xml', |
|
|||
284 | {}, |
|
|||
285 | {:success_code => :ok}) |
|
|||
286 |
|
||||
287 | should "delete the project" do |
|
|||
288 | assert_difference('Project.count',-1) do |
|
|||
289 | delete '/projects/2.xml', {}, credentials('admin') |
|
|||
290 | end |
|
|||
291 | assert_response :ok |
|
|||
292 | assert_equal '', @response.body |
|
|||
293 | assert_nil Project.find_by_id(2) |
|
|||
294 | end |
|
|||
295 | end |
|
230 | end | |
|
231 | assert_response :ok | |||
|
232 | assert_equal '', @response.body | |||
|
233 | assert_nil Project.find_by_id(2) | |||
296 | end |
|
234 | end | |
297 | end |
|
235 | end |
@@ -31,28 +31,23 class Redmine::ApiTest::QueriesTest < Redmine::ApiTest::Base | |||||
31 | Setting.rest_api_enabled = '1' |
|
31 | Setting.rest_api_enabled = '1' | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | context "/queries" do |
|
34 | test "GET /queries.xml should return queries" do | |
35 | context "GET" do |
|
35 | get '/queries.xml' | |
36 |
|
36 | |||
37 | should "return queries" do |
|
37 | assert_response :success | |
38 | get '/queries.xml' |
|
38 | assert_equal 'application/xml', @response.content_type | |
39 |
|
39 | assert_tag :tag => 'queries', | ||
40 | assert_response :success |
|
40 | :attributes => {:type => 'array'}, | |
41 | assert_equal 'application/xml', @response.content_type |
|
41 | :child => { | |
42 |
|
|
42 | :tag => 'query', | |
43 | :attributes => {:type => 'array'}, |
|
43 | :child => { | |
44 |
: |
|
44 | :tag => 'id', | |
45 |
|
|
45 | :content => '4', | |
46 |
|
|
46 | :sibling => { | |
47 |
|
|
47 | :tag => 'name', | |
48 |
|
|
48 | :content => 'Public query for all projects' | |
49 | :sibling => { |
|
|||
50 | :tag => 'name', |
|
|||
51 | :content => 'Public query for all projects' |
|
|||
52 | } |
|
|||
53 | } |
|
|||
54 | } |
|
49 | } | |
55 |
|
|
50 | } | |
56 | end |
|
51 | } | |
57 | end |
|
52 | end | |
58 | end |
|
53 | end |
@@ -24,66 +24,52 class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base | |||||
24 | Setting.rest_api_enabled = '1' |
|
24 | Setting.rest_api_enabled = '1' | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | context "/roles" do |
|
27 | test "GET /roles.xml should return the roles" do | |
28 | context "GET" do |
|
28 | get '/roles.xml' | |
29 | context "xml" do |
|
|||
30 | should "return the roles" do |
|
|||
31 | get '/roles.xml' |
|
|||
32 |
|
29 | |||
33 |
|
|
30 | assert_response :success | |
34 |
|
|
31 | assert_equal 'application/xml', @response.content_type | |
35 |
|
|
32 | assert_equal 3, assigns(:roles).size | |
36 |
|
33 | |||
37 |
|
|
34 | assert_tag :tag => 'roles', | |
38 |
|
|
35 | :attributes => {:type => 'array'}, | |
39 |
|
|
36 | :child => { | |
40 |
|
|
37 | :tag => 'role', | |
41 |
|
|
38 | :child => { | |
42 |
|
|
39 | :tag => 'id', | |
43 |
|
|
40 | :content => '2', | |
44 |
|
|
41 | :sibling => { | |
45 |
|
|
42 | :tag => 'name', | |
46 |
|
|
43 | :content => 'Developer' | |
47 |
|
|
44 | } | |
48 |
|
|
45 | } | |
49 |
|
|
46 | } | |
50 |
|
|
47 | end | |
51 | end |
|
|||
52 |
|
48 | |||
53 | context "json" do |
|
49 | test "GET /roles.json should return the roles" do | |
54 | should "return the roles" do |
|
50 | get '/roles.json' | |
55 | get '/roles.json' |
|
|||
56 |
|
51 | |||
57 |
|
|
52 | assert_response :success | |
58 |
|
|
53 | assert_equal 'application/json', @response.content_type | |
59 |
|
|
54 | assert_equal 3, assigns(:roles).size | |
60 |
|
55 | |||
61 |
|
|
56 | json = ActiveSupport::JSON.decode(response.body) | |
62 |
|
|
57 | assert_kind_of Hash, json | |
63 |
|
|
58 | assert_kind_of Array, json['roles'] | |
64 |
|
|
59 | assert_include({'id' => 2, 'name' => 'Developer'}, json['roles']) | |
65 | end |
|
|||
66 | end |
|
|||
67 | end |
|
|||
68 | end |
|
60 | end | |
69 |
|
61 | |||
70 | context "/roles/:id" do |
|
62 | test "GET /roles/:id.xml should return the role" do | |
71 | context "GET" do |
|
63 | get '/roles/1.xml' | |
72 | context "xml" do |
|
|||
73 | should "return the role" do |
|
|||
74 | get '/roles/1.xml' |
|
|||
75 |
|
64 | |||
76 |
|
|
65 | assert_response :success | |
77 |
|
|
66 | assert_equal 'application/xml', @response.content_type | |
78 |
|
67 | |||
79 |
|
|
68 | assert_select 'role' do | |
80 |
|
|
69 | assert_select 'name', :text => 'Manager' | |
81 |
|
|
70 | assert_select 'role permissions[type=array]' do | |
82 |
|
|
71 | assert_select 'permission', Role.find(1).permissions.size | |
83 |
|
|
72 | assert_select 'permission', :text => 'view_issues' | |
84 | end |
|
|||
85 | end |
|
|||
86 | end |
|
|||
87 | end |
|
73 | end | |
88 | end |
|
74 | end | |
89 | end |
|
75 | end |
@@ -31,134 +31,112 class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base | |||||
31 | Setting.rest_api_enabled = '1' |
|
31 | Setting.rest_api_enabled = '1' | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 |
|
|
34 | test "GET /time_entries.xml should return time entries" do | |
35 | should "return time entries" do |
|
35 | get '/time_entries.xml', {}, credentials('jsmith') | |
36 | get '/time_entries.xml', {}, credentials('jsmith') |
|
36 | assert_response :success | |
37 | assert_response :success |
|
37 | assert_equal 'application/xml', @response.content_type | |
38 | assert_equal 'application/xml', @response.content_type |
|
38 | assert_tag :tag => 'time_entries', | |
39 | assert_tag :tag => 'time_entries', |
|
39 | :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} | |
40 | :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} |
|
40 | end | |
41 | end |
|
|||
42 |
|
41 | |||
43 | context "with limit" do |
|
42 | test "GET /time_entries.xml with limit should return limited results" do | |
44 | should "return limited results" do |
|
43 | get '/time_entries.xml?limit=2', {}, credentials('jsmith') | |
45 | get '/time_entries.xml?limit=2', {}, credentials('jsmith') |
|
44 | assert_response :success | |
46 | assert_response :success |
|
45 | assert_equal 'application/xml', @response.content_type | |
47 | assert_equal 'application/xml', @response.content_type |
|
46 | assert_tag :tag => 'time_entries', | |
48 | assert_tag :tag => 'time_entries', |
|
47 | :children => {:count => 2} | |
49 | :children => {:count => 2} |
|
|||
50 | end |
|
|||
51 | end |
|
|||
52 | end |
|
48 | end | |
53 |
|
49 | |||
54 |
|
|
50 | test "GET /time_entries/:id.xml should return the time entry" do | |
55 | should "return requested time entry" do |
|
51 | get '/time_entries/2.xml', {}, credentials('jsmith') | |
56 | get '/time_entries/2.xml', {}, credentials('jsmith') |
|
52 | assert_response :success | |
57 | assert_response :success |
|
53 | assert_equal 'application/xml', @response.content_type | |
58 | assert_equal 'application/xml', @response.content_type |
|
54 | assert_tag :tag => 'time_entry', | |
59 | assert_tag :tag => 'time_entry', |
|
55 | :child => {:tag => 'id', :content => '2'} | |
60 | :child => {:tag => 'id', :content => '2'} |
|
|||
61 | end |
|
|||
62 | end |
|
56 | end | |
63 |
|
57 | |||
64 |
|
|
58 | test "POST /time_entries.xml with issue_id should create time entry" do | |
65 | context "with issue_id" do |
|
59 | assert_difference 'TimeEntry.count' do | |
66 | should "return create time entry" do |
|
60 | post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') | |
67 | assert_difference 'TimeEntry.count' do |
|
|||
68 | post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') |
|
|||
69 | end |
|
|||
70 | assert_response :created |
|
|||
71 | assert_equal 'application/xml', @response.content_type |
|
|||
72 |
|
||||
73 | entry = TimeEntry.first(:order => 'id DESC') |
|
|||
74 | assert_equal 'jsmith', entry.user.login |
|
|||
75 | assert_equal Issue.find(1), entry.issue |
|
|||
76 | assert_equal Project.find(1), entry.project |
|
|||
77 | assert_equal Date.parse('2010-12-02'), entry.spent_on |
|
|||
78 | assert_equal 3.5, entry.hours |
|
|||
79 | assert_equal TimeEntryActivity.find(11), entry.activity |
|
|||
80 | end |
|
|||
81 |
|
||||
82 | should "accept custom fields" do |
|
|||
83 | field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') |
|
|||
84 |
|
||||
85 | assert_difference 'TimeEntry.count' do |
|
|||
86 | post '/time_entries.xml', {:time_entry => { |
|
|||
87 | :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] |
|
|||
88 | }}, credentials('jsmith') |
|
|||
89 | end |
|
|||
90 | assert_response :created |
|
|||
91 | assert_equal 'application/xml', @response.content_type |
|
|||
92 |
|
||||
93 | entry = TimeEntry.first(:order => 'id DESC') |
|
|||
94 | assert_equal 'accepted', entry.custom_field_value(field) |
|
|||
95 | end |
|
|||
96 | end |
|
61 | end | |
|
62 | assert_response :created | |||
|
63 | assert_equal 'application/xml', @response.content_type | |||
|
64 | ||||
|
65 | entry = TimeEntry.first(:order => 'id DESC') | |||
|
66 | assert_equal 'jsmith', entry.user.login | |||
|
67 | assert_equal Issue.find(1), entry.issue | |||
|
68 | assert_equal Project.find(1), entry.project | |||
|
69 | assert_equal Date.parse('2010-12-02'), entry.spent_on | |||
|
70 | assert_equal 3.5, entry.hours | |||
|
71 | assert_equal TimeEntryActivity.find(11), entry.activity | |||
|
72 | end | |||
|
73 | ||||
|
74 | test "POST /time_entries.xml with issue_id should accept custom fields" do | |||
|
75 | field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') | |||
97 |
|
76 | |||
98 | context "with project_id" do |
|
77 | assert_difference 'TimeEntry.count' do | |
99 | should "return create time entry" do |
|
78 | post '/time_entries.xml', {:time_entry => { | |
100 | assert_difference 'TimeEntry.count' do |
|
79 | :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] | |
101 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') |
|
80 | }}, credentials('jsmith') | |
102 | end |
|
|||
103 | assert_response :created |
|
|||
104 | assert_equal 'application/xml', @response.content_type |
|
|||
105 |
|
||||
106 | entry = TimeEntry.first(:order => 'id DESC') |
|
|||
107 | assert_equal 'jsmith', entry.user.login |
|
|||
108 | assert_nil entry.issue |
|
|||
109 | assert_equal Project.find(1), entry.project |
|
|||
110 | assert_equal Date.parse('2010-12-02'), entry.spent_on |
|
|||
111 | assert_equal 3.5, entry.hours |
|
|||
112 | assert_equal TimeEntryActivity.find(11), entry.activity |
|
|||
113 | end |
|
|||
114 | end |
|
81 | end | |
|
82 | assert_response :created | |||
|
83 | assert_equal 'application/xml', @response.content_type | |||
115 |
|
84 | |||
116 | context "with invalid parameters" do |
|
85 | entry = TimeEntry.first(:order => 'id DESC') | |
117 | should "return errors" do |
|
86 | assert_equal 'accepted', entry.custom_field_value(field) | |
118 | assert_no_difference 'TimeEntry.count' do |
|
87 | end | |
119 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') |
|
|||
120 | end |
|
|||
121 | assert_response :unprocessable_entity |
|
|||
122 | assert_equal 'application/xml', @response.content_type |
|
|||
123 |
|
88 | |||
124 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
|
89 | test "POST /time_entries.xml with project_id should create time entry" do | |
125 | end |
|
90 | assert_difference 'TimeEntry.count' do | |
|
91 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') | |||
126 | end |
|
92 | end | |
|
93 | assert_response :created | |||
|
94 | assert_equal 'application/xml', @response.content_type | |||
|
95 | ||||
|
96 | entry = TimeEntry.first(:order => 'id DESC') | |||
|
97 | assert_equal 'jsmith', entry.user.login | |||
|
98 | assert_nil entry.issue | |||
|
99 | assert_equal Project.find(1), entry.project | |||
|
100 | assert_equal Date.parse('2010-12-02'), entry.spent_on | |||
|
101 | assert_equal 3.5, entry.hours | |||
|
102 | assert_equal TimeEntryActivity.find(11), entry.activity | |||
127 | end |
|
103 | end | |
128 |
|
104 | |||
129 | context "PUT /time_entries/2.xml" do |
|
105 | test "POST /time_entries.xml with invalid parameters should return errors" do | |
130 | context "with valid parameters" do |
|
106 | assert_no_difference 'TimeEntry.count' do | |
131 | should "update time entry" do |
|
107 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') | |
132 | assert_no_difference 'TimeEntry.count' do |
|
|||
133 | put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') |
|
|||
134 | end |
|
|||
135 | assert_response :ok |
|
|||
136 | assert_equal '', @response.body |
|
|||
137 | assert_equal 'API Update', TimeEntry.find(2).comments |
|
|||
138 | end |
|
|||
139 | end |
|
108 | end | |
|
109 | assert_response :unprocessable_entity | |||
|
110 | assert_equal 'application/xml', @response.content_type | |||
|
111 | ||||
|
112 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | |||
|
113 | end | |||
140 |
|
114 | |||
141 | context "with invalid parameters" do |
|
115 | test "PUT /time_entries/:id.xml with valid parameters should update time entry" do | |
142 | should "return errors" do |
|
116 | assert_no_difference 'TimeEntry.count' do | |
143 | assert_no_difference 'TimeEntry.count' do |
|
117 | put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') | |
144 | put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') |
|
118 | end | |
145 | end |
|
119 | assert_response :ok | |
146 | assert_response :unprocessable_entity |
|
120 | assert_equal '', @response.body | |
147 | assert_equal 'application/xml', @response.content_type |
|
121 | assert_equal 'API Update', TimeEntry.find(2).comments | |
|
122 | end | |||
148 |
|
123 | |||
149 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
|
124 | test "PUT /time_entries/:id.xml with invalid parameters should return errors" do | |
150 | end |
|
125 | assert_no_difference 'TimeEntry.count' do | |
|
126 | put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') | |||
151 | end |
|
127 | end | |
|
128 | assert_response :unprocessable_entity | |||
|
129 | assert_equal 'application/xml', @response.content_type | |||
|
130 | ||||
|
131 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | |||
152 | end |
|
132 | end | |
153 |
|
133 | |||
154 |
|
|
134 | test "DELETE /time_entries/:id.xml should destroy time entry" do | |
155 | should "destroy time entry" do |
|
135 | assert_difference 'TimeEntry.count', -1 do | |
156 | assert_difference 'TimeEntry.count', -1 do |
|
136 | delete '/time_entries/2.xml', {}, credentials('jsmith') | |
157 | delete '/time_entries/2.xml', {}, credentials('jsmith') |
|
|||
158 | end |
|
|||
159 | assert_response :ok |
|
|||
160 | assert_equal '', @response.body |
|
|||
161 | assert_nil TimeEntry.find_by_id(2) |
|
|||
162 | end |
|
137 | end | |
|
138 | assert_response :ok | |||
|
139 | assert_equal '', @response.body | |||
|
140 | assert_nil TimeEntry.find_by_id(2) | |||
163 | end |
|
141 | end | |
164 | end |
|
142 | end |
@@ -37,13 +37,6 class Redmine::ApiTest::TokenAuthenticationTest < Redmine::ApiTest::Base | |||||
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | # Using the NewsController because it's a simple API. |
|
39 | # Using the NewsController because it's a simple API. | |
40 | context "get /news" do |
|
40 | should_allow_key_based_auth(:get, "/news.xml") | |
41 | context "in :xml format" do |
|
41 | should_allow_key_based_auth(:get, "/news.json") | |
42 | should_allow_key_based_auth(:get, "/news.xml") |
|
|||
43 | end |
|
|||
44 |
|
||||
45 | context "in :json format" do |
|
|||
46 | should_allow_key_based_auth(:get, "/news.json") |
|
|||
47 | end |
|
|||
48 | end |
|
|||
49 | end |
|
42 | end |
@@ -24,28 +24,23 class Redmine::ApiTest::TrackersTest < Redmine::ApiTest::Base | |||||
24 | Setting.rest_api_enabled = '1' |
|
24 | Setting.rest_api_enabled = '1' | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | context "/trackers" do |
|
27 | test "GET /trackers.xml should return trackers" do | |
28 | context "GET" do |
|
28 | get '/trackers.xml' | |
29 |
|
29 | |||
30 | should "return trackers" do |
|
30 | assert_response :success | |
31 | get '/trackers.xml' |
|
31 | assert_equal 'application/xml', @response.content_type | |
32 |
|
32 | assert_tag :tag => 'trackers', | ||
33 | assert_response :success |
|
33 | :attributes => {:type => 'array'}, | |
34 | assert_equal 'application/xml', @response.content_type |
|
34 | :child => { | |
35 |
|
|
35 | :tag => 'tracker', | |
36 | :attributes => {:type => 'array'}, |
|
36 | :child => { | |
37 |
: |
|
37 | :tag => 'id', | |
38 |
|
|
38 | :content => '2', | |
39 |
|
|
39 | :sibling => { | |
40 |
|
|
40 | :tag => 'name', | |
41 |
|
|
41 | :content => 'Feature request' | |
42 | :sibling => { |
|
|||
43 | :tag => 'name', |
|
|||
44 | :content => 'Feature request' |
|
|||
45 | } |
|
|||
46 | } |
|
|||
47 | } |
|
42 | } | |
48 |
|
|
43 | } | |
49 | end |
|
44 | } | |
50 | end |
|
45 | end | |
51 | end |
|
46 | end |
This diff has been collapsed as it changes many lines, (532 lines changed) Show them Hide them | |||||
@@ -24,76 +24,96 class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base | |||||
24 | Setting.rest_api_enabled = '1' |
|
24 | Setting.rest_api_enabled = '1' | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | context "GET /users" do |
|
27 | should_allow_api_authentication(:get, "/users.xml") | |
28 |
|
|
28 | should_allow_api_authentication(:get, "/users.json") | |
29 |
|
|
29 | should_allow_api_authentication(:post, | |
|
30 | '/users.xml', | |||
|
31 | {:user => { | |||
|
32 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |||
|
33 | :mail => 'foo@example.net', :password => 'secret123' | |||
|
34 | }}, | |||
|
35 | {:success_code => :created}) | |||
|
36 | should_allow_api_authentication(:post, | |||
|
37 | '/users.json', | |||
|
38 | {:user => { | |||
|
39 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |||
|
40 | :mail => 'foo@example.net' | |||
|
41 | }}, | |||
|
42 | {:success_code => :created}) | |||
|
43 | should_allow_api_authentication(:put, | |||
|
44 | '/users/2.xml', | |||
|
45 | {:user => { | |||
|
46 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |||
|
47 | :mail => 'jsmith@somenet.foo' | |||
|
48 | }}, | |||
|
49 | {:success_code => :ok}) | |||
|
50 | should_allow_api_authentication(:put, | |||
|
51 | '/users/2.json', | |||
|
52 | {:user => { | |||
|
53 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |||
|
54 | :mail => 'jsmith@somenet.foo' | |||
|
55 | }}, | |||
|
56 | {:success_code => :ok}) | |||
|
57 | should_allow_api_authentication(:delete, | |||
|
58 | '/users/2.xml', | |||
|
59 | {}, | |||
|
60 | {:success_code => :ok}) | |||
|
61 | should_allow_api_authentication(:delete, | |||
|
62 | '/users/2.xml', | |||
|
63 | {}, | |||
|
64 | {:success_code => :ok}) | |||
|
65 | ||||
|
66 | test "GET /users/:id.xml should return the user" do | |||
|
67 | get '/users/2.xml' | |||
|
68 | ||||
|
69 | assert_response :success | |||
|
70 | assert_tag :tag => 'user', | |||
|
71 | :child => {:tag => 'id', :content => '2'} | |||
30 | end |
|
72 | end | |
31 |
|
73 | |||
32 | context "GET /users/2" do |
|
74 | test "GET /users/:id.json should return the user" do | |
33 | context ".xml" do |
|
75 | get '/users/2.json' | |
34 | should "return requested user" do |
|
|||
35 | get '/users/2.xml' |
|
|||
36 |
|
||||
37 | assert_response :success |
|
|||
38 | assert_tag :tag => 'user', |
|
|||
39 | :child => {:tag => 'id', :content => '2'} |
|
|||
40 | end |
|
|||
41 |
|
||||
42 | context "with include=memberships" do |
|
|||
43 | should "include memberships" do |
|
|||
44 | get '/users/2.xml?include=memberships' |
|
|||
45 |
|
||||
46 | assert_response :success |
|
|||
47 | assert_tag :tag => 'memberships', |
|
|||
48 | :parent => {:tag => 'user'}, |
|
|||
49 | :children => {:count => 1} |
|
|||
50 | end |
|
|||
51 | end |
|
|||
52 | end |
|
|||
53 |
|
76 | |||
54 | context ".json" do |
|
77 | assert_response :success | |
55 | should "return requested user" do |
|
78 | json = ActiveSupport::JSON.decode(response.body) | |
56 | get '/users/2.json' |
|
79 | assert_kind_of Hash, json | |
57 |
|
80 | assert_kind_of Hash, json['user'] | ||
58 | assert_response :success |
|
81 | assert_equal 2, json['user']['id'] | |
59 | json = ActiveSupport::JSON.decode(response.body) |
|
|||
60 | assert_kind_of Hash, json |
|
|||
61 | assert_kind_of Hash, json['user'] |
|
|||
62 | assert_equal 2, json['user']['id'] |
|
|||
63 | end |
|
|||
64 |
|
||||
65 | context "with include=memberships" do |
|
|||
66 | should "include memberships" do |
|
|||
67 | get '/users/2.json?include=memberships' |
|
|||
68 |
|
||||
69 | assert_response :success |
|
|||
70 | json = ActiveSupport::JSON.decode(response.body) |
|
|||
71 | assert_kind_of Array, json['user']['memberships'] |
|
|||
72 | assert_equal [{ |
|
|||
73 | "id"=>1, |
|
|||
74 | "project"=>{"name"=>"eCookbook", "id"=>1}, |
|
|||
75 | "roles"=>[{"name"=>"Manager", "id"=>1}] |
|
|||
76 | }], json['user']['memberships'] |
|
|||
77 | end |
|
|||
78 | end |
|
|||
79 | end |
|
|||
80 | end |
|
82 | end | |
81 |
|
83 | |||
82 | context "GET /users/current" do |
|
84 | test "GET /users/:id.xml with include=memberships should include memberships" do | |
83 | context ".xml" do |
|
85 | get '/users/2.xml?include=memberships' | |
84 | should "require authentication" do |
|
|||
85 | get '/users/current.xml' |
|
|||
86 |
|
86 | |||
87 |
|
|
87 | assert_response :success | |
88 | end |
|
88 | assert_tag :tag => 'memberships', | |
|
89 | :parent => {:tag => 'user'}, | |||
|
90 | :children => {:count => 1} | |||
|
91 | end | |||
89 |
|
92 | |||
90 | should "return current user" do |
|
93 | test "GET /users/:id.json with include=memberships should include memberships" do | |
91 | get '/users/current.xml', {}, credentials('jsmith') |
|
94 | get '/users/2.json?include=memberships' | |
92 |
|
95 | |||
93 | assert_tag :tag => 'user', |
|
96 | assert_response :success | |
94 | :child => {:tag => 'id', :content => '2'} |
|
97 | json = ActiveSupport::JSON.decode(response.body) | |
95 | end |
|
98 | assert_kind_of Array, json['user']['memberships'] | |
96 | end |
|
99 | assert_equal [{ | |
|
100 | "id"=>1, | |||
|
101 | "project"=>{"name"=>"eCookbook", "id"=>1}, | |||
|
102 | "roles"=>[{"name"=>"Manager", "id"=>1}] | |||
|
103 | }], json['user']['memberships'] | |||
|
104 | end | |||
|
105 | ||||
|
106 | test "GET /users/current.xml should require authentication" do | |||
|
107 | get '/users/current.xml' | |||
|
108 | ||||
|
109 | assert_response 401 | |||
|
110 | end | |||
|
111 | ||||
|
112 | test "GET /users/current.xml should return current user" do | |||
|
113 | get '/users/current.xml', {}, credentials('jsmith') | |||
|
114 | ||||
|
115 | assert_tag :tag => 'user', | |||
|
116 | :child => {:tag => 'id', :content => '2'} | |||
97 | end |
|
117 | end | |
98 |
|
118 | |||
99 | test "GET /users/:id should not return login for other user" do |
|
119 | test "GET /users/:id should not return login for other user" do | |
@@ -132,252 +152,176 class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base | |||||
132 | assert_tag 'user', :child => {:tag => 'status', :content => User.find(1).status.to_s} |
|
152 | assert_tag 'user', :child => {:tag => 'status', :content => User.find(1).status.to_s} | |
133 | end |
|
153 | end | |
134 |
|
154 | |||
135 | context "POST /users" do |
|
155 | test "POST /users.xml with valid parameters should create the user" do | |
136 | context "with valid parameters" do |
|
156 | assert_difference('User.count') do | |
137 | setup do |
|
157 | post '/users.xml', { | |
138 |
|
|
158 | :user => { | |
139 | :user => { |
|
159 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |
140 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
160 | :mail => 'foo@example.net', :password => 'secret123', | |
141 | :mail => 'foo@example.net', :password => 'secret123', |
|
161 | :mail_notification => 'only_assigned'} | |
142 | :mail_notification => 'only_assigned' |
|
162 | }, | |
143 | } |
|
163 | credentials('admin') | |
144 | } |
|
164 | end | |
145 | end |
|
165 | ||
146 |
|
166 | user = User.first(:order => 'id DESC') | ||
147 | context ".xml" do |
|
167 | assert_equal 'foo', user.login | |
148 | should_allow_api_authentication(:post, |
|
168 | assert_equal 'Firstname', user.firstname | |
149 | '/users.xml', |
|
169 | assert_equal 'Lastname', user.lastname | |
150 | {:user => { |
|
170 | assert_equal 'foo@example.net', user.mail | |
151 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
171 | assert_equal 'only_assigned', user.mail_notification | |
152 | :mail => 'foo@example.net', :password => 'secret123' |
|
172 | assert !user.admin? | |
153 | }}, |
|
173 | assert user.check_password?('secret123') | |
154 | {:success_code => :created}) |
|
174 | ||
155 |
|
175 | assert_response :created | ||
156 | should "create a user with the attributes" do |
|
176 | assert_equal 'application/xml', @response.content_type | |
157 | assert_difference('User.count') do |
|
177 | assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s} | |
158 | post '/users.xml', @parameters, credentials('admin') |
|
178 | end | |
159 | end |
|
179 | ||
160 |
|
180 | test "POST /users.json with valid parameters should create the user" do | ||
161 | user = User.first(:order => 'id DESC') |
|
181 | assert_difference('User.count') do | |
162 | assert_equal 'foo', user.login |
|
182 | post '/users.json', { | |
163 | assert_equal 'Firstname', user.firstname |
|
183 | :user => { | |
164 | assert_equal 'Lastname', user.lastname |
|
184 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', | |
165 |
|
|
185 | :mail => 'foo@example.net', :password => 'secret123', | |
166 | assert_equal 'only_assigned', user.mail_notification |
|
186 | :mail_notification => 'only_assigned'} | |
167 | assert !user.admin? |
|
187 | }, | |
168 | assert user.check_password?('secret123') |
|
188 | credentials('admin') | |
169 |
|
189 | end | ||
170 | assert_response :created |
|
190 | ||
171 | assert_equal 'application/xml', @response.content_type |
|
191 | user = User.first(:order => 'id DESC') | |
172 | assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s} |
|
192 | assert_equal 'foo', user.login | |
173 | end |
|
193 | assert_equal 'Firstname', user.firstname | |
174 | end |
|
194 | assert_equal 'Lastname', user.lastname | |
175 |
|
195 | assert_equal 'foo@example.net', user.mail | ||
176 | context ".json" do |
|
196 | assert !user.admin? | |
177 | should_allow_api_authentication(:post, |
|
197 | ||
178 | '/users.json', |
|
198 | assert_response :created | |
179 | {:user => { |
|
199 | assert_equal 'application/json', @response.content_type | |
180 | :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
200 | json = ActiveSupport::JSON.decode(response.body) | |
181 | :mail => 'foo@example.net' |
|
201 | assert_kind_of Hash, json | |
182 | }}, |
|
202 | assert_kind_of Hash, json['user'] | |
183 | {:success_code => :created}) |
|
203 | assert_equal user.id, json['user']['id'] | |
184 |
|
204 | end | ||
185 | should "create a user with the attributes" do |
|
205 | ||
186 | assert_difference('User.count') do |
|
206 | test "POST /users.xml with with invalid parameters should return errors" do | |
187 | post '/users.json', @parameters, credentials('admin') |
|
207 | assert_no_difference('User.count') do | |
188 | end |
|
208 | post '/users.xml', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin') | |
189 |
|
209 | end | ||
190 | user = User.first(:order => 'id DESC') |
|
210 | ||
191 | assert_equal 'foo', user.login |
|
211 | assert_response :unprocessable_entity | |
192 | assert_equal 'Firstname', user.firstname |
|
212 | assert_equal 'application/xml', @response.content_type | |
193 | assert_equal 'Lastname', user.lastname |
|
213 | assert_tag 'errors', :child => { | |
194 | assert_equal 'foo@example.net', user.mail |
|
214 | :tag => 'error', | |
195 | assert !user.admin? |
|
215 | :content => "First name can't be blank" | |
196 |
|
216 | } | ||
197 | assert_response :created |
|
217 | end | |
198 | assert_equal 'application/json', @response.content_type |
|
218 | ||
199 | json = ActiveSupport::JSON.decode(response.body) |
|
219 | test "POST /users.json with with invalid parameters should return errors" do | |
200 | assert_kind_of Hash, json |
|
220 | assert_no_difference('User.count') do | |
201 | assert_kind_of Hash, json['user'] |
|
221 | post '/users.json', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin') | |
202 | assert_equal user.id, json['user']['id'] |
|
|||
203 | end |
|
|||
204 | end |
|
|||
205 | end |
|
222 | end | |
206 |
|
223 | |||
207 | context "with invalid parameters" do |
|
224 | assert_response :unprocessable_entity | |
208 | setup do |
|
225 | assert_equal 'application/json', @response.content_type | |
209 | @parameters = {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}} |
|
226 | json = ActiveSupport::JSON.decode(response.body) | |
210 | end |
|
227 | assert_kind_of Hash, json | |
211 |
|
228 | assert json.has_key?('errors') | ||
212 | context ".xml" do |
|
229 | assert_kind_of Array, json['errors'] | |
213 | should "return errors" do |
|
230 | end | |
214 | assert_no_difference('User.count') do |
|
231 | ||
215 | post '/users.xml', @parameters, credentials('admin') |
|
232 | test "PUT /users/:id.xml with valid parameters should update the user" do | |
216 | end |
|
233 | assert_no_difference('User.count') do | |
217 |
|
234 | put '/users/2.xml', { | ||
218 | assert_response :unprocessable_entity |
|
235 | :user => { | |
219 | assert_equal 'application/xml', @response.content_type |
|
236 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |
220 | assert_tag 'errors', :child => { |
|
237 | :mail => 'jsmith@somenet.foo'} | |
221 | :tag => 'error', |
|
238 | }, | |
222 | :content => "First name can't be blank" |
|
239 | credentials('admin') | |
223 | } |
|
|||
224 | end |
|
|||
225 | end |
|
|||
226 |
|
||||
227 | context ".json" do |
|
|||
228 | should "return errors" do |
|
|||
229 | assert_no_difference('User.count') do |
|
|||
230 | post '/users.json', @parameters, credentials('admin') |
|
|||
231 | end |
|
|||
232 |
|
||||
233 | assert_response :unprocessable_entity |
|
|||
234 | assert_equal 'application/json', @response.content_type |
|
|||
235 | json = ActiveSupport::JSON.decode(response.body) |
|
|||
236 | assert_kind_of Hash, json |
|
|||
237 | assert json.has_key?('errors') |
|
|||
238 | assert_kind_of Array, json['errors'] |
|
|||
239 | end |
|
|||
240 | end |
|
|||
241 | end |
|
240 | end | |
|
241 | ||||
|
242 | user = User.find(2) | |||
|
243 | assert_equal 'jsmith', user.login | |||
|
244 | assert_equal 'John', user.firstname | |||
|
245 | assert_equal 'Renamed', user.lastname | |||
|
246 | assert_equal 'jsmith@somenet.foo', user.mail | |||
|
247 | assert !user.admin? | |||
|
248 | ||||
|
249 | assert_response :ok | |||
|
250 | assert_equal '', @response.body | |||
242 | end |
|
251 | end | |
243 |
|
252 | |||
244 | context "PUT /users/2" do |
|
253 | test "PUT /users/:id.json with valid parameters should update the user" do | |
245 | context "with valid parameters" do |
|
254 | assert_no_difference('User.count') do | |
246 | setup do |
|
255 | put '/users/2.json', { | |
247 |
|
|
256 | :user => { | |
248 | :user => { |
|
257 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', | |
249 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', |
|
258 | :mail => 'jsmith@somenet.foo'} | |
250 | :mail => 'jsmith@somenet.foo' |
|
259 | }, | |
251 | } |
|
260 | credentials('admin') | |
252 | } |
|
|||
253 | end |
|
|||
254 |
|
||||
255 | context ".xml" do |
|
|||
256 | should_allow_api_authentication(:put, |
|
|||
257 | '/users/2.xml', |
|
|||
258 | {:user => { |
|
|||
259 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', |
|
|||
260 | :mail => 'jsmith@somenet.foo' |
|
|||
261 | }}, |
|
|||
262 | {:success_code => :ok}) |
|
|||
263 |
|
||||
264 | should "update user with the attributes" do |
|
|||
265 | assert_no_difference('User.count') do |
|
|||
266 | put '/users/2.xml', @parameters, credentials('admin') |
|
|||
267 | end |
|
|||
268 |
|
||||
269 | user = User.find(2) |
|
|||
270 | assert_equal 'jsmith', user.login |
|
|||
271 | assert_equal 'John', user.firstname |
|
|||
272 | assert_equal 'Renamed', user.lastname |
|
|||
273 | assert_equal 'jsmith@somenet.foo', user.mail |
|
|||
274 | assert !user.admin? |
|
|||
275 |
|
||||
276 | assert_response :ok |
|
|||
277 | assert_equal '', @response.body |
|
|||
278 | end |
|
|||
279 | end |
|
|||
280 |
|
||||
281 | context ".json" do |
|
|||
282 | should_allow_api_authentication(:put, |
|
|||
283 | '/users/2.json', |
|
|||
284 | {:user => { |
|
|||
285 | :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', |
|
|||
286 | :mail => 'jsmith@somenet.foo' |
|
|||
287 | }}, |
|
|||
288 | {:success_code => :ok}) |
|
|||
289 |
|
||||
290 | should "update user with the attributes" do |
|
|||
291 | assert_no_difference('User.count') do |
|
|||
292 | put '/users/2.json', @parameters, credentials('admin') |
|
|||
293 | end |
|
|||
294 |
|
||||
295 | user = User.find(2) |
|
|||
296 | assert_equal 'jsmith', user.login |
|
|||
297 | assert_equal 'John', user.firstname |
|
|||
298 | assert_equal 'Renamed', user.lastname |
|
|||
299 | assert_equal 'jsmith@somenet.foo', user.mail |
|
|||
300 | assert !user.admin? |
|
|||
301 |
|
||||
302 | assert_response :ok |
|
|||
303 | assert_equal '', @response.body |
|
|||
304 | end |
|
|||
305 | end |
|
|||
306 | end |
|
261 | end | |
307 |
|
262 | |||
308 | context "with invalid parameters" do |
|
263 | user = User.find(2) | |
309 | setup do |
|
264 | assert_equal 'jsmith', user.login | |
310 | @parameters = { |
|
265 | assert_equal 'John', user.firstname | |
311 | :user => { |
|
266 | assert_equal 'Renamed', user.lastname | |
312 | :login => 'jsmith', :firstname => '', :lastname => 'Lastname', |
|
267 | assert_equal 'jsmith@somenet.foo', user.mail | |
313 | :mail => 'foo' |
|
268 | assert !user.admin? | |
314 | } |
|
269 | ||
315 | } |
|
270 | assert_response :ok | |
316 | end |
|
271 | assert_equal '', @response.body | |
317 |
|
272 | end | ||
318 | context ".xml" do |
|
273 | ||
319 | should "return errors" do |
|
274 | test "PUT /users/:id.xml with invalid parameters" do | |
320 |
|
|
275 | assert_no_difference('User.count') do | |
321 | put '/users/2.xml', @parameters, credentials('admin') |
|
276 | put '/users/2.xml', { | |
322 |
|
|
277 | :user => { | |
323 |
|
278 | :login => 'jsmith', :firstname => '', :lastname => 'Lastname', | ||
324 | assert_response :unprocessable_entity |
|
279 | :mail => 'foo'} | |
325 | assert_equal 'application/xml', @response.content_type |
|
280 | }, | |
326 | assert_tag 'errors', :child => { |
|
281 | credentials('admin') | |
327 | :tag => 'error', |
|
|||
328 | :content => "First name can't be blank" |
|
|||
329 | } |
|
|||
330 | end |
|
|||
331 | end |
|
|||
332 |
|
||||
333 | context ".json" do |
|
|||
334 | should "return errors" do |
|
|||
335 | assert_no_difference('User.count') do |
|
|||
336 | put '/users/2.json', @parameters, credentials('admin') |
|
|||
337 | end |
|
|||
338 |
|
||||
339 | assert_response :unprocessable_entity |
|
|||
340 | assert_equal 'application/json', @response.content_type |
|
|||
341 | json = ActiveSupport::JSON.decode(response.body) |
|
|||
342 | assert_kind_of Hash, json |
|
|||
343 | assert json.has_key?('errors') |
|
|||
344 | assert_kind_of Array, json['errors'] |
|
|||
345 | end |
|
|||
346 | end |
|
|||
347 | end |
|
282 | end | |
|
283 | ||||
|
284 | assert_response :unprocessable_entity | |||
|
285 | assert_equal 'application/xml', @response.content_type | |||
|
286 | assert_tag 'errors', :child => { | |||
|
287 | :tag => 'error', | |||
|
288 | :content => "First name can't be blank" | |||
|
289 | } | |||
348 | end |
|
290 | end | |
349 |
|
291 | |||
350 | context "DELETE /users/2" do |
|
292 | test "PUT /users/:id.json with invalid parameters" do | |
351 | context ".xml" do |
|
293 | assert_no_difference('User.count') do | |
352 | should_allow_api_authentication(:delete, |
|
294 | put '/users/2.json', { | |
353 | '/users/2.xml', |
|
295 | :user => { | |
354 | {}, |
|
296 | :login => 'jsmith', :firstname => '', :lastname => 'Lastname', | |
355 | {:success_code => :ok}) |
|
297 | :mail => 'foo'} | |
356 |
|
298 | }, | ||
357 | should "delete user" do |
|
299 | credentials('admin') | |
358 | assert_difference('User.count', -1) do |
|
|||
359 | delete '/users/2.xml', {}, credentials('admin') |
|
|||
360 | end |
|
|||
361 |
|
||||
362 | assert_response :ok |
|
|||
363 | assert_equal '', @response.body |
|
|||
364 | end |
|
|||
365 | end |
|
300 | end | |
366 |
|
301 | |||
367 | context ".json" do |
|
302 | assert_response :unprocessable_entity | |
368 | should_allow_api_authentication(:delete, |
|
303 | assert_equal 'application/json', @response.content_type | |
369 | '/users/2.xml', |
|
304 | json = ActiveSupport::JSON.decode(response.body) | |
370 | {}, |
|
305 | assert_kind_of Hash, json | |
371 | {:success_code => :ok}) |
|
306 | assert json.has_key?('errors') | |
|
307 | assert_kind_of Array, json['errors'] | |||
|
308 | end | |||
372 |
|
309 | |||
373 |
|
|
310 | test "DELETE /users/:id.xml should delete the user" do | |
374 |
|
|
311 | assert_difference('User.count', -1) do | |
375 |
|
|
312 | delete '/users/2.xml', {}, credentials('admin') | |
376 |
|
|
313 | end | |
377 |
|
314 | |||
378 |
|
|
315 | assert_response :ok | |
379 |
|
|
316 | assert_equal '', @response.body | |
380 |
|
|
317 | end | |
|
318 | ||||
|
319 | test "DELETE /users/:id.json should delete the user" do | |||
|
320 | assert_difference('User.count', -1) do | |||
|
321 | delete '/users/2.json', {}, credentials('admin') | |||
381 | end |
|
322 | end | |
|
323 | ||||
|
324 | assert_response :ok | |||
|
325 | assert_equal '', @response.body | |||
382 | end |
|
326 | end | |
383 | end |
|
327 | end |
@@ -31,128 +31,112 class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base | |||||
31 | Setting.rest_api_enabled = '1' |
|
31 | Setting.rest_api_enabled = '1' | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 |
|
|
34 | test "GET /projects/:project_id/versions.xml should return project versions" do | |
35 | context "GET" do |
|
35 | get '/projects/1/versions.xml' | |
36 | should "return project versions" do |
|
36 | ||
37 | get '/projects/1/versions.xml' |
|
37 | assert_response :success | |
38 |
|
38 | assert_equal 'application/xml', @response.content_type | ||
39 | assert_response :success |
|
39 | assert_tag :tag => 'versions', | |
40 | assert_equal 'application/xml', @response.content_type |
|
40 | :attributes => {:type => 'array'}, | |
41 | assert_tag :tag => 'versions', |
|
41 | :child => { | |
42 | :attributes => {:type => 'array'}, |
|
42 | :tag => 'version', | |
43 |
|
|
43 | :child => { | |
44 |
|
|
44 | :tag => 'id', | |
45 |
|
|
45 | :content => '2', | |
46 |
|
|
46 | :sibling => { | |
47 |
|
|
47 | :tag => 'name', | |
48 |
|
|
48 | :content => '1.0' | |
49 | :tag => 'name', |
|
|||
50 | :content => '1.0' |
|
|||
51 | } |
|
|||
52 | } |
|
|||
53 | } |
|
49 | } | |
54 |
|
|
50 | } | |
|
51 | } | |||
|
52 | end | |||
|
53 | ||||
|
54 | test "POST /projects/:project_id/versions.xml should create the version" do | |||
|
55 | assert_difference 'Version.count' do | |||
|
56 | post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith') | |||
|
57 | end | |||
|
58 | ||||
|
59 | version = Version.first(:order => 'id DESC') | |||
|
60 | assert_equal 'API test', version.name | |||
|
61 | ||||
|
62 | assert_response :created | |||
|
63 | assert_equal 'application/xml', @response.content_type | |||
|
64 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} | |||
|
65 | end | |||
|
66 | ||||
|
67 | test "POST /projects/:project_id/versions.xml should create the version with due date" do | |||
|
68 | assert_difference 'Version.count' do | |||
|
69 | post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith') | |||
55 | end |
|
70 | end | |
56 |
|
71 | |||
57 | context "POST" do |
|
72 | version = Version.first(:order => 'id DESC') | |
58 | should "create the version" do |
|
73 | assert_equal 'API test', version.name | |
59 | assert_difference 'Version.count' do |
|
74 | assert_equal Date.parse('2012-01-24'), version.due_date | |
60 | post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith') |
|
75 | ||
61 | end |
|
76 | assert_response :created | |
62 |
|
77 | assert_equal 'application/xml', @response.content_type | ||
63 | version = Version.first(:order => 'id DESC') |
|
78 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} | |
64 | assert_equal 'API test', version.name |
|
79 | end | |
65 |
|
80 | |||
66 | assert_response :created |
|
81 | test "POST /projects/:project_id/versions.xml should create the version with custom fields" do | |
67 | assert_equal 'application/xml', @response.content_type |
|
82 | field = VersionCustomField.generate! | |
68 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} |
|
83 | ||
69 | end |
|
84 | assert_difference 'Version.count' do | |
70 |
|
85 | post '/projects/1/versions.xml', { | ||
71 | should "create the version with due date" do |
|
86 | :version => { | |
72 | assert_difference 'Version.count' do |
|
87 | :name => 'API test', | |
73 | post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith') |
|
88 | :custom_fields => [ | |
74 | end |
|
89 | {'id' => field.id.to_s, 'value' => 'Some value'} | |
75 |
|
90 | ] | ||
76 | version = Version.first(:order => 'id DESC') |
|
91 | } | |
77 | assert_equal 'API test', version.name |
|
92 | }, credentials('jsmith') | |
78 | assert_equal Date.parse('2012-01-24'), version.due_date |
|
|||
79 |
|
||||
80 | assert_response :created |
|
|||
81 | assert_equal 'application/xml', @response.content_type |
|
|||
82 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} |
|
|||
83 | end |
|
|||
84 |
|
||||
85 | should "create the version with custom fields" do |
|
|||
86 | field = VersionCustomField.generate! |
|
|||
87 |
|
||||
88 | assert_difference 'Version.count' do |
|
|||
89 | post '/projects/1/versions.xml', { |
|
|||
90 | :version => { |
|
|||
91 | :name => 'API test', |
|
|||
92 | :custom_fields => [ |
|
|||
93 | {'id' => field.id.to_s, 'value' => 'Some value'} |
|
|||
94 | ] |
|
|||
95 | } |
|
|||
96 | }, credentials('jsmith') |
|
|||
97 | end |
|
|||
98 |
|
||||
99 | version = Version.first(:order => 'id DESC') |
|
|||
100 | assert_equal 'API test', version.name |
|
|||
101 | assert_equal 'Some value', version.custom_field_value(field) |
|
|||
102 |
|
||||
103 | assert_response :created |
|
|||
104 | assert_equal 'application/xml', @response.content_type |
|
|||
105 | assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value' |
|
|||
106 | end |
|
|||
107 |
|
||||
108 | context "with failure" do |
|
|||
109 | should "return the errors" do |
|
|||
110 | assert_no_difference('Version.count') do |
|
|||
111 | post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith') |
|
|||
112 | end |
|
|||
113 |
|
||||
114 | assert_response :unprocessable_entity |
|
|||
115 | assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} |
|
|||
116 | end |
|
|||
117 | end |
|
|||
118 | end |
|
93 | end | |
|
94 | ||||
|
95 | version = Version.first(:order => 'id DESC') | |||
|
96 | assert_equal 'API test', version.name | |||
|
97 | assert_equal 'Some value', version.custom_field_value(field) | |||
|
98 | ||||
|
99 | assert_response :created | |||
|
100 | assert_equal 'application/xml', @response.content_type | |||
|
101 | assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value' | |||
119 | end |
|
102 | end | |
120 |
|
103 | |||
121 | context "/versions/:id" do |
|
104 | test "POST /projects/:project_id/versions.xml with failure should return the errors" do | |
122 | context "GET" do |
|
105 | assert_no_difference('Version.count') do | |
123 | should "return the version" do |
|
106 | post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith') | |
124 | get '/versions/2.xml' |
|
|||
125 |
|
||||
126 | assert_response :success |
|
|||
127 | assert_equal 'application/xml', @response.content_type |
|
|||
128 | assert_select 'version' do |
|
|||
129 | assert_select 'id', :text => '2' |
|
|||
130 | assert_select 'name', :text => '1.0' |
|
|||
131 | assert_select 'sharing', :text => 'none' |
|
|||
132 | end |
|
|||
133 | end |
|
|||
134 | end |
|
107 | end | |
135 |
|
108 | |||
136 | context "PUT" do |
|
109 | assert_response :unprocessable_entity | |
137 | should "update the version" do |
|
110 | assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} | |
138 | put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') |
|
111 | end | |
|
112 | ||||
|
113 | test "GET /versions/:id.xml should return the version" do | |||
|
114 | get '/versions/2.xml' | |||
139 |
|
115 | |||
140 |
|
|
116 | assert_response :success | |
141 |
|
|
117 | assert_equal 'application/xml', @response.content_type | |
142 | assert_equal 'API update', Version.find(2).name |
|
118 | assert_select 'version' do | |
143 | end |
|
119 | assert_select 'id', :text => '2' | |
|
120 | assert_select 'name', :text => '1.0' | |||
|
121 | assert_select 'sharing', :text => 'none' | |||
144 | end |
|
122 | end | |
|
123 | end | |||
145 |
|
124 | |||
146 | context "DELETE" do |
|
125 | test "PUT /versions/:id.xml should update the version" do | |
147 | should "destroy the version" do |
|
126 | put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') | |
148 | assert_difference 'Version.count', -1 do |
|
|||
149 | delete '/versions/3.xml', {}, credentials('jsmith') |
|
|||
150 | end |
|
|||
151 |
|
127 | |||
152 |
|
|
128 | assert_response :ok | |
153 |
|
|
129 | assert_equal '', @response.body | |
154 | assert_nil Version.find_by_id(3) |
|
130 | assert_equal 'API update', Version.find(2).name | |
155 |
|
|
131 | end | |
|
132 | ||||
|
133 | test "DELETE /versions/:id.xml should destroy the version" do | |||
|
134 | assert_difference 'Version.count', -1 do | |||
|
135 | delete '/versions/3.xml', {}, credentials('jsmith') | |||
156 | end |
|
136 | end | |
|
137 | ||||
|
138 | assert_response :ok | |||
|
139 | assert_equal '', @response.body | |||
|
140 | assert_nil Version.find_by_id(3) | |||
157 | end |
|
141 | end | |
158 | end |
|
142 | end |
General Comments 0
You need to be logged in to leave comments.
Login now