annotate test/integration/api_test/projects_test.rb @ 1458:b1f4c9a2af24 bug_794

Makes the default radio button checked by default -- this should fix bug #794.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 11 Nov 2013 18:25:22 +0000
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
rev   line source
chris@37 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
chris@37 3 #
chris@37 4 # This program is free software; you can redistribute it and/or
chris@37 5 # modify it under the terms of the GNU General Public License
chris@37 6 # as published by the Free Software Foundation; either version 2
chris@37 7 # of the License, or (at your option) any later version.
Chris@909 8 #
chris@37 9 # This program is distributed in the hope that it will be useful,
chris@37 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@37 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
chris@37 12 # GNU General Public License for more details.
Chris@909 13 #
chris@37 14 # You should have received a copy of the GNU General Public License
chris@37 15 # along with this program; if not, write to the Free Software
chris@37 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
chris@37 17
Chris@119 18 require File.expand_path('../../../test_helper', __FILE__)
chris@37 19
chris@37 20 class ApiTest::ProjectsTest < ActionController::IntegrationTest
chris@37 21 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
chris@37 22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
Chris@909 23 :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories
chris@37 24
chris@37 25 def setup
chris@37 26 Setting.rest_api_enabled = '1'
Chris@909 27 set_tmp_attachments_directory
chris@37 28 end
Chris@909 29
Chris@119 30 context "GET /projects" do
Chris@119 31 context ".xml" do
Chris@119 32 should "return projects" do
Chris@119 33 get '/projects.xml'
Chris@119 34 assert_response :success
Chris@119 35 assert_equal 'application/xml', @response.content_type
Chris@909 36
Chris@119 37 assert_tag :tag => 'projects',
Chris@119 38 :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
Chris@119 39 end
chris@37 40 end
chris@37 41
Chris@119 42 context ".json" do
Chris@119 43 should "return projects" do
Chris@119 44 get '/projects.json'
Chris@119 45 assert_response :success
Chris@119 46 assert_equal 'application/json', @response.content_type
Chris@909 47
Chris@119 48 json = ActiveSupport::JSON.decode(response.body)
Chris@119 49 assert_kind_of Hash, json
Chris@119 50 assert_kind_of Array, json['projects']
Chris@119 51 assert_kind_of Hash, json['projects'].first
Chris@119 52 assert json['projects'].first.has_key?('id')
Chris@119 53 end
chris@37 54 end
chris@37 55 end
Chris@909 56
Chris@119 57 context "GET /projects/:id" do
Chris@119 58 context ".xml" do
Chris@119 59 # TODO: A private project is needed because should_allow_api_authentication
Chris@119 60 # actually tests that authentication is *required*, not just allowed
Chris@119 61 should_allow_api_authentication(:get, "/projects/2.xml")
Chris@909 62
Chris@119 63 should "return requested project" do
Chris@119 64 get '/projects/1.xml'
Chris@119 65 assert_response :success
Chris@119 66 assert_equal 'application/xml', @response.content_type
Chris@909 67
Chris@119 68 assert_tag :tag => 'project',
Chris@119 69 :child => {:tag => 'id', :content => '1'}
Chris@119 70 assert_tag :tag => 'custom_field',
Chris@119 71 :attributes => {:name => 'Development status'}, :content => 'Stable'
Chris@909 72
Chris@909 73 assert_no_tag 'trackers'
Chris@909 74 assert_no_tag 'issue_categories'
Chris@119 75 end
Chris@909 76
Chris@119 77 context "with hidden custom fields" do
Chris@119 78 setup do
Chris@119 79 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
Chris@119 80 end
Chris@909 81
Chris@119 82 should "not display hidden custom fields" do
Chris@119 83 get '/projects/1.xml'
Chris@119 84 assert_response :success
Chris@119 85 assert_equal 'application/xml', @response.content_type
Chris@909 86
Chris@119 87 assert_no_tag 'custom_field',
Chris@119 88 :attributes => {:name => 'Development status'}
Chris@119 89 end
Chris@119 90 end
Chris@909 91
Chris@909 92 should "return categories with include=issue_categories" do
Chris@909 93 get '/projects/1.xml?include=issue_categories'
Chris@909 94 assert_response :success
Chris@909 95 assert_equal 'application/xml', @response.content_type
Chris@909 96
Chris@909 97 assert_tag 'issue_categories',
Chris@909 98 :attributes => {:type => 'array'},
Chris@909 99 :child => {
Chris@909 100 :tag => 'issue_category',
Chris@909 101 :attributes => {
Chris@909 102 :id => '2',
Chris@909 103 :name => 'Recipes'
Chris@909 104 }
Chris@909 105 }
Chris@909 106 end
Chris@909 107
Chris@909 108 should "return trackers with include=trackers" do
Chris@909 109 get '/projects/1.xml?include=trackers'
Chris@909 110 assert_response :success
Chris@909 111 assert_equal 'application/xml', @response.content_type
Chris@909 112
Chris@909 113 assert_tag 'trackers',
Chris@909 114 :attributes => {:type => 'array'},
Chris@909 115 :child => {
Chris@909 116 :tag => 'tracker',
Chris@909 117 :attributes => {
Chris@909 118 :id => '2',
Chris@909 119 :name => 'Feature request'
Chris@909 120 }
Chris@909 121 }
Chris@909 122 end
chris@37 123 end
Chris@119 124
Chris@119 125 context ".json" do
Chris@119 126 should_allow_api_authentication(:get, "/projects/2.json")
Chris@909 127
Chris@119 128 should "return requested project" do
Chris@119 129 get '/projects/1.json'
Chris@909 130
Chris@119 131 json = ActiveSupport::JSON.decode(response.body)
Chris@119 132 assert_kind_of Hash, json
Chris@119 133 assert_kind_of Hash, json['project']
Chris@119 134 assert_equal 1, json['project']['id']
Chris@119 135 end
Chris@119 136 end
Chris@119 137 end
Chris@909 138
Chris@119 139 context "POST /projects" do
Chris@119 140 context "with valid parameters" do
Chris@119 141 setup do
Chris@119 142 Setting.default_projects_modules = ['issue_tracking', 'repository']
Chris@119 143 @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}}
Chris@119 144 end
Chris@909 145
Chris@119 146 context ".xml" do
Chris@119 147 should_allow_api_authentication(:post,
Chris@119 148 '/projects.xml',
Chris@119 149 {:project => {:name => 'API test', :identifier => 'api-test'}},
Chris@119 150 {:success_code => :created})
Chris@909 151
Chris@909 152
Chris@119 153 should "create a project with the attributes" do
Chris@119 154 assert_difference('Project.count') do
Chris@1115 155 post '/projects.xml', @parameters, credentials('admin')
Chris@119 156 end
Chris@909 157
Chris@119 158 project = Project.first(:order => 'id DESC')
Chris@119 159 assert_equal 'API test', project.name
Chris@119 160 assert_equal 'api-test', project.identifier
Chris@119 161 assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
Chris@119 162 assert_equal Tracker.all.size, project.trackers.size
Chris@909 163
Chris@119 164 assert_response :created
Chris@119 165 assert_equal 'application/xml', @response.content_type
Chris@119 166 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
Chris@119 167 end
Chris@909 168
Chris@119 169 should "accept enabled_module_names attribute" do
Chris@119 170 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
Chris@909 171
Chris@119 172 assert_difference('Project.count') do
Chris@1115 173 post '/projects.xml', @parameters, credentials('admin')
Chris@119 174 end
Chris@909 175
Chris@119 176 project = Project.first(:order => 'id DESC')
Chris@119 177 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
Chris@119 178 end
Chris@909 179
Chris@119 180 should "accept tracker_ids attribute" do
Chris@119 181 @parameters[:project].merge!({:tracker_ids => [1, 3]})
Chris@909 182
Chris@119 183 assert_difference('Project.count') do
Chris@1115 184 post '/projects.xml', @parameters, credentials('admin')
Chris@119 185 end
Chris@909 186
Chris@119 187 project = Project.first(:order => 'id DESC')
Chris@119 188 assert_equal [1, 3], project.trackers.map(&:id).sort
Chris@119 189 end
Chris@119 190 end
Chris@119 191 end
Chris@909 192
Chris@119 193 context "with invalid parameters" do
Chris@119 194 setup do
Chris@119 195 @parameters = {:project => {:name => 'API test'}}
Chris@119 196 end
Chris@119 197
Chris@119 198 context ".xml" do
Chris@119 199 should "return errors" do
Chris@119 200 assert_no_difference('Project.count') do
Chris@1115 201 post '/projects.xml', @parameters, credentials('admin')
Chris@119 202 end
Chris@909 203
Chris@119 204 assert_response :unprocessable_entity
Chris@119 205 assert_equal 'application/xml', @response.content_type
Chris@119 206 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
Chris@119 207 end
Chris@119 208 end
Chris@119 209 end
chris@37 210 end
Chris@909 211
Chris@119 212 context "PUT /projects/:id" do
Chris@119 213 context "with valid parameters" do
Chris@119 214 setup do
Chris@119 215 @parameters = {:project => {:name => 'API update'}}
Chris@119 216 end
Chris@909 217
Chris@119 218 context ".xml" do
Chris@119 219 should_allow_api_authentication(:put,
Chris@119 220 '/projects/2.xml',
Chris@119 221 {:project => {:name => 'API update'}},
Chris@119 222 {:success_code => :ok})
Chris@909 223
Chris@119 224 should "update the project" do
Chris@119 225 assert_no_difference 'Project.count' do
Chris@1115 226 put '/projects/2.xml', @parameters, credentials('jsmith')
Chris@119 227 end
Chris@119 228 assert_response :ok
Chris@1115 229 assert_equal '', @response.body
Chris@119 230 assert_equal 'application/xml', @response.content_type
Chris@119 231 project = Project.find(2)
Chris@119 232 assert_equal 'API update', project.name
Chris@119 233 end
Chris@909 234
Chris@119 235 should "accept enabled_module_names attribute" do
Chris@119 236 @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
Chris@909 237
Chris@119 238 assert_no_difference 'Project.count' do
Chris@1115 239 put '/projects/2.xml', @parameters, credentials('admin')
Chris@119 240 end
Chris@119 241 assert_response :ok
Chris@1115 242 assert_equal '', @response.body
Chris@119 243 project = Project.find(2)
Chris@119 244 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
Chris@119 245 end
Chris@909 246
Chris@119 247 should "accept tracker_ids attribute" do
Chris@119 248 @parameters[:project].merge!({:tracker_ids => [1, 3]})
Chris@909 249
Chris@119 250 assert_no_difference 'Project.count' do
Chris@1115 251 put '/projects/2.xml', @parameters, credentials('admin')
Chris@119 252 end
Chris@119 253 assert_response :ok
Chris@1115 254 assert_equal '', @response.body
Chris@119 255 project = Project.find(2)
Chris@119 256 assert_equal [1, 3], project.trackers.map(&:id).sort
Chris@119 257 end
Chris@119 258 end
chris@37 259 end
Chris@909 260
Chris@119 261 context "with invalid parameters" do
Chris@119 262 setup do
Chris@119 263 @parameters = {:project => {:name => ''}}
Chris@119 264 end
Chris@909 265
Chris@119 266 context ".xml" do
Chris@119 267 should "return errors" do
Chris@119 268 assert_no_difference('Project.count') do
Chris@1115 269 put '/projects/2.xml', @parameters, credentials('admin')
Chris@119 270 end
Chris@909 271
Chris@119 272 assert_response :unprocessable_entity
Chris@119 273 assert_equal 'application/xml', @response.content_type
Chris@119 274 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
Chris@119 275 end
Chris@119 276 end
Chris@119 277 end
Chris@119 278 end
Chris@909 279
Chris@119 280 context "DELETE /projects/:id" do
Chris@119 281 context ".xml" do
Chris@119 282 should_allow_api_authentication(:delete,
Chris@119 283 '/projects/2.xml',
Chris@119 284 {},
Chris@119 285 {:success_code => :ok})
Chris@909 286
Chris@119 287 should "delete the project" do
Chris@119 288 assert_difference('Project.count',-1) do
Chris@1115 289 delete '/projects/2.xml', {}, credentials('admin')
Chris@119 290 end
Chris@119 291 assert_response :ok
Chris@1115 292 assert_equal '', @response.body
Chris@119 293 assert_nil Project.find_by_id(2)
Chris@119 294 end
Chris@119 295 end
chris@37 296 end
chris@37 297 end