annotate test/integration/issues_api_test.rb @ 36:de76cd3e8c8e cc-branches

* Probably abortive experiments in extracting the branch from Hg
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 20 Oct 2010 10:07:29 +0100
parents 40f7cfd4df19
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2010 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require "#{File.dirname(__FILE__)}/../test_helper"
Chris@0 19
Chris@0 20 class IssuesApiTest < ActionController::IntegrationTest
Chris@0 21 fixtures :projects,
Chris@0 22 :users,
Chris@0 23 :roles,
Chris@0 24 :members,
Chris@0 25 :member_roles,
Chris@0 26 :issues,
Chris@0 27 :issue_statuses,
Chris@0 28 :versions,
Chris@0 29 :trackers,
Chris@0 30 :projects_trackers,
Chris@0 31 :issue_categories,
Chris@0 32 :enabled_modules,
Chris@0 33 :enumerations,
Chris@0 34 :attachments,
Chris@0 35 :workflows,
Chris@0 36 :custom_fields,
Chris@0 37 :custom_values,
Chris@0 38 :custom_fields_projects,
Chris@0 39 :custom_fields_trackers,
Chris@0 40 :time_entries,
Chris@0 41 :journals,
Chris@0 42 :journal_details,
Chris@0 43 :queries
Chris@0 44
Chris@0 45 def setup
Chris@0 46 Setting.rest_api_enabled = '1'
Chris@0 47 end
Chris@0 48
Chris@0 49 context "/index.xml" do
Chris@0 50 setup do
Chris@0 51 get '/issues.xml'
Chris@0 52 end
Chris@0 53
Chris@0 54 should_respond_with :success
Chris@0 55 should_respond_with_content_type 'application/xml'
Chris@0 56 end
Chris@0 57
Chris@0 58 context "/index.json" do
Chris@0 59 setup do
Chris@0 60 get '/issues.json'
Chris@0 61 end
Chris@0 62
Chris@0 63 should_respond_with :success
Chris@0 64 should_respond_with_content_type 'application/json'
Chris@0 65
Chris@0 66 should 'return a valid JSON string' do
Chris@0 67 assert ActiveSupport::JSON.decode(response.body)
Chris@0 68 end
Chris@0 69 end
Chris@0 70
Chris@0 71 context "/index.xml with filter" do
Chris@0 72 setup do
Chris@0 73 get '/issues.xml?status_id=5'
Chris@0 74 end
Chris@0 75
Chris@0 76 should_respond_with :success
Chris@0 77 should_respond_with_content_type 'application/xml'
Chris@0 78 should "show only issues with the status_id" do
Chris@0 79 assert_tag :tag => 'issues',
Chris@0 80 :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
Chris@0 81 :only => { :tag => 'issue' } }
Chris@0 82 end
Chris@0 83 end
Chris@0 84
Chris@0 85 context "/index.json with filter" do
Chris@0 86 setup do
Chris@0 87 get '/issues.json?status_id=5'
Chris@0 88 end
Chris@0 89
Chris@0 90 should_respond_with :success
Chris@0 91 should_respond_with_content_type 'application/json'
Chris@0 92
Chris@0 93 should 'return a valid JSON string' do
Chris@0 94 assert ActiveSupport::JSON.decode(response.body)
Chris@0 95 end
Chris@0 96
Chris@0 97 should "show only issues with the status_id" do
Chris@0 98 json = ActiveSupport::JSON.decode(response.body)
Chris@0 99 status_ids_used = json.collect {|j| j['status_id'] }
Chris@0 100 assert_equal 3, status_ids_used.length
Chris@0 101 assert status_ids_used.all? {|id| id == 5 }
Chris@0 102 end
Chris@0 103
Chris@0 104 end
Chris@0 105
Chris@0 106 context "/issues/1.xml" do
Chris@0 107 setup do
Chris@0 108 get '/issues/1.xml'
Chris@0 109 end
Chris@0 110
Chris@0 111 should_respond_with :success
Chris@0 112 should_respond_with_content_type 'application/xml'
Chris@0 113 end
Chris@0 114
Chris@0 115 context "/issues/1.json" do
Chris@0 116 setup do
Chris@0 117 get '/issues/1.json'
Chris@0 118 end
Chris@0 119
Chris@0 120 should_respond_with :success
Chris@0 121 should_respond_with_content_type 'application/json'
Chris@0 122
Chris@0 123 should 'return a valid JSON string' do
Chris@0 124 assert ActiveSupport::JSON.decode(response.body)
Chris@0 125 end
Chris@0 126 end
Chris@0 127
Chris@0 128 context "POST /issues.xml" do
Chris@0 129 setup do
Chris@0 130 @issue_count = Issue.count
Chris@0 131 @attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
Chris@0 132 post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 133 end
Chris@0 134
Chris@0 135 should_respond_with :created
Chris@0 136 should_respond_with_content_type 'application/xml'
Chris@0 137
Chris@0 138 should "create an issue with the attributes" do
Chris@0 139 assert_equal Issue.count, @issue_count + 1
Chris@0 140
Chris@0 141 issue = Issue.first(:order => 'id DESC')
Chris@0 142 @attributes.each do |attribute, value|
Chris@0 143 assert_equal value, issue.send(attribute)
Chris@0 144 end
Chris@0 145 end
Chris@0 146 end
Chris@0 147
Chris@0 148 context "POST /issues.xml with failure" do
Chris@0 149 setup do
Chris@0 150 @attributes = {:project_id => 1}
Chris@0 151 post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 152 end
Chris@0 153
Chris@0 154 should_respond_with :unprocessable_entity
Chris@0 155 should_respond_with_content_type 'application/xml'
Chris@0 156
Chris@0 157 should "have an errors tag" do
Chris@0 158 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
Chris@0 159 end
Chris@0 160 end
Chris@0 161
Chris@0 162 context "POST /issues.json" do
Chris@0 163 setup do
Chris@0 164 @issue_count = Issue.count
Chris@0 165 @attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
Chris@0 166 post '/issues.json', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 167 end
Chris@0 168
Chris@0 169 should_respond_with :created
Chris@0 170 should_respond_with_content_type 'application/json'
Chris@0 171
Chris@0 172 should "create an issue with the attributes" do
Chris@0 173 assert_equal Issue.count, @issue_count + 1
Chris@0 174
Chris@0 175 issue = Issue.first(:order => 'id DESC')
Chris@0 176 @attributes.each do |attribute, value|
Chris@0 177 assert_equal value, issue.send(attribute)
Chris@0 178 end
Chris@0 179 end
Chris@0 180 end
Chris@0 181
Chris@0 182 context "POST /issues.json with failure" do
Chris@0 183 setup do
Chris@0 184 @attributes = {:project_id => 1}
Chris@0 185 post '/issues.json', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 186 end
Chris@0 187
Chris@0 188 should_respond_with :unprocessable_entity
Chris@0 189 should_respond_with_content_type 'application/json'
Chris@0 190
Chris@0 191 should "have an errors element" do
Chris@0 192 json = ActiveSupport::JSON.decode(response.body)
Chris@0 193 assert_equal "can't be blank", json.first['subject']
Chris@0 194 end
Chris@0 195 end
Chris@0 196
Chris@0 197 context "PUT /issues/1.xml" do
Chris@0 198 setup do
Chris@0 199 @issue_count = Issue.count
Chris@0 200 @journal_count = Journal.count
chris@22 201 @attributes = {:subject => 'API update', :notes => 'A new note'}
Chris@0 202
Chris@0 203 put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 204 end
Chris@0 205
Chris@0 206 should_respond_with :ok
Chris@0 207 should_respond_with_content_type 'application/xml'
Chris@0 208
Chris@0 209 should "not create a new issue" do
Chris@0 210 assert_equal Issue.count, @issue_count
Chris@0 211 end
Chris@0 212
Chris@0 213 should "create a new journal" do
Chris@0 214 assert_equal Journal.count, @journal_count + 1
Chris@0 215 end
Chris@0 216
chris@22 217 should "add the note to the journal" do
chris@22 218 journal = Journal.last
chris@22 219 assert_equal "A new note", journal.notes
chris@22 220 end
chris@22 221
Chris@0 222 should "update the issue" do
Chris@0 223 issue = Issue.find(1)
Chris@0 224 @attributes.each do |attribute, value|
chris@22 225 assert_equal value, issue.send(attribute) unless attribute == :notes
Chris@0 226 end
Chris@0 227 end
Chris@0 228
Chris@0 229 end
Chris@0 230
Chris@0 231 context "PUT /issues/1.xml with failed update" do
Chris@0 232 setup do
Chris@0 233 @attributes = {:subject => ''}
Chris@0 234 @issue_count = Issue.count
Chris@0 235 @journal_count = Journal.count
Chris@0 236
Chris@0 237 put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 238 end
Chris@0 239
Chris@0 240 should_respond_with :unprocessable_entity
Chris@0 241 should_respond_with_content_type 'application/xml'
Chris@0 242
Chris@0 243 should "not create a new issue" do
Chris@0 244 assert_equal Issue.count, @issue_count
Chris@0 245 end
Chris@0 246
Chris@0 247 should "not create a new journal" do
Chris@0 248 assert_equal Journal.count, @journal_count
Chris@0 249 end
Chris@0 250
Chris@0 251 should "have an errors tag" do
Chris@0 252 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
Chris@0 253 end
Chris@0 254 end
Chris@0 255
Chris@0 256 context "PUT /issues/1.json" do
Chris@0 257 setup do
Chris@0 258 @issue_count = Issue.count
Chris@0 259 @journal_count = Journal.count
chris@22 260 @attributes = {:subject => 'API update', :notes => 'A new note'}
Chris@0 261
Chris@0 262 put '/issues/1.json', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 263 end
Chris@0 264
Chris@0 265 should_respond_with :ok
Chris@0 266 should_respond_with_content_type 'application/json'
Chris@0 267
Chris@0 268 should "not create a new issue" do
Chris@0 269 assert_equal Issue.count, @issue_count
Chris@0 270 end
Chris@0 271
Chris@0 272 should "create a new journal" do
Chris@0 273 assert_equal Journal.count, @journal_count + 1
Chris@0 274 end
Chris@0 275
chris@22 276 should "add the note to the journal" do
chris@22 277 journal = Journal.last
chris@22 278 assert_equal "A new note", journal.notes
chris@22 279 end
chris@22 280
Chris@0 281 should "update the issue" do
Chris@0 282 issue = Issue.find(1)
Chris@0 283 @attributes.each do |attribute, value|
chris@22 284 assert_equal value, issue.send(attribute) unless attribute == :notes
Chris@0 285 end
Chris@0 286 end
chris@22 287
Chris@0 288 end
Chris@0 289
Chris@0 290 context "PUT /issues/1.json with failed update" do
Chris@0 291 setup do
Chris@0 292 @attributes = {:subject => ''}
Chris@0 293 @issue_count = Issue.count
Chris@0 294 @journal_count = Journal.count
Chris@0 295
Chris@0 296 put '/issues/1.json', {:issue => @attributes}, :authorization => credentials('jsmith')
Chris@0 297 end
Chris@0 298
Chris@0 299 should_respond_with :unprocessable_entity
Chris@0 300 should_respond_with_content_type 'application/json'
Chris@0 301
Chris@0 302 should "not create a new issue" do
Chris@0 303 assert_equal Issue.count, @issue_count
Chris@0 304 end
Chris@0 305
Chris@0 306 should "not create a new journal" do
Chris@0 307 assert_equal Journal.count, @journal_count
Chris@0 308 end
Chris@0 309
Chris@0 310 should "have an errors attribute" do
Chris@0 311 json = ActiveSupport::JSON.decode(response.body)
Chris@0 312 assert_equal "can't be blank", json.first['subject']
Chris@0 313 end
Chris@0 314 end
Chris@0 315
Chris@0 316 context "DELETE /issues/1.xml" do
Chris@0 317 setup do
Chris@0 318 @issue_count = Issue.count
Chris@0 319 delete '/issues/1.xml', {}, :authorization => credentials('jsmith')
Chris@0 320 end
Chris@0 321
Chris@0 322 should_respond_with :ok
Chris@0 323 should_respond_with_content_type 'application/xml'
Chris@0 324
Chris@0 325 should "delete the issue" do
Chris@0 326 assert_equal Issue.count, @issue_count -1
Chris@0 327 assert_nil Issue.find_by_id(1)
Chris@0 328 end
Chris@0 329 end
Chris@0 330
Chris@0 331 context "DELETE /issues/1.json" do
Chris@0 332 setup do
Chris@0 333 @issue_count = Issue.count
Chris@0 334 delete '/issues/1.json', {}, :authorization => credentials('jsmith')
Chris@0 335 end
Chris@0 336
Chris@0 337 should_respond_with :ok
Chris@0 338 should_respond_with_content_type 'application/json'
Chris@0 339
Chris@0 340 should "delete the issue" do
Chris@0 341 assert_equal Issue.count, @issue_count -1
Chris@0 342 assert_nil Issue.find_by_id(1)
Chris@0 343 end
Chris@0 344 end
Chris@0 345
Chris@0 346 def credentials(user, password=nil)
Chris@0 347 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
Chris@0 348 end
Chris@0 349 end