annotate test/integration/api_test/versions_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@909 19
Chris@1295 20 class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
Chris@909 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 22 :enumerations, :users, :issue_categories,
Chris@909 23 :projects_trackers,
Chris@909 24 :roles,
Chris@909 25 :member_roles,
Chris@909 26 :members,
Chris@909 27 :enabled_modules,
Chris@909 28 :versions
Chris@909 29
Chris@909 30 def setup
Chris@909 31 Setting.rest_api_enabled = '1'
Chris@909 32 end
Chris@909 33
Chris@909 34 context "/projects/:project_id/versions" do
Chris@909 35 context "GET" do
Chris@909 36 should "return project versions" do
Chris@909 37 get '/projects/1/versions.xml'
Chris@909 38
Chris@909 39 assert_response :success
Chris@909 40 assert_equal 'application/xml', @response.content_type
Chris@909 41 assert_tag :tag => 'versions',
Chris@909 42 :attributes => {:type => 'array'},
Chris@909 43 :child => {
Chris@909 44 :tag => 'version',
Chris@909 45 :child => {
Chris@909 46 :tag => 'id',
Chris@909 47 :content => '2',
Chris@909 48 :sibling => {
Chris@909 49 :tag => 'name',
Chris@909 50 :content => '1.0'
Chris@909 51 }
Chris@909 52 }
Chris@909 53 }
Chris@909 54 end
Chris@909 55 end
Chris@909 56
Chris@909 57 context "POST" do
Chris@909 58 should "create the version" do
Chris@909 59 assert_difference 'Version.count' do
Chris@1115 60 post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
Chris@909 61 end
Chris@909 62
Chris@909 63 version = Version.first(:order => 'id DESC')
Chris@909 64 assert_equal 'API test', version.name
Chris@909 65
Chris@909 66 assert_response :created
Chris@909 67 assert_equal 'application/xml', @response.content_type
Chris@909 68 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
Chris@909 69 end
Chris@909 70
Chris@909 71 should "create the version with due date" do
Chris@909 72 assert_difference 'Version.count' do
Chris@1115 73 post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
Chris@909 74 end
Chris@909 75
Chris@909 76 version = Version.first(:order => 'id DESC')
Chris@909 77 assert_equal 'API test', version.name
Chris@909 78 assert_equal Date.parse('2012-01-24'), version.due_date
Chris@909 79
Chris@909 80 assert_response :created
Chris@909 81 assert_equal 'application/xml', @response.content_type
Chris@909 82 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
Chris@909 83 end
Chris@909 84
Chris@1295 85 should "create the version with custom fields" do
Chris@1295 86 field = VersionCustomField.generate!
Chris@1295 87
Chris@1295 88 assert_difference 'Version.count' do
Chris@1295 89 post '/projects/1/versions.xml', {
Chris@1295 90 :version => {
Chris@1295 91 :name => 'API test',
Chris@1295 92 :custom_fields => [
Chris@1295 93 {'id' => field.id.to_s, 'value' => 'Some value'}
Chris@1295 94 ]
Chris@1295 95 }
Chris@1295 96 }, credentials('jsmith')
Chris@1295 97 end
Chris@1295 98
Chris@1295 99 version = Version.first(:order => 'id DESC')
Chris@1295 100 assert_equal 'API test', version.name
Chris@1295 101 assert_equal 'Some value', version.custom_field_value(field)
Chris@1295 102
Chris@1295 103 assert_response :created
Chris@1295 104 assert_equal 'application/xml', @response.content_type
Chris@1295 105 assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value'
Chris@1295 106 end
Chris@1295 107
Chris@909 108 context "with failure" do
Chris@909 109 should "return the errors" do
Chris@909 110 assert_no_difference('Version.count') do
Chris@1115 111 post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
Chris@909 112 end
Chris@909 113
Chris@909 114 assert_response :unprocessable_entity
Chris@909 115 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
Chris@909 116 end
Chris@909 117 end
Chris@909 118 end
Chris@909 119 end
Chris@909 120
Chris@909 121 context "/versions/:id" do
Chris@909 122 context "GET" do
Chris@909 123 should "return the version" do
Chris@909 124 get '/versions/2.xml'
Chris@909 125
Chris@909 126 assert_response :success
Chris@909 127 assert_equal 'application/xml', @response.content_type
Chris@1115 128 assert_select 'version' do
Chris@1115 129 assert_select 'id', :text => '2'
Chris@1115 130 assert_select 'name', :text => '1.0'
Chris@1115 131 assert_select 'sharing', :text => 'none'
Chris@1115 132 end
Chris@909 133 end
Chris@909 134 end
Chris@909 135
Chris@909 136 context "PUT" do
Chris@909 137 should "update the version" do
Chris@1115 138 put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
Chris@909 139
Chris@909 140 assert_response :ok
Chris@1115 141 assert_equal '', @response.body
Chris@909 142 assert_equal 'API update', Version.find(2).name
Chris@909 143 end
Chris@909 144 end
Chris@909 145
Chris@909 146 context "DELETE" do
Chris@909 147 should "destroy the version" do
Chris@909 148 assert_difference 'Version.count', -1 do
Chris@1115 149 delete '/versions/3.xml', {}, credentials('jsmith')
Chris@909 150 end
Chris@909 151
Chris@909 152 assert_response :ok
Chris@1115 153 assert_equal '', @response.body
Chris@909 154 assert_nil Version.find_by_id(3)
Chris@909 155 end
Chris@909 156 end
Chris@909 157 end
Chris@909 158 end