comparison .svn/pristine/81/81b5162180e7da6eba9eec12f7d1c6c77f6bbb3a.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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