##// END OF EJS Templates
Rails3: replace "all" fixtures at test/integration/api_test/versions_test.rb...
Toshi MARUYAMA -
r7388:2fef102a99ac
parent child
Show More
@@ -1,120 +1,128
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 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 31 def setup
24 32 Setting.rest_api_enabled = '1'
25 33 end
26 34
27 35 context "/projects/:project_id/versions" do
28 36 context "GET" do
29 37 should "return project versions" do
30 38 get '/projects/1/versions.xml'
31 39
32 40 assert_response :success
33 41 assert_equal 'application/xml', @response.content_type
34 42 assert_tag :tag => 'versions',
35 43 :attributes => {:type => 'array'},
36 44 :child => {
37 45 :tag => 'version',
38 46 :child => {
39 47 :tag => 'id',
40 48 :content => '2',
41 49 :sibling => {
42 50 :tag => 'name',
43 51 :content => '1.0'
44 52 }
45 53 }
46 54 }
47 55 end
48 56 end
49 57
50 58 context "POST" do
51 59 should "create the version" do
52 60 assert_difference 'Version.count' do
53 61 post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, :authorization => credentials('jsmith')
54 62 end
55 63
56 64 version = Version.first(:order => 'id DESC')
57 65 assert_equal 'API test', version.name
58 66
59 67 assert_response :created
60 68 assert_equal 'application/xml', @response.content_type
61 69 assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
62 70 end
63 71
64 72 context "with failure" do
65 73 should "return the errors" do
66 74 assert_no_difference('Version.count') do
67 75 post '/projects/1/versions.xml', {:version => {:name => ''}}, :authorization => credentials('jsmith')
68 76 end
69 77
70 78 assert_response :unprocessable_entity
71 79 assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
72 80 end
73 81 end
74 82 end
75 83 end
76 84
77 85 context "/versions/:id" do
78 86 context "GET" do
79 87 should "return the version" do
80 88 get '/versions/2.xml'
81 89
82 90 assert_response :success
83 91 assert_equal 'application/xml', @response.content_type
84 92 assert_tag 'version',
85 93 :child => {
86 94 :tag => 'id',
87 95 :content => '2',
88 96 :sibling => {
89 97 :tag => 'name',
90 98 :content => '1.0'
91 99 }
92 100 }
93 101 end
94 102 end
95 103
96 104 context "PUT" do
97 105 should "update the version" do
98 106 put '/versions/2.xml', {:version => {:name => 'API update'}}, :authorization => credentials('jsmith')
99 107
100 108 assert_response :ok
101 109 assert_equal 'API update', Version.find(2).name
102 110 end
103 111 end
104 112
105 113 context "DELETE" do
106 114 should "destroy the version" do
107 115 assert_difference 'Version.count', -1 do
108 116 delete '/versions/3.xml', {}, :authorization => credentials('jsmith')
109 117 end
110 118
111 119 assert_response :ok
112 120 assert_nil Version.find_by_id(3)
113 121 end
114 122 end
115 123 end
116 124
117 125 def credentials(user, password=nil)
118 126 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
119 127 end
120 128 end
General Comments 0
You need to be logged in to leave comments. Login now