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