annotate .svn/pristine/99/994c6e124b87f66f87d072585f0635b097da8f7b.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class SysControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects, :repositories, :enabled_modules
Chris@1295 22
Chris@1295 23 def setup
Chris@1295 24 Setting.sys_api_enabled = '1'
Chris@1295 25 Setting.enabled_scm = %w(Subversion Git)
Chris@1295 26 end
Chris@1295 27
Chris@1295 28 def teardown
Chris@1295 29 Setting.clear_cache
Chris@1295 30 end
Chris@1295 31
Chris@1295 32 def test_projects_with_repository_enabled
Chris@1295 33 get :projects
Chris@1295 34 assert_response :success
Chris@1295 35 assert_equal 'application/xml', @response.content_type
Chris@1295 36 with_options :tag => 'projects' do |test|
Chris@1295 37 test.assert_tag :children => { :count => Project.active.has_module(:repository).count }
Chris@1295 38 test.assert_tag 'project', :child => {:tag => 'identifier', :sibling => {:tag => 'is-public'}}
Chris@1295 39 end
Chris@1295 40 assert_no_tag 'extra-info'
Chris@1295 41 assert_no_tag 'extra_info'
Chris@1295 42 end
Chris@1295 43
Chris@1295 44 def test_create_project_repository
Chris@1295 45 assert_nil Project.find(4).repository
Chris@1295 46
Chris@1295 47 post :create_project_repository, :id => 4,
Chris@1295 48 :vendor => 'Subversion',
Chris@1295 49 :repository => { :url => 'file:///create/project/repository/subproject2'}
Chris@1295 50 assert_response :created
Chris@1295 51 assert_equal 'application/xml', @response.content_type
Chris@1295 52
Chris@1295 53 r = Project.find(4).repository
Chris@1295 54 assert r.is_a?(Repository::Subversion)
Chris@1295 55 assert_equal 'file:///create/project/repository/subproject2', r.url
Chris@1295 56
Chris@1295 57 assert_tag 'repository-subversion',
Chris@1295 58 :child => {
Chris@1295 59 :tag => 'id', :content => r.id.to_s,
Chris@1295 60 :sibling => {:tag => 'url', :content => r.url}
Chris@1295 61 }
Chris@1295 62 assert_no_tag 'extra-info'
Chris@1295 63 assert_no_tag 'extra_info'
Chris@1295 64 end
Chris@1295 65
Chris@1295 66 def test_create_already_existing
Chris@1295 67 post :create_project_repository, :id => 1,
Chris@1295 68 :vendor => 'Subversion',
Chris@1295 69 :repository => { :url => 'file:///create/project/repository/subproject2'}
Chris@1295 70
Chris@1295 71 assert_response :conflict
Chris@1295 72 end
Chris@1295 73
Chris@1295 74 def test_create_with_failure
Chris@1295 75 post :create_project_repository, :id => 4,
Chris@1295 76 :vendor => 'Subversion',
Chris@1295 77 :repository => { :url => 'invalid url'}
Chris@1295 78
Chris@1295 79 assert_response :unprocessable_entity
Chris@1295 80 end
Chris@1295 81
Chris@1295 82 def test_fetch_changesets
Chris@1295 83 Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true)
Chris@1295 84 get :fetch_changesets
Chris@1295 85 assert_response :success
Chris@1295 86 end
Chris@1295 87
Chris@1295 88 def test_fetch_changesets_one_project_by_identifier
Chris@1295 89 Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
Chris@1295 90 get :fetch_changesets, :id => 'ecookbook'
Chris@1295 91 assert_response :success
Chris@1295 92 end
Chris@1295 93
Chris@1295 94 def test_fetch_changesets_one_project_by_id
Chris@1295 95 Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
Chris@1295 96 get :fetch_changesets, :id => '1'
Chris@1295 97 assert_response :success
Chris@1295 98 end
Chris@1295 99
Chris@1295 100 def test_fetch_changesets_unknown_project
Chris@1295 101 get :fetch_changesets, :id => 'unknown'
Chris@1295 102 assert_response 404
Chris@1295 103 end
Chris@1295 104
Chris@1295 105 def test_disabled_ws_should_respond_with_403_error
Chris@1295 106 with_settings :sys_api_enabled => '0' do
Chris@1295 107 get :projects
Chris@1295 108 assert_response 403
Chris@1295 109 end
Chris@1295 110 end
Chris@1295 111
Chris@1295 112 def test_api_key
Chris@1295 113 with_settings :sys_api_key => 'my_secret_key' do
Chris@1295 114 get :projects, :key => 'my_secret_key'
Chris@1295 115 assert_response :success
Chris@1295 116 end
Chris@1295 117 end
Chris@1295 118
Chris@1295 119 def test_wrong_key_should_respond_with_403_error
Chris@1295 120 with_settings :sys_api_enabled => 'my_secret_key' do
Chris@1295 121 get :projects, :key => 'wrong_key'
Chris@1295 122 assert_response 403
Chris@1295 123 end
Chris@1295 124 end
Chris@1295 125 end