##// END OF EJS Templates
Add project is_public to GET /projects/:id and /projects API response (#17628)....
Jean-Baptiste Barth -
r12985:772418461f0c
parent child
Show More
@@ -1,17 +1,18
1 1 api.array :projects, api_meta(:total_count => @project_count, :offset => @offset, :limit => @limit) do
2 2 @projects.each do |project|
3 3 api.project do
4 4 api.id project.id
5 5 api.name project.name
6 6 api.identifier project.identifier
7 7 api.description project.description
8 8 api.parent(:id => project.parent.id, :name => project.parent.name) if project.parent && project.parent.visible?
9 9 api.status project.status
10 api.is_public project.is_public?
10 11
11 12 render_api_custom_values project.visible_custom_field_values, api
12 13
13 14 api.created_on project.created_on
14 15 api.updated_on project.updated_on
15 16 end
16 17 end
17 18 end
@@ -1,26 +1,27
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 api.status @project.status
9 api.is_public @project.is_public?
9 10
10 11 render_api_custom_values @project.visible_custom_field_values, api
11 12
12 13 api.created_on @project.created_on
13 14 api.updated_on @project.updated_on
14 15
15 16 api.array :trackers do
16 17 @project.trackers.each do |tracker|
17 18 api.tracker(:id => tracker.id, :name => tracker.name)
18 19 end
19 20 end if include_in_api_response?('trackers')
20 21
21 22 api.array :issue_categories do
22 23 @project.issue_categories.each do |category|
23 24 api.issue_category(:id => category.id, :name => category.name)
24 25 end
25 26 end if include_in_api_response?('issue_categories')
26 27 end
@@ -1,234 +1,236
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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 Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
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 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 # TODO: A private project is needed because should_allow_api_authentication
31 31 # actually tests that authentication is *required*, not just allowed
32 32 should_allow_api_authentication(:get, "/projects/2.xml")
33 33 should_allow_api_authentication(:get, "/projects/2.json")
34 34 should_allow_api_authentication(:post,
35 35 '/projects.xml',
36 36 {:project => {:name => 'API test', :identifier => 'api-test'}},
37 37 {:success_code => :created})
38 38 should_allow_api_authentication(:put,
39 39 '/projects/2.xml',
40 40 {:project => {:name => 'API update'}},
41 41 {:success_code => :ok})
42 42 should_allow_api_authentication(:delete,
43 43 '/projects/2.xml',
44 44 {},
45 45 {:success_code => :ok})
46 46
47 47 test "GET /projects.xml should return projects" do
48 48 get '/projects.xml'
49 49 assert_response :success
50 50 assert_equal 'application/xml', @response.content_type
51 51
52 52 assert_select 'projects>project>id', :text => '1'
53 53 assert_select 'projects>project>status', :text => '1'
54 assert_select 'projects>project>is_public', :text => 'true'
54 55 end
55 56
56 57 test "GET /projects.json should return projects" do
57 58 get '/projects.json'
58 59 assert_response :success
59 60 assert_equal 'application/json', @response.content_type
60 61
61 62 json = ActiveSupport::JSON.decode(response.body)
62 63 assert_kind_of Hash, json
63 64 assert_kind_of Array, json['projects']
64 65 assert_kind_of Hash, json['projects'].first
65 66 assert json['projects'].first.has_key?('id')
66 67 end
67 68
68 69 test "GET /projects/:id.xml should return the project" do
69 70 get '/projects/1.xml'
70 71 assert_response :success
71 72 assert_equal 'application/xml', @response.content_type
72 73
73 74 assert_select 'project>id', :text => '1'
74 75 assert_select 'project>status', :text => '1'
76 assert_select 'project>is_public', :text => 'true'
75 77 assert_select 'custom_field[name=Development status]', :text => 'Stable'
76 78
77 79 assert_no_tag 'trackers'
78 80 assert_no_tag 'issue_categories'
79 81 end
80 82
81 83 test "GET /projects/:id.json should return the project" do
82 84 get '/projects/1.json'
83 85
84 86 json = ActiveSupport::JSON.decode(response.body)
85 87 assert_kind_of Hash, json
86 88 assert_kind_of Hash, json['project']
87 89 assert_equal 1, json['project']['id']
88 90 end
89 91
90 92 test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
91 93 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
92 94
93 95 get '/projects/1.xml'
94 96 assert_response :success
95 97 assert_equal 'application/xml', @response.content_type
96 98
97 99 assert_no_tag 'custom_field',
98 100 :attributes => {:name => 'Development status'}
99 101 end
100 102
101 103 test "GET /projects/:id.xml with include=issue_categories should return categories" do
102 104 get '/projects/1.xml?include=issue_categories'
103 105 assert_response :success
104 106 assert_equal 'application/xml', @response.content_type
105 107
106 108 assert_tag 'issue_categories',
107 109 :attributes => {:type => 'array'},
108 110 :child => {
109 111 :tag => 'issue_category',
110 112 :attributes => {
111 113 :id => '2',
112 114 :name => 'Recipes'
113 115 }
114 116 }
115 117 end
116 118
117 119 test "GET /projects/:id.xml with include=trackers should return trackers" do
118 120 get '/projects/1.xml?include=trackers'
119 121 assert_response :success
120 122 assert_equal 'application/xml', @response.content_type
121 123
122 124 assert_tag 'trackers',
123 125 :attributes => {:type => 'array'},
124 126 :child => {
125 127 :tag => 'tracker',
126 128 :attributes => {
127 129 :id => '2',
128 130 :name => 'Feature request'
129 131 }
130 132 }
131 133 end
132 134
133 135 test "POST /projects.xml with valid parameters should create the project" do
134 136 Setting.default_projects_modules = ['issue_tracking', 'repository']
135 137
136 138 assert_difference('Project.count') do
137 139 post '/projects.xml',
138 140 {:project => {:name => 'API test', :identifier => 'api-test'}},
139 141 credentials('admin')
140 142 end
141 143
142 144 project = Project.order('id DESC').first
143 145 assert_equal 'API test', project.name
144 146 assert_equal 'api-test', project.identifier
145 147 assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
146 148 assert_equal Tracker.all.size, project.trackers.size
147 149
148 150 assert_response :created
149 151 assert_equal 'application/xml', @response.content_type
150 152 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
151 153 end
152 154
153 155 test "POST /projects.xml should accept enabled_module_names attribute" do
154 156 assert_difference('Project.count') do
155 157 post '/projects.xml',
156 158 {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
157 159 credentials('admin')
158 160 end
159 161
160 162 project = Project.order('id DESC').first
161 163 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
162 164 end
163 165
164 166 test "POST /projects.xml should accept tracker_ids attribute" do
165 167 assert_difference('Project.count') do
166 168 post '/projects.xml',
167 169 {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
168 170 credentials('admin')
169 171 end
170 172
171 173 project = Project.order('id DESC').first
172 174 assert_equal [1, 3], project.trackers.map(&:id).sort
173 175 end
174 176
175 177 test "POST /projects.xml with invalid parameters should return errors" do
176 178 assert_no_difference('Project.count') do
177 179 post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin')
178 180 end
179 181
180 182 assert_response :unprocessable_entity
181 183 assert_equal 'application/xml', @response.content_type
182 184 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
183 185 end
184 186
185 187 test "PUT /projects/:id.xml with valid parameters should update the project" do
186 188 assert_no_difference 'Project.count' do
187 189 put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith')
188 190 end
189 191 assert_response :ok
190 192 assert_equal '', @response.body
191 193 assert_equal 'application/xml', @response.content_type
192 194 project = Project.find(2)
193 195 assert_equal 'API update', project.name
194 196 end
195 197
196 198 test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
197 199 assert_no_difference 'Project.count' do
198 200 put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin')
199 201 end
200 202 assert_response :ok
201 203 assert_equal '', @response.body
202 204 project = Project.find(2)
203 205 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
204 206 end
205 207
206 208 test "PUT /projects/:id.xml should accept tracker_ids attribute" do
207 209 assert_no_difference 'Project.count' do
208 210 put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin')
209 211 end
210 212 assert_response :ok
211 213 assert_equal '', @response.body
212 214 project = Project.find(2)
213 215 assert_equal [1, 3], project.trackers.map(&:id).sort
214 216 end
215 217
216 218 test "PUT /projects/:id.xml with invalid parameters should return errors" do
217 219 assert_no_difference('Project.count') do
218 220 put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin')
219 221 end
220 222
221 223 assert_response :unprocessable_entity
222 224 assert_equal 'application/xml', @response.content_type
223 225 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
224 226 end
225 227
226 228 test "DELETE /projects/:id.xml should delete the project" do
227 229 assert_difference('Project.count',-1) do
228 230 delete '/projects/2.xml', {}, credentials('admin')
229 231 end
230 232 assert_response :ok
231 233 assert_equal '', @response.body
232 234 assert_nil Project.find_by_id(2)
233 235 end
234 236 end
General Comments 0
You need to be logged in to leave comments. Login now