##// END OF EJS Templates
Makes issue categories available in project REST API (#9553)....
Jean-Philippe Lang -
r7760:30556f8cbfac
parent child
Show More
@@ -1,19 +1,25
1 1 api.project do
2 2 api.id @project.id
3 3 api.name @project.name
4 4 api.identifier @project.identifier
5 5 api.description @project.description
6 6 api.homepage @project.homepage
7 7 api.parent(:id => @project.parent.id, :name => @project.parent.name) if @project.parent && @project.parent.visible?
8 8
9 9 render_api_custom_values @project.visible_custom_field_values, api
10 10
11 11 api.created_on @project.created_on
12 12 api.updated_on @project.updated_on
13 13
14 14 api.array :trackers do
15 15 @project.trackers.each do |tracker|
16 16 api.tracker(:id => tracker.id, :name => tracker.name)
17 17 end
18 18 end if include_in_api_response?('trackers')
19
20 api.array :issue_categories do
21 @project.issue_categories.each do |category|
22 api.issue_category(:id => category.id, :name => category.name)
23 end
24 end if include_in_api_response?('issue_categories')
19 25 end
@@ -1,262 +1,297
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::ProjectsTest < ActionController::IntegrationTest
21 21 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
22 22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
23 :attachments, :custom_fields, :custom_values, :time_entries
23 :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories
24 24
25 25 def setup
26 26 Setting.rest_api_enabled = '1'
27 27 set_tmp_attachments_directory
28 28 end
29 29
30 30 context "GET /projects" do
31 31 context ".xml" do
32 32 should "return projects" do
33 33 get '/projects.xml'
34 34 assert_response :success
35 35 assert_equal 'application/xml', @response.content_type
36 36
37 37 assert_tag :tag => 'projects',
38 38 :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
39 39 end
40 40 end
41 41
42 42 context ".json" do
43 43 should "return projects" do
44 44 get '/projects.json'
45 45 assert_response :success
46 46 assert_equal 'application/json', @response.content_type
47 47
48 48 json = ActiveSupport::JSON.decode(response.body)
49 49 assert_kind_of Hash, json
50 50 assert_kind_of Array, json['projects']
51 51 assert_kind_of Hash, json['projects'].first
52 52 assert json['projects'].first.has_key?('id')
53 53 end
54 54 end
55 55 end
56 56
57 57 context "GET /projects/:id" do
58 58 context ".xml" do
59 59 # TODO: A private project is needed because should_allow_api_authentication
60 60 # actually tests that authentication is *required*, not just allowed
61 61 should_allow_api_authentication(:get, "/projects/2.xml")
62 62
63 63 should "return requested project" do
64 64 get '/projects/1.xml'
65 65 assert_response :success
66 66 assert_equal 'application/xml', @response.content_type
67 67
68 68 assert_tag :tag => 'project',
69 69 :child => {:tag => 'id', :content => '1'}
70 70 assert_tag :tag => 'custom_field',
71 71 :attributes => {:name => 'Development status'}, :content => 'Stable'
72
73 assert_no_tag 'trackers'
74 assert_no_tag 'issue_categories'
72 75 end
73 76
74 77 context "with hidden custom fields" do
75 78 setup do
76 79 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
77 80 end
78 81
79 82 should "not display hidden custom fields" do
80 83 get '/projects/1.xml'
81 84 assert_response :success
82 85 assert_equal 'application/xml', @response.content_type
83 86
84 87 assert_no_tag 'custom_field',
85 88 :attributes => {:name => 'Development status'}
86 89 end
87 90 end
91
92 should "return categories with include=issue_categories" do
93 get '/projects/1.xml?include=issue_categories'
94 assert_response :success
95 assert_equal 'application/xml', @response.content_type
96
97 assert_tag 'issue_categories',
98 :attributes => {:type => 'array'},
99 :child => {
100 :tag => 'issue_category',
101 :attributes => {
102 :id => '2',
103 :name => 'Recipes'
104 }
105 }
106 end
107
108 should "return trackers with include=trackers" do
109 get '/projects/1.xml?include=trackers'
110 assert_response :success
111 assert_equal 'application/xml', @response.content_type
112
113 assert_tag 'trackers',
114 :attributes => {:type => 'array'},
115 :child => {
116 :tag => 'tracker',
117 :attributes => {
118 :id => '2',
119 :name => 'Feature request'
120 }
121 }
122 end
88 123 end
89 124
90 125 context ".json" do
91 126 should_allow_api_authentication(:get, "/projects/2.json")
92 127
93 128 should "return requested project" do
94 129 get '/projects/1.json'
95 130
96 131 json = ActiveSupport::JSON.decode(response.body)
97 132 assert_kind_of Hash, json
98 133 assert_kind_of Hash, json['project']
99 134 assert_equal 1, json['project']['id']
100 135 end
101 136 end
102 137 end
103 138
104 139 context "POST /projects" do
105 140 context "with valid parameters" do
106 141 setup do
107 142 Setting.default_projects_modules = ['issue_tracking', 'repository']
108 143 @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}}
109 144 end
110 145
111 146 context ".xml" do
112 147 should_allow_api_authentication(:post,
113 148 '/projects.xml',
114 149 {:project => {:name => 'API test', :identifier => 'api-test'}},
115 150 {:success_code => :created})
116 151
117 152
118 153 should "create a project with the attributes" do
119 154 assert_difference('Project.count') do
120 155 post '/projects.xml', @parameters, :authorization => credentials('admin')
121 156 end
122 157
123 158 project = Project.first(:order => 'id DESC')
124 159 assert_equal 'API test', project.name
125 160 assert_equal 'api-test', project.identifier
126 161 assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
127 162 assert_equal Tracker.all.size, project.trackers.size
128 163
129 164 assert_response :created
130 165 assert_equal 'application/xml', @response.content_type
131 166 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
132 167 end
133 168
134 169 should "accept enabled_module_names attribute" do
135 170 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
136 171
137 172 assert_difference('Project.count') do
138 173 post '/projects.xml', @parameters, :authorization => credentials('admin')
139 174 end
140 175
141 176 project = Project.first(:order => 'id DESC')
142 177 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
143 178 end
144 179
145 180 should "accept tracker_ids attribute" do
146 181 @parameters[:project].merge!({:tracker_ids => [1, 3]})
147 182
148 183 assert_difference('Project.count') do
149 184 post '/projects.xml', @parameters, :authorization => credentials('admin')
150 185 end
151 186
152 187 project = Project.first(:order => 'id DESC')
153 188 assert_equal [1, 3], project.trackers.map(&:id).sort
154 189 end
155 190 end
156 191 end
157 192
158 193 context "with invalid parameters" do
159 194 setup do
160 195 @parameters = {:project => {:name => 'API test'}}
161 196 end
162 197
163 198 context ".xml" do
164 199 should "return errors" do
165 200 assert_no_difference('Project.count') do
166 201 post '/projects.xml', @parameters, :authorization => credentials('admin')
167 202 end
168 203
169 204 assert_response :unprocessable_entity
170 205 assert_equal 'application/xml', @response.content_type
171 206 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
172 207 end
173 208 end
174 209 end
175 210 end
176 211
177 212 context "PUT /projects/:id" do
178 213 context "with valid parameters" do
179 214 setup do
180 215 @parameters = {:project => {:name => 'API update'}}
181 216 end
182 217
183 218 context ".xml" do
184 219 should_allow_api_authentication(:put,
185 220 '/projects/2.xml',
186 221 {:project => {:name => 'API update'}},
187 222 {:success_code => :ok})
188 223
189 224 should "update the project" do
190 225 assert_no_difference 'Project.count' do
191 226 put '/projects/2.xml', @parameters, :authorization => credentials('jsmith')
192 227 end
193 228 assert_response :ok
194 229 assert_equal 'application/xml', @response.content_type
195 230 project = Project.find(2)
196 231 assert_equal 'API update', project.name
197 232 end
198 233
199 234 should "accept enabled_module_names attribute" do
200 235 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
201 236
202 237 assert_no_difference 'Project.count' do
203 238 put '/projects/2.xml', @parameters, :authorization => credentials('admin')
204 239 end
205 240 assert_response :ok
206 241 project = Project.find(2)
207 242 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
208 243 end
209 244
210 245 should "accept tracker_ids attribute" do
211 246 @parameters[:project].merge!({:tracker_ids => [1, 3]})
212 247
213 248 assert_no_difference 'Project.count' do
214 249 put '/projects/2.xml', @parameters, :authorization => credentials('admin')
215 250 end
216 251 assert_response :ok
217 252 project = Project.find(2)
218 253 assert_equal [1, 3], project.trackers.map(&:id).sort
219 254 end
220 255 end
221 256 end
222 257
223 258 context "with invalid parameters" do
224 259 setup do
225 260 @parameters = {:project => {:name => ''}}
226 261 end
227 262
228 263 context ".xml" do
229 264 should "return errors" do
230 265 assert_no_difference('Project.count') do
231 266 put '/projects/2.xml', @parameters, :authorization => credentials('admin')
232 267 end
233 268
234 269 assert_response :unprocessable_entity
235 270 assert_equal 'application/xml', @response.content_type
236 271 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
237 272 end
238 273 end
239 274 end
240 275 end
241 276
242 277 context "DELETE /projects/:id" do
243 278 context ".xml" do
244 279 should_allow_api_authentication(:delete,
245 280 '/projects/2.xml',
246 281 {},
247 282 {:success_code => :ok})
248 283
249 284 should "delete the project" do
250 285 assert_difference('Project.count',-1) do
251 286 delete '/projects/2.xml', {}, :authorization => credentials('admin')
252 287 end
253 288 assert_response :ok
254 289 assert_nil Project.find_by_id(2)
255 290 end
256 291 end
257 292 end
258 293
259 294 def credentials(user, password=nil)
260 295 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
261 296 end
262 297 end
General Comments 0
You need to be logged in to leave comments. Login now