Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/.svn/text-base/issues_test.rb.svn-base @ 117:af80e5618e9b redmine-1.1
* Update to Redmine 1.1-stable branch (Redmine SVN rev 4707)
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 12:53:21 +0000 |
parents | 94944d00e43c |
children |
comparison
equal
deleted
inserted
replaced
39:150ceac17a8d | 117:af80e5618e9b |
---|---|
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require "#{File.dirname(__FILE__)}/../../test_helper" | 18 require File.expand_path('../../../test_helper', __FILE__) |
19 | 19 |
20 class ApiTest::IssuesTest < ActionController::IntegrationTest | 20 class ApiTest::IssuesTest < ActionController::IntegrationTest |
21 fixtures :projects, | 21 fixtures :projects, |
22 :users, | 22 :users, |
23 :roles, | 23 :roles, |
44 | 44 |
45 def setup | 45 def setup |
46 Setting.rest_api_enabled = '1' | 46 Setting.rest_api_enabled = '1' |
47 end | 47 end |
48 | 48 |
49 # Use a private project to make sure auth is really working and not just | |
50 # only showing public issues. | |
51 context "/index.xml" do | 49 context "/index.xml" do |
50 # Use a private project to make sure auth is really working and not just | |
51 # only showing public issues. | |
52 should_allow_api_authentication(:get, "/projects/private-child/issues.xml") | 52 should_allow_api_authentication(:get, "/projects/private-child/issues.xml") |
53 | |
54 should "contain metadata" do | |
55 get '/issues.xml' | |
56 | |
57 assert_tag :tag => 'issues', | |
58 :attributes => { | |
59 :type => 'array', | |
60 :total_count => assigns(:issue_count), | |
61 :limit => 25, | |
62 :offset => 0 | |
63 } | |
64 end | |
65 | |
66 context "with offset and limit" do | |
67 should "use the params" do | |
68 get '/issues.xml?offset=2&limit=3' | |
69 | |
70 assert_equal 3, assigns(:limit) | |
71 assert_equal 2, assigns(:offset) | |
72 assert_tag :tag => 'issues', :children => {:count => 3, :only => {:tag => 'issue'}} | |
73 end | |
74 end | |
75 | |
76 context "with nometa param" do | |
77 should "not contain metadata" do | |
78 get '/issues.xml?nometa=1' | |
79 | |
80 assert_tag :tag => 'issues', | |
81 :attributes => { | |
82 :type => 'array', | |
83 :total_count => nil, | |
84 :limit => nil, | |
85 :offset => nil | |
86 } | |
87 end | |
88 end | |
89 | |
90 context "with nometa header" do | |
91 should "not contain metadata" do | |
92 get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} | |
93 | |
94 assert_tag :tag => 'issues', | |
95 :attributes => { | |
96 :type => 'array', | |
97 :total_count => nil, | |
98 :limit => nil, | |
99 :offset => nil | |
100 } | |
101 end | |
102 end | |
53 end | 103 end |
54 | 104 |
55 context "/index.json" do | 105 context "/index.json" do |
56 should_allow_api_authentication(:get, "/projects/private-child/issues.json") | 106 should_allow_api_authentication(:get, "/projects/private-child/issues.json") |
57 end | 107 end |
72 | 122 |
73 should "show only issues with the status_id" do | 123 should "show only issues with the status_id" do |
74 get '/issues.json?status_id=5' | 124 get '/issues.json?status_id=5' |
75 | 125 |
76 json = ActiveSupport::JSON.decode(response.body) | 126 json = ActiveSupport::JSON.decode(response.body) |
77 status_ids_used = json.collect {|j| j['status_id'] } | 127 status_ids_used = json['issues'].collect {|j| j['status']['id'] } |
78 assert_equal 3, status_ids_used.length | 128 assert_equal 3, status_ids_used.length |
79 assert status_ids_used.all? {|id| id == 5 } | 129 assert status_ids_used.all? {|id| id == 5 } |
80 end | 130 end |
81 | 131 |
82 end | 132 end |
86 should_allow_api_authentication(:get, "/issues/6.xml") | 136 should_allow_api_authentication(:get, "/issues/6.xml") |
87 end | 137 end |
88 | 138 |
89 context "/issues/6.json" do | 139 context "/issues/6.json" do |
90 should_allow_api_authentication(:get, "/issues/6.json") | 140 should_allow_api_authentication(:get, "/issues/6.json") |
141 end | |
142 | |
143 context "GET /issues/:id" do | |
144 context "with journals" do | |
145 context ".xml" do | |
146 should "display journals" do | |
147 get '/issues/1.xml?include=journals' | |
148 | |
149 assert_tag :tag => 'issue', | |
150 :child => { | |
151 :tag => 'journals', | |
152 :attributes => { :type => 'array' }, | |
153 :child => { | |
154 :tag => 'journal', | |
155 :attributes => { :id => '1'}, | |
156 :child => { | |
157 :tag => 'details', | |
158 :attributes => { :type => 'array' }, | |
159 :child => { | |
160 :tag => 'detail', | |
161 :attributes => { :name => 'status_id' }, | |
162 :child => { | |
163 :tag => 'old_value', | |
164 :content => '1', | |
165 :sibling => { | |
166 :tag => 'new_value', | |
167 :content => '2' | |
168 } | |
169 } | |
170 } | |
171 } | |
172 } | |
173 } | |
174 end | |
175 end | |
176 end | |
177 | |
178 context "with custom fields" do | |
179 context ".xml" do | |
180 should "display custom fields" do | |
181 get '/issues/3.xml' | |
182 | |
183 assert_tag :tag => 'issue', | |
184 :child => { | |
185 :tag => 'custom_fields', | |
186 :attributes => { :type => 'array' }, | |
187 :child => { | |
188 :tag => 'custom_field', | |
189 :attributes => { :id => '1'}, | |
190 :child => { | |
191 :tag => 'value', | |
192 :content => 'MySQL' | |
193 } | |
194 } | |
195 } | |
196 | |
197 assert_nothing_raised do | |
198 Hash.from_xml(response.body).to_xml | |
199 end | |
200 end | |
201 end | |
202 end | |
203 | |
204 context "with subtasks" do | |
205 setup do | |
206 @c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) | |
207 @c2 = Issue.generate!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) | |
208 @c3 = Issue.generate!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :parent_issue_id => @c1.id) | |
209 end | |
210 | |
211 context ".xml" do | |
212 should "display children" do | |
213 get '/issues/1.xml?include=children' | |
214 | |
215 assert_tag :tag => 'issue', | |
216 :child => { | |
217 :tag => 'children', | |
218 :children => {:count => 2}, | |
219 :child => { | |
220 :tag => 'issue', | |
221 :attributes => {:id => @c1.id.to_s}, | |
222 :child => { | |
223 :tag => 'subject', | |
224 :content => 'child c1', | |
225 :sibling => { | |
226 :tag => 'children', | |
227 :children => {:count => 1}, | |
228 :child => { | |
229 :tag => 'issue', | |
230 :attributes => {:id => @c3.id.to_s} | |
231 } | |
232 } | |
233 } | |
234 } | |
235 } | |
236 end | |
237 | |
238 context ".json" do | |
239 should "display children" do | |
240 get '/issues/1.json?include=children' | |
241 | |
242 json = ActiveSupport::JSON.decode(response.body) | |
243 assert_equal([ | |
244 { | |
245 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, | |
246 'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }] | |
247 }, | |
248 { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } | |
249 ], | |
250 json['issue']['children']) | |
251 end | |
252 end | |
253 end | |
254 end | |
91 end | 255 end |
92 | 256 |
93 context "POST /issues.xml" do | 257 context "POST /issues.xml" do |
94 should_allow_api_authentication(:post, | 258 should_allow_api_authentication(:post, |
95 '/issues.xml', | 259 '/issues.xml', |
158 assert_no_difference('Issue.count') do | 322 assert_no_difference('Issue.count') do |
159 post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith') | 323 post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith') |
160 end | 324 end |
161 | 325 |
162 json = ActiveSupport::JSON.decode(response.body) | 326 json = ActiveSupport::JSON.decode(response.body) |
163 assert_equal "can't be blank", json.first['subject'] | 327 assert json['errors'].include?(['subject', "can't be blank"]) |
164 end | 328 end |
165 end | 329 end |
166 | 330 |
167 # Issue 6 is on a private project | 331 # Issue 6 is on a private project |
168 context "PUT /issues/6.xml" do | 332 context "PUT /issues/6.xml" do |
202 assert_equal "API update", issue.subject | 366 assert_equal "API update", issue.subject |
203 end | 367 end |
204 | 368 |
205 end | 369 end |
206 | 370 |
371 context "PUT /issues/3.xml with custom fields" do | |
372 setup do | |
373 @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} | |
374 @headers = { :authorization => credentials('jsmith') } | |
375 end | |
376 | |
377 should "update custom fields" do | |
378 assert_no_difference('Issue.count') do | |
379 put '/issues/3.xml', @parameters, @headers | |
380 end | |
381 | |
382 issue = Issue.find(3) | |
383 assert_equal '150', issue.custom_value_for(2).value | |
384 assert_equal 'PostgreSQL', issue.custom_value_for(1).value | |
385 end | |
386 end | |
387 | |
207 context "PUT /issues/6.xml with failed update" do | 388 context "PUT /issues/6.xml with failed update" do |
208 setup do | 389 setup do |
209 @parameters = {:issue => {:subject => ''}} | 390 @parameters = {:issue => {:subject => ''}} |
210 @headers = { :authorization => credentials('jsmith') } | 391 @headers = { :authorization => credentials('jsmith') } |
211 end | 392 end |
298 | 479 |
299 should "have an errors attribute" do | 480 should "have an errors attribute" do |
300 put '/issues/6.json', @parameters, @headers | 481 put '/issues/6.json', @parameters, @headers |
301 | 482 |
302 json = ActiveSupport::JSON.decode(response.body) | 483 json = ActiveSupport::JSON.decode(response.body) |
303 assert_equal "can't be blank", json.first['subject'] | 484 assert json['errors'].include?(['subject', "can't be blank"]) |
304 end | 485 end |
305 end | 486 end |
306 | 487 |
307 context "DELETE /issues/1.xml" do | 488 context "DELETE /issues/1.xml" do |
308 should_allow_api_authentication(:delete, | 489 should_allow_api_authentication(:delete, |