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 / .svn / pristine / 46 / 46d08e5d685f85ea6b371254e247586c06beb87e.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (3.52 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
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
require File.expand_path('../../test_helper', __FILE__)
19
require 'sys_controller'
20
require 'mocha'
21

    
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
  fixtures :projects, :repositories, :enabled_modules
27

    
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
      test.assert_tag 'project', :child => {:tag => 'identifier', :sibling => {:tag => 'is-public'}}
43
    end
44
    assert_no_tag 'extra-info'
45
    assert_no_tag 'extra_info'
46
  end
47

    
48
  def test_create_project_repository
49
    assert_nil Project.find(4).repository
50

    
51
    post :create_project_repository, :id => 4,
52
                                     :vendor => 'Subversion',
53
                                     :repository => { :url => 'file:///create/project/repository/subproject2'}
54
    assert_response :created
55
    assert_equal 'application/xml', @response.content_type
56

    
57
    r = Project.find(4).repository
58
    assert r.is_a?(Repository::Subversion)
59
    assert_equal 'file:///create/project/repository/subproject2', r.url
60
    
61
    assert_tag 'repository-subversion',
62
      :child => {
63
        :tag => 'id', :content => r.id.to_s,
64
        :sibling => {:tag => 'url', :content => r.url}
65
      }
66
    assert_no_tag 'extra-info'
67
    assert_no_tag 'extra_info'
68
  end
69

    
70
  def test_fetch_changesets
71
    Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
72
    get :fetch_changesets
73
    assert_response :success
74
  end
75

    
76
  def test_fetch_changesets_one_project
77
    Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true)
78
    get :fetch_changesets, :id => 'ecookbook'
79
    assert_response :success
80
  end
81

    
82
  def test_fetch_changesets_unknown_project
83
    get :fetch_changesets, :id => 'unknown'
84
    assert_response 404
85
  end
86

    
87
  def test_disabled_ws_should_respond_with_403_error
88
    with_settings :sys_api_enabled => '0' do
89
      get :projects
90
      assert_response 403
91
    end
92
  end
93

    
94
  def test_api_key
95
    with_settings :sys_api_key => 'my_secret_key' do
96
      get :projects, :key => 'my_secret_key'
97
      assert_response :success
98
    end
99
  end
100

    
101
  def test_wrong_key_should_respond_with_403_error
102
    with_settings :sys_api_enabled => 'my_secret_key' do
103
      get :projects, :key => 'wrong_key'
104
      assert_response 403
105
    end
106
  end
107
end