annotate .svn/pristine/d6/d67c3b233c2de5e381b50b04ecf28037f5dff73a.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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