##// END OF EJS Templates
remove trailing white-spaces from test/integration/api_test/projects_test.rb....
Toshi MARUYAMA -
r6552:1762486c231a
parent child
Show More
@@ -1,16 +1,16
1 1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
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.
@@ -25,14 +25,14 class ApiTest::ProjectsTest < ActionController::IntegrationTest
25 25 def setup
26 26 Setting.rest_api_enabled = '1'
27 27 end
28
28
29 29 context "GET /projects" do
30 30 context ".xml" do
31 31 should "return projects" do
32 32 get '/projects.xml'
33 33 assert_response :success
34 34 assert_equal 'application/xml', @response.content_type
35
35
36 36 assert_tag :tag => 'projects',
37 37 :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
38 38 end
@@ -43,7 +43,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest
43 43 get '/projects.json'
44 44 assert_response :success
45 45 assert_equal 'application/json', @response.content_type
46
46
47 47 json = ActiveSupport::JSON.decode(response.body)
48 48 assert_kind_of Hash, json
49 49 assert_kind_of Array, json['projects']
@@ -52,34 +52,34 class ApiTest::ProjectsTest < ActionController::IntegrationTest
52 52 end
53 53 end
54 54 end
55
55
56 56 context "GET /projects/:id" do
57 57 context ".xml" do
58 58 # TODO: A private project is needed because should_allow_api_authentication
59 59 # actually tests that authentication is *required*, not just allowed
60 60 should_allow_api_authentication(:get, "/projects/2.xml")
61
61
62 62 should "return requested project" do
63 63 get '/projects/1.xml'
64 64 assert_response :success
65 65 assert_equal 'application/xml', @response.content_type
66
66
67 67 assert_tag :tag => 'project',
68 68 :child => {:tag => 'id', :content => '1'}
69 69 assert_tag :tag => 'custom_field',
70 70 :attributes => {:name => 'Development status'}, :content => 'Stable'
71 71 end
72
72
73 73 context "with hidden custom fields" do
74 74 setup do
75 75 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
76 76 end
77
77
78 78 should "not display hidden custom fields" do
79 79 get '/projects/1.xml'
80 80 assert_response :success
81 81 assert_equal 'application/xml', @response.content_type
82
82
83 83 assert_no_tag 'custom_field',
84 84 :attributes => {:name => 'Development status'}
85 85 end
@@ -88,10 +88,10 class ApiTest::ProjectsTest < ActionController::IntegrationTest
88 88
89 89 context ".json" do
90 90 should_allow_api_authentication(:get, "/projects/2.json")
91
91
92 92 should "return requested project" do
93 93 get '/projects/1.json'
94
94
95 95 json = ActiveSupport::JSON.decode(response.body)
96 96 assert_kind_of Hash, json
97 97 assert_kind_of Hash, json['project']
@@ -99,61 +99,61 class ApiTest::ProjectsTest < ActionController::IntegrationTest
99 99 end
100 100 end
101 101 end
102
102
103 103 context "POST /projects" do
104 104 context "with valid parameters" do
105 105 setup do
106 106 Setting.default_projects_modules = ['issue_tracking', 'repository']
107 107 @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}}
108 108 end
109
109
110 110 context ".xml" do
111 111 should_allow_api_authentication(:post,
112 112 '/projects.xml',
113 113 {:project => {:name => 'API test', :identifier => 'api-test'}},
114 114 {:success_code => :created})
115
116
115
116
117 117 should "create a project with the attributes" do
118 118 assert_difference('Project.count') do
119 119 post '/projects.xml', @parameters, :authorization => credentials('admin')
120 120 end
121
121
122 122 project = Project.first(:order => 'id DESC')
123 123 assert_equal 'API test', project.name
124 124 assert_equal 'api-test', project.identifier
125 125 assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
126 126 assert_equal Tracker.all.size, project.trackers.size
127
127
128 128 assert_response :created
129 129 assert_equal 'application/xml', @response.content_type
130 130 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
131 131 end
132
132
133 133 should "accept enabled_module_names attribute" do
134 134 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
135
135
136 136 assert_difference('Project.count') do
137 137 post '/projects.xml', @parameters, :authorization => credentials('admin')
138 138 end
139
139
140 140 project = Project.first(:order => 'id DESC')
141 141 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
142 142 end
143
143
144 144 should "accept tracker_ids attribute" do
145 145 @parameters[:project].merge!({:tracker_ids => [1, 3]})
146
146
147 147 assert_difference('Project.count') do
148 148 post '/projects.xml', @parameters, :authorization => credentials('admin')
149 149 end
150
150
151 151 project = Project.first(:order => 'id DESC')
152 152 assert_equal [1, 3], project.trackers.map(&:id).sort
153 153 end
154 154 end
155 155 end
156
156
157 157 context "with invalid parameters" do
158 158 setup do
159 159 @parameters = {:project => {:name => 'API test'}}
@@ -164,7 +164,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest
164 164 assert_no_difference('Project.count') do
165 165 post '/projects.xml', @parameters, :authorization => credentials('admin')
166 166 end
167
167
168 168 assert_response :unprocessable_entity
169 169 assert_equal 'application/xml', @response.content_type
170 170 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
@@ -172,19 +172,19 class ApiTest::ProjectsTest < ActionController::IntegrationTest
172 172 end
173 173 end
174 174 end
175
175
176 176 context "PUT /projects/:id" do
177 177 context "with valid parameters" do
178 178 setup do
179 179 @parameters = {:project => {:name => 'API update'}}
180 180 end
181
181
182 182 context ".xml" do
183 183 should_allow_api_authentication(:put,
184 184 '/projects/2.xml',
185 185 {:project => {:name => 'API update'}},
186 186 {:success_code => :ok})
187
187
188 188 should "update the project" do
189 189 assert_no_difference 'Project.count' do
190 190 put '/projects/2.xml', @parameters, :authorization => credentials('jsmith')
@@ -194,10 +194,10 class ApiTest::ProjectsTest < ActionController::IntegrationTest
194 194 project = Project.find(2)
195 195 assert_equal 'API update', project.name
196 196 end
197
197
198 198 should "accept enabled_module_names attribute" do
199 199 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
200
200
201 201 assert_no_difference 'Project.count' do
202 202 put '/projects/2.xml', @parameters, :authorization => credentials('admin')
203 203 end
@@ -205,10 +205,10 class ApiTest::ProjectsTest < ActionController::IntegrationTest
205 205 project = Project.find(2)
206 206 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
207 207 end
208
208
209 209 should "accept tracker_ids attribute" do
210 210 @parameters[:project].merge!({:tracker_ids => [1, 3]})
211
211
212 212 assert_no_difference 'Project.count' do
213 213 put '/projects/2.xml', @parameters, :authorization => credentials('admin')
214 214 end
@@ -218,18 +218,18 class ApiTest::ProjectsTest < ActionController::IntegrationTest
218 218 end
219 219 end
220 220 end
221
221
222 222 context "with invalid parameters" do
223 223 setup do
224 224 @parameters = {:project => {:name => ''}}
225 225 end
226
226
227 227 context ".xml" do
228 228 should "return errors" do
229 229 assert_no_difference('Project.count') do
230 230 put '/projects/2.xml', @parameters, :authorization => credentials('admin')
231 231 end
232
232
233 233 assert_response :unprocessable_entity
234 234 assert_equal 'application/xml', @response.content_type
235 235 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
@@ -237,14 +237,14 class ApiTest::ProjectsTest < ActionController::IntegrationTest
237 237 end
238 238 end
239 239 end
240
240
241 241 context "DELETE /projects/:id" do
242 242 context ".xml" do
243 243 should_allow_api_authentication(:delete,
244 244 '/projects/2.xml',
245 245 {},
246 246 {:success_code => :ok})
247
247
248 248 should "delete the project" do
249 249 assert_difference('Project.count',-1) do
250 250 delete '/projects/2.xml', {}, :authorization => credentials('admin')
@@ -254,7 +254,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest
254 254 end
255 255 end
256 256 end
257
257
258 258 def credentials(user, password=nil)
259 259 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
260 260 end
General Comments 0
You need to be logged in to leave comments. Login now