annotate test/integration/api_test/versions_test.rb @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
rev   line source
Chris@909 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 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@909 20 class ApiTest::VersionsTest < ActionController::IntegrationTest
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 :workflows,
Chris@909 29 :versions
Chris@909 30
Chris@909 31 def setup
Chris@909 32 Setting.rest_api_enabled = '1'
Chris@909 33 end
Chris@909 34
Chris@909 35 context "/projects/:project_id/versions" do
Chris@909 36 context "GET" do
Chris@909 37 should "return project versions" do
Chris@909 38 get '/projects/1/versions.xml'
Chris@909 39
Chris@909 40 assert_response :success
Chris@909 41 assert_equal 'application/xml', @response.content_type
Chris@909 42 assert_tag :tag => 'versions',
Chris@909 43 :attributes => {:type => 'array'},
Chris@909 44 :child => {
Chris@909 45 :tag => 'version',
Chris@909 46 :child => {
Chris@909 47 :tag => 'id',
Chris@909 48 :content => '2',
Chris@909 49 :sibling => {
Chris@909 50 :tag => 'name',
Chris@909 51 :content => '1.0'
Chris@909 52 }
Chris@909 53 }
Chris@909 54 }
Chris@909 55 end
Chris@909 56 end
Chris@909 57
Chris@909 58 context "POST" do
Chris@909 59 should "create the version" do
Chris@909 60 assert_difference 'Version.count' do
Chris@1115 61 post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
Chris@909 62 end
Chris@909 63
Chris@909 64 version = Version.first(:order => 'id DESC')
Chris@909 65 assert_equal 'API test', version.name
Chris@909 66
Chris@909 67 assert_response :created
Chris@909 68 assert_equal 'application/xml', @response.content_type
Chris@909 69 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
Chris@909 70 end
Chris@909 71
Chris@909 72 should "create the version with due date" do
Chris@909 73 assert_difference 'Version.count' do
Chris@1115 74 post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
Chris@909 75 end
Chris@909 76
Chris@909 77 version = Version.first(:order => 'id DESC')
Chris@909 78 assert_equal 'API test', version.name
Chris@909 79 assert_equal Date.parse('2012-01-24'), version.due_date
Chris@909 80
Chris@909 81 assert_response :created
Chris@909 82 assert_equal 'application/xml', @response.content_type
Chris@909 83 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
Chris@909 84 end
Chris@909 85
Chris@909 86 context "with failure" do
Chris@909 87 should "return the errors" do
Chris@909 88 assert_no_difference('Version.count') do
Chris@1115 89 post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
Chris@909 90 end
Chris@909 91
Chris@909 92 assert_response :unprocessable_entity
Chris@909 93 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
Chris@909 94 end
Chris@909 95 end
Chris@909 96 end
Chris@909 97 end
Chris@909 98
Chris@909 99 context "/versions/:id" do
Chris@909 100 context "GET" do
Chris@909 101 should "return the version" do
Chris@909 102 get '/versions/2.xml'
Chris@909 103
Chris@909 104 assert_response :success
Chris@909 105 assert_equal 'application/xml', @response.content_type
Chris@1115 106 assert_select 'version' do
Chris@1115 107 assert_select 'id', :text => '2'
Chris@1115 108 assert_select 'name', :text => '1.0'
Chris@1115 109 assert_select 'sharing', :text => 'none'
Chris@1115 110 end
Chris@909 111 end
Chris@909 112 end
Chris@909 113
Chris@909 114 context "PUT" do
Chris@909 115 should "update the version" do
Chris@1115 116 put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
Chris@909 117
Chris@909 118 assert_response :ok
Chris@1115 119 assert_equal '', @response.body
Chris@909 120 assert_equal 'API update', Version.find(2).name
Chris@909 121 end
Chris@909 122 end
Chris@909 123
Chris@909 124 context "DELETE" do
Chris@909 125 should "destroy the version" do
Chris@909 126 assert_difference 'Version.count', -1 do
Chris@1115 127 delete '/versions/3.xml', {}, credentials('jsmith')
Chris@909 128 end
Chris@909 129
Chris@909 130 assert_response :ok
Chris@1115 131 assert_equal '', @response.body
Chris@909 132 assert_nil Version.find_by_id(3)
Chris@909 133 end
Chris@909 134 end
Chris@909 135 end
Chris@909 136 end