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