annotate .svn/pristine/3d/3deac52abf28b28a938f19bd86796aea55496f9a.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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