@@ -1,120 +1,128 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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 ApiTest::VersionsTest < ActionController::IntegrationTest | |
21 | fixtures :all |
|
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 | :workflows, | |||
|
29 | :versions | |||
22 |
|
30 | |||
23 | def setup |
|
31 | def setup | |
24 | Setting.rest_api_enabled = '1' |
|
32 | Setting.rest_api_enabled = '1' | |
25 | end |
|
33 | end | |
26 |
|
34 | |||
27 | context "/projects/:project_id/versions" do |
|
35 | context "/projects/:project_id/versions" do | |
28 | context "GET" do |
|
36 | context "GET" do | |
29 | should "return project versions" do |
|
37 | should "return project versions" do | |
30 | get '/projects/1/versions.xml' |
|
38 | get '/projects/1/versions.xml' | |
31 |
|
39 | |||
32 | assert_response :success |
|
40 | assert_response :success | |
33 | assert_equal 'application/xml', @response.content_type |
|
41 | assert_equal 'application/xml', @response.content_type | |
34 | assert_tag :tag => 'versions', |
|
42 | assert_tag :tag => 'versions', | |
35 | :attributes => {:type => 'array'}, |
|
43 | :attributes => {:type => 'array'}, | |
36 | :child => { |
|
44 | :child => { | |
37 | :tag => 'version', |
|
45 | :tag => 'version', | |
38 | :child => { |
|
46 | :child => { | |
39 | :tag => 'id', |
|
47 | :tag => 'id', | |
40 | :content => '2', |
|
48 | :content => '2', | |
41 | :sibling => { |
|
49 | :sibling => { | |
42 | :tag => 'name', |
|
50 | :tag => 'name', | |
43 | :content => '1.0' |
|
51 | :content => '1.0' | |
44 | } |
|
52 | } | |
45 | } |
|
53 | } | |
46 | } |
|
54 | } | |
47 | end |
|
55 | end | |
48 | end |
|
56 | end | |
49 |
|
57 | |||
50 | context "POST" do |
|
58 | context "POST" do | |
51 | should "create the version" do |
|
59 | should "create the version" do | |
52 | assert_difference 'Version.count' do |
|
60 | assert_difference 'Version.count' do | |
53 | post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, :authorization => credentials('jsmith') |
|
61 | post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, :authorization => credentials('jsmith') | |
54 | end |
|
62 | end | |
55 |
|
63 | |||
56 | version = Version.first(:order => 'id DESC') |
|
64 | version = Version.first(:order => 'id DESC') | |
57 | assert_equal 'API test', version.name |
|
65 | assert_equal 'API test', version.name | |
58 |
|
66 | |||
59 | assert_response :created |
|
67 | assert_response :created | |
60 | assert_equal 'application/xml', @response.content_type |
|
68 | assert_equal 'application/xml', @response.content_type | |
61 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} |
|
69 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} | |
62 | end |
|
70 | end | |
63 |
|
71 | |||
64 | context "with failure" do |
|
72 | context "with failure" do | |
65 | should "return the errors" do |
|
73 | should "return the errors" do | |
66 | assert_no_difference('Version.count') do |
|
74 | assert_no_difference('Version.count') do | |
67 | post '/projects/1/versions.xml', {:version => {:name => ''}}, :authorization => credentials('jsmith') |
|
75 | post '/projects/1/versions.xml', {:version => {:name => ''}}, :authorization => credentials('jsmith') | |
68 | end |
|
76 | end | |
69 |
|
77 | |||
70 | assert_response :unprocessable_entity |
|
78 | assert_response :unprocessable_entity | |
71 | assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} |
|
79 | assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"} | |
72 | end |
|
80 | end | |
73 | end |
|
81 | end | |
74 | end |
|
82 | end | |
75 | end |
|
83 | end | |
76 |
|
84 | |||
77 | context "/versions/:id" do |
|
85 | context "/versions/:id" do | |
78 | context "GET" do |
|
86 | context "GET" do | |
79 | should "return the version" do |
|
87 | should "return the version" do | |
80 | get '/versions/2.xml' |
|
88 | get '/versions/2.xml' | |
81 |
|
89 | |||
82 | assert_response :success |
|
90 | assert_response :success | |
83 | assert_equal 'application/xml', @response.content_type |
|
91 | assert_equal 'application/xml', @response.content_type | |
84 | assert_tag 'version', |
|
92 | assert_tag 'version', | |
85 | :child => { |
|
93 | :child => { | |
86 | :tag => 'id', |
|
94 | :tag => 'id', | |
87 | :content => '2', |
|
95 | :content => '2', | |
88 | :sibling => { |
|
96 | :sibling => { | |
89 | :tag => 'name', |
|
97 | :tag => 'name', | |
90 | :content => '1.0' |
|
98 | :content => '1.0' | |
91 | } |
|
99 | } | |
92 | } |
|
100 | } | |
93 | end |
|
101 | end | |
94 | end |
|
102 | end | |
95 |
|
103 | |||
96 | context "PUT" do |
|
104 | context "PUT" do | |
97 | should "update the version" do |
|
105 | should "update the version" do | |
98 | put '/versions/2.xml', {:version => {:name => 'API update'}}, :authorization => credentials('jsmith') |
|
106 | put '/versions/2.xml', {:version => {:name => 'API update'}}, :authorization => credentials('jsmith') | |
99 |
|
107 | |||
100 | assert_response :ok |
|
108 | assert_response :ok | |
101 | assert_equal 'API update', Version.find(2).name |
|
109 | assert_equal 'API update', Version.find(2).name | |
102 | end |
|
110 | end | |
103 | end |
|
111 | end | |
104 |
|
112 | |||
105 | context "DELETE" do |
|
113 | context "DELETE" do | |
106 | should "destroy the version" do |
|
114 | should "destroy the version" do | |
107 | assert_difference 'Version.count', -1 do |
|
115 | assert_difference 'Version.count', -1 do | |
108 | delete '/versions/3.xml', {}, :authorization => credentials('jsmith') |
|
116 | delete '/versions/3.xml', {}, :authorization => credentials('jsmith') | |
109 | end |
|
117 | end | |
110 |
|
118 | |||
111 | assert_response :ok |
|
119 | assert_response :ok | |
112 | assert_nil Version.find_by_id(3) |
|
120 | assert_nil Version.find_by_id(3) | |
113 | end |
|
121 | end | |
114 | end |
|
122 | end | |
115 | end |
|
123 | end | |
116 |
|
124 | |||
117 | def credentials(user, password=nil) |
|
125 | def credentials(user, password=nil) | |
118 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
|
126 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
119 | end |
|
127 | end | |
120 | end |
|
128 | end |
General Comments 0
You need to be logged in to leave comments.
Login now