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