To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / functional / .svn / text-base / sys_controller_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (3.1 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 441:cbce1fd3b1b7 Chris
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 119:8661b858af72 Chris
require File.expand_path('../../test_helper', __FILE__)
19 0:513646585e45 Chris
require 'sys_controller'
20 441:cbce1fd3b1b7 Chris
require 'mocha'
21 0:513646585e45 Chris
22
# Re-raise errors caught by the controller.
23
class SysController; def rescue_action(e) raise e end; end
24
25
class SysControllerTest < ActionController::TestCase
26 441:cbce1fd3b1b7 Chris
  fixtures :projects, :repositories, :enabled_modules
27 0:513646585e45 Chris
28
  def setup
29
    @controller = SysController.new
30
    @request    = ActionController::TestRequest.new
31
    @response   = ActionController::TestResponse.new
32
    Setting.sys_api_enabled = '1'
33
    Setting.enabled_scm = %w(Subversion Git)
34
  end
35
36
  def test_projects_with_repository_enabled
37
    get :projects
38
    assert_response :success
39
    assert_equal 'application/xml', @response.content_type
40
    with_options :tag => 'projects' do |test|
41
      test.assert_tag :children => { :count  => Project.active.has_module(:repository).count }
42
    end
43
  end
44
45
  def test_create_project_repository
46
    assert_nil Project.find(4).repository
47
48
    post :create_project_repository, :id => 4,
49
                                     :vendor => 'Subversion',
50
                                     :repository => { :url => 'file:///create/project/repository/subproject2'}
51
    assert_response :created
52
53
    r = Project.find(4).repository
54
    assert r.is_a?(Repository::Subversion)
55
    assert_equal 'file:///create/project/repository/subproject2', r.url
56
  end
57
58
  def test_fetch_changesets
59 441:cbce1fd3b1b7 Chris
    Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
60 0:513646585e45 Chris
    get :fetch_changesets
61
    assert_response :success
62
  end
63
64
  def test_fetch_changesets_one_project
65 441:cbce1fd3b1b7 Chris
    Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
66 0:513646585e45 Chris
    get :fetch_changesets, :id => 'ecookbook'
67
    assert_response :success
68
  end
69
70
  def test_fetch_changesets_unknown_project
71
    get :fetch_changesets, :id => 'unknown'
72
    assert_response 404
73
  end
74
75
  def test_disabled_ws_should_respond_with_403_error
76
    with_settings :sys_api_enabled => '0' do
77
      get :projects
78
      assert_response 403
79
    end
80
  end
81
82
  def test_api_key
83
    with_settings :sys_api_key => 'my_secret_key' do
84
      get :projects, :key => 'my_secret_key'
85
      assert_response :success
86
    end
87
  end
88
89
  def test_wrong_key_should_respond_with_403_error
90
    with_settings :sys_api_enabled => 'my_secret_key' do
91
      get :projects, :key => 'wrong_key'
92
      assert_response 403
93
    end
94
  end
95
end