Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/versions_test.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
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.expand_path('../../../test_helper', __FILE__) | 18 require File.expand_path('../../../test_helper', __FILE__) |
19 | 19 |
20 class ApiTest::VersionsTest < ActionController::IntegrationTest | 20 class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base |
21 fixtures :projects, :trackers, :issue_statuses, :issues, | 21 fixtures :projects, :trackers, :issue_statuses, :issues, |
22 :enumerations, :users, :issue_categories, | 22 :enumerations, :users, :issue_categories, |
23 :projects_trackers, | 23 :projects_trackers, |
24 :roles, | 24 :roles, |
25 :member_roles, | 25 :member_roles, |
26 :members, | 26 :members, |
27 :enabled_modules, | 27 :enabled_modules, |
28 :workflows, | |
29 :versions | 28 :versions |
30 | 29 |
31 def setup | 30 def setup |
32 Setting.rest_api_enabled = '1' | 31 Setting.rest_api_enabled = '1' |
33 end | 32 end |
34 | 33 |
35 context "/projects/:project_id/versions" do | 34 test "GET /projects/:project_id/versions.xml should return project versions" do |
36 context "GET" do | 35 get '/projects/1/versions.xml' |
37 should "return project versions" do | |
38 get '/projects/1/versions.xml' | |
39 | 36 |
40 assert_response :success | 37 assert_response :success |
41 assert_equal 'application/xml', @response.content_type | 38 assert_equal 'application/xml', @response.content_type |
42 assert_tag :tag => 'versions', | 39 assert_tag :tag => 'versions', |
43 :attributes => {:type => 'array'}, | 40 :attributes => {:type => 'array'}, |
44 :child => { | 41 :child => { |
45 :tag => 'version', | 42 :tag => 'version', |
46 :child => { | 43 :child => { |
47 :tag => 'id', | 44 :tag => 'id', |
48 :content => '2', | 45 :content => '2', |
49 :sibling => { | 46 :sibling => { |
50 :tag => 'name', | 47 :tag => 'name', |
51 :content => '1.0' | 48 :content => '1.0' |
52 } | |
53 } | |
54 } | 49 } |
55 end | 50 } |
51 } | |
52 end | |
53 | |
54 test "POST /projects/:project_id/versions.xml should create the version" do | |
55 assert_difference 'Version.count' do | |
56 post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith') | |
56 end | 57 end |
57 | 58 |
58 context "POST" do | 59 version = Version.first(:order => 'id DESC') |
59 should "create the version" do | 60 assert_equal 'API test', version.name |
60 assert_difference 'Version.count' do | |
61 post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith') | |
62 end | |
63 | 61 |
64 version = Version.first(:order => 'id DESC') | 62 assert_response :created |
65 assert_equal 'API test', version.name | 63 assert_equal 'application/xml', @response.content_type |
64 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} | |
65 end | |
66 | 66 |
67 assert_response :created | 67 test "POST /projects/:project_id/versions.xml should create the version with due date" do |
68 assert_equal 'application/xml', @response.content_type | 68 assert_difference 'Version.count' do |
69 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} | 69 post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith') |
70 end | 70 end |
71 | 71 |
72 should "create the version with due date" do | 72 version = Version.first(:order => 'id DESC') |
73 assert_difference 'Version.count' do | 73 assert_equal 'API test', version.name |
74 post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith') | 74 assert_equal Date.parse('2012-01-24'), version.due_date |
75 end | |
76 | 75 |
77 version = Version.first(:order => 'id DESC') | 76 assert_response :created |
78 assert_equal 'API test', version.name | 77 assert_equal 'application/xml', @response.content_type |
79 assert_equal Date.parse('2012-01-24'), version.due_date | 78 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} |
79 end | |
80 | 80 |
81 assert_response :created | 81 test "POST /projects/:project_id/versions.xml should create the version with custom fields" do |
82 assert_equal 'application/xml', @response.content_type | 82 field = VersionCustomField.generate! |
83 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} | |
84 end | |
85 | 83 |
86 context "with failure" do | 84 assert_difference 'Version.count' do |
87 should "return the errors" do | 85 post '/projects/1/versions.xml', { |
88 assert_no_difference('Version.count') do | 86 :version => { |
89 post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith') | 87 :name => 'API test', |
90 end | 88 :custom_fields => [ |
89 {'id' => field.id.to_s, 'value' => 'Some value'} | |
90 ] | |
91 } | |
92 }, credentials('jsmith') | |
93 end | |
91 | 94 |
92 assert_response :unprocessable_entity | 95 version = Version.first(:order => 'id DESC') |
93 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} | 96 assert_equal 'API test', version.name |
94 end | 97 assert_equal 'Some value', version.custom_field_value(field) |
95 end | 98 |
99 assert_response :created | |
100 assert_equal 'application/xml', @response.content_type | |
101 assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value' | |
102 end | |
103 | |
104 test "POST /projects/:project_id/versions.xml with failure should return the errors" do | |
105 assert_no_difference('Version.count') do | |
106 post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith') | |
107 end | |
108 | |
109 assert_response :unprocessable_entity | |
110 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} | |
111 end | |
112 | |
113 test "GET /versions/:id.xml should return the version" do | |
114 get '/versions/2.xml' | |
115 | |
116 assert_response :success | |
117 assert_equal 'application/xml', @response.content_type | |
118 assert_select 'version' do | |
119 assert_select 'id', :text => '2' | |
120 assert_select 'name', :text => '1.0' | |
121 assert_select 'sharing', :text => 'none' | |
96 end | 122 end |
97 end | 123 end |
98 | 124 |
99 context "/versions/:id" do | 125 test "PUT /versions/:id.xml should update the version" do |
100 context "GET" do | 126 put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') |
101 should "return the version" do | |
102 get '/versions/2.xml' | |
103 | 127 |
104 assert_response :success | 128 assert_response :ok |
105 assert_equal 'application/xml', @response.content_type | 129 assert_equal '', @response.body |
106 assert_select 'version' do | 130 assert_equal 'API update', Version.find(2).name |
107 assert_select 'id', :text => '2' | 131 end |
108 assert_select 'name', :text => '1.0' | 132 |
109 assert_select 'sharing', :text => 'none' | 133 test "DELETE /versions/:id.xml should destroy the version" do |
110 end | 134 assert_difference 'Version.count', -1 do |
111 end | 135 delete '/versions/3.xml', {}, credentials('jsmith') |
112 end | 136 end |
113 | 137 |
114 context "PUT" do | 138 assert_response :ok |
115 should "update the version" do | 139 assert_equal '', @response.body |
116 put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') | 140 assert_nil Version.find_by_id(3) |
117 | |
118 assert_response :ok | |
119 assert_equal '', @response.body | |
120 assert_equal 'API update', Version.find(2).name | |
121 end | |
122 end | |
123 | |
124 context "DELETE" do | |
125 should "destroy the version" do | |
126 assert_difference 'Version.count', -1 do | |
127 delete '/versions/3.xml', {}, credentials('jsmith') | |
128 end | |
129 | |
130 assert_response :ok | |
131 assert_equal '', @response.body | |
132 assert_nil Version.find_by_id(3) | |
133 end | |
134 end | |
135 end | 141 end |
136 end | 142 end |