annotate .svn/pristine/99/994c6e124b87f66f87d072585f0635b097da8f7b.svn-base @ 1494:e248c7af89ec redmine-2.4

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