2009-02-11 01:03:25 +03:00
|
|
|
# Redmine - project management software
|
2012-05-05 16:56:53 +04:00
|
|
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
2009-02-11 01:03:25 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-25 08:40:18 +04:00
|
|
|
#
|
2009-02-11 01:03:25 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-25 08:40:18 +04:00
|
|
|
#
|
2009-02-11 01:03:25 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2009-02-11 01:03:25 +03:00
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class SysControllerTest < ActionController::TestCase
|
2011-03-16 23:31:01 +03:00
|
|
|
fixtures :projects, :repositories, :enabled_modules
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2009-02-11 01:03:25 +03:00
|
|
|
def setup
|
|
|
|
Setting.sys_api_enabled = '1'
|
2009-03-01 13:55:01 +03:00
|
|
|
Setting.enabled_scm = %w(Subversion Git)
|
2009-02-11 01:03:25 +03:00
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2012-07-08 16:23:47 +04:00
|
|
|
def teardown
|
|
|
|
Setting.clear_cache
|
|
|
|
end
|
|
|
|
|
2009-02-11 01:03:25 +03:00
|
|
|
def test_projects_with_repository_enabled
|
|
|
|
get :projects
|
|
|
|
assert_response :success
|
|
|
|
assert_equal 'application/xml', @response.content_type
|
|
|
|
with_options :tag => 'projects' do |test|
|
|
|
|
test.assert_tag :children => { :count => Project.active.has_module(:repository).count }
|
2011-11-27 21:30:28 +04:00
|
|
|
test.assert_tag 'project', :child => {:tag => 'identifier', :sibling => {:tag => 'is-public'}}
|
2009-02-11 01:03:25 +03:00
|
|
|
end
|
2011-11-27 21:30:28 +04:00
|
|
|
assert_no_tag 'extra-info'
|
|
|
|
assert_no_tag 'extra_info'
|
2009-02-11 01:03:25 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_project_repository
|
|
|
|
assert_nil Project.find(4).repository
|
2011-05-25 08:40:18 +04:00
|
|
|
|
|
|
|
post :create_project_repository, :id => 4,
|
2009-02-11 01:03:25 +03:00
|
|
|
:vendor => 'Subversion',
|
|
|
|
:repository => { :url => 'file:///create/project/repository/subproject2'}
|
|
|
|
assert_response :created
|
2011-11-27 21:30:28 +04:00
|
|
|
assert_equal 'application/xml', @response.content_type
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2009-02-11 01:03:25 +03:00
|
|
|
r = Project.find(4).repository
|
|
|
|
assert r.is_a?(Repository::Subversion)
|
|
|
|
assert_equal 'file:///create/project/repository/subproject2', r.url
|
2011-11-27 21:30:28 +04:00
|
|
|
|
|
|
|
assert_tag 'repository-subversion',
|
|
|
|
:child => {
|
|
|
|
:tag => 'id', :content => r.id.to_s,
|
|
|
|
:sibling => {:tag => 'url', :content => r.url}
|
|
|
|
}
|
|
|
|
assert_no_tag 'extra-info'
|
|
|
|
assert_no_tag 'extra_info'
|
2009-02-11 01:03:25 +03:00
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2011-12-03 17:59:17 +04:00
|
|
|
def test_create_already_existing
|
|
|
|
post :create_project_repository, :id => 1,
|
|
|
|
:vendor => 'Subversion',
|
|
|
|
:repository => { :url => 'file:///create/project/repository/subproject2'}
|
|
|
|
|
|
|
|
assert_response :conflict
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_with_failure
|
|
|
|
post :create_project_repository, :id => 4,
|
|
|
|
:vendor => 'Subversion',
|
|
|
|
:repository => { :url => 'invalid url'}
|
|
|
|
|
|
|
|
assert_response :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
2009-11-28 19:50:26 +03:00
|
|
|
def test_fetch_changesets
|
2012-01-15 18:23:06 +04:00
|
|
|
Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true)
|
2009-11-28 19:50:26 +03:00
|
|
|
get :fetch_changesets
|
|
|
|
assert_response :success
|
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2012-02-25 16:57:30 +04:00
|
|
|
def test_fetch_changesets_one_project_by_identifier
|
2012-01-15 18:23:06 +04:00
|
|
|
Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
|
2009-11-28 19:50:26 +03:00
|
|
|
get :fetch_changesets, :id => 'ecookbook'
|
|
|
|
assert_response :success
|
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2012-02-25 16:57:30 +04:00
|
|
|
def test_fetch_changesets_one_project_by_id
|
|
|
|
Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
|
|
|
|
get :fetch_changesets, :id => '1'
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2009-11-28 19:50:26 +03:00
|
|
|
def test_fetch_changesets_unknown_project
|
|
|
|
get :fetch_changesets, :id => 'unknown'
|
|
|
|
assert_response 404
|
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2009-12-20 12:44:28 +03:00
|
|
|
def test_disabled_ws_should_respond_with_403_error
|
|
|
|
with_settings :sys_api_enabled => '0' do
|
|
|
|
get :projects
|
|
|
|
assert_response 403
|
|
|
|
end
|
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2009-12-20 12:44:28 +03:00
|
|
|
def test_api_key
|
|
|
|
with_settings :sys_api_key => 'my_secret_key' do
|
|
|
|
get :projects, :key => 'my_secret_key'
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
2011-05-25 08:40:18 +04:00
|
|
|
|
2009-12-20 12:44:28 +03:00
|
|
|
def test_wrong_key_should_respond_with_403_error
|
|
|
|
with_settings :sys_api_enabled => 'my_secret_key' do
|
|
|
|
get :projects, :key => 'wrong_key'
|
|
|
|
assert_response 403
|
|
|
|
end
|
|
|
|
end
|
2009-02-11 01:03:25 +03:00
|
|
|
end
|