@@ -1,117 +1,122 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'repositories_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class RepositoriesController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class RepositoriesMercurialControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules |
|
26 | 26 | |
|
27 | 27 | # No '..' in the repository path |
|
28 | 28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
29 | 29 | |
|
30 | 30 | def setup |
|
31 | 31 | @controller = RepositoriesController.new |
|
32 | 32 | @request = ActionController::TestRequest.new |
|
33 | 33 | @response = ActionController::TestResponse.new |
|
34 | 34 | User.current = nil |
|
35 | 35 | Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | if File.directory?(REPOSITORY_PATH) | |
|
38 | 39 | def test_show |
|
39 | 40 | get :show, :id => 3 |
|
40 | 41 | assert_response :success |
|
41 | 42 | assert_template 'show' |
|
42 | 43 | assert_not_nil assigns(:entries) |
|
43 | 44 | assert_not_nil assigns(:changesets) |
|
44 | 45 | end |
|
45 | 46 | |
|
46 | 47 | def test_browse_root |
|
47 | 48 | get :browse, :id => 3 |
|
48 | 49 | assert_response :success |
|
49 | 50 | assert_template 'browse' |
|
50 | 51 | assert_not_nil assigns(:entries) |
|
51 | 52 | assert_equal 3, assigns(:entries).size |
|
52 | 53 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
53 | 54 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
54 | 55 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
55 | 56 | end |
|
56 | 57 | |
|
57 | 58 | def test_browse_directory |
|
58 | 59 | get :browse, :id => 3, :path => ['images'] |
|
59 | 60 | assert_response :success |
|
60 | 61 | assert_template 'browse' |
|
61 | 62 | assert_not_nil assigns(:entries) |
|
62 | 63 | assert_equal 2, assigns(:entries).size |
|
63 | 64 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
64 | 65 | assert_not_nil entry |
|
65 | 66 | assert_equal 'file', entry.kind |
|
66 | 67 | assert_equal 'images/edit.png', entry.path |
|
67 | 68 | end |
|
68 | 69 | |
|
69 | 70 | def test_changes |
|
70 | 71 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
71 | 72 | assert_response :success |
|
72 | 73 | assert_template 'changes' |
|
73 | 74 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
74 | 75 | end |
|
75 | 76 | |
|
76 | 77 | def test_entry_show |
|
77 | 78 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
78 | 79 | assert_response :success |
|
79 | 80 | assert_template 'entry' |
|
80 | 81 | # Line 19 |
|
81 | 82 | assert_tag :tag => 'th', |
|
82 | 83 | :content => /10/, |
|
83 | 84 | :attributes => { :class => /line-num/ }, |
|
84 | 85 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
85 | 86 | end |
|
86 | 87 | |
|
87 | 88 | def test_entry_download |
|
88 | 89 | get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' |
|
89 | 90 | assert_response :success |
|
90 | 91 | # File content |
|
91 | 92 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
92 | 93 | end |
|
93 | 94 | |
|
94 | 95 | def test_diff |
|
95 | 96 | # Full diff of changeset 4 |
|
96 | 97 | get :diff, :id => 3, :rev => 4 |
|
97 | 98 | assert_response :success |
|
98 | 99 | assert_template 'diff' |
|
99 | 100 | # Line 22 removed |
|
100 | 101 | assert_tag :tag => 'th', |
|
101 | 102 | :content => /22/, |
|
102 | 103 | :sibling => { :tag => 'td', |
|
103 | 104 | :attributes => { :class => /diff_out/ }, |
|
104 | 105 | :content => /def remove/ } |
|
105 | 106 | end |
|
106 | 107 | |
|
107 | 108 | def test_annotate |
|
108 | 109 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
109 | 110 | assert_response :success |
|
110 | 111 | assert_template 'annotate' |
|
111 | 112 | # Line 23, revision 4 |
|
112 | 113 | assert_tag :tag => 'th', :content => /23/, |
|
113 | 114 | :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /4/ } }, |
|
114 | 115 | :sibling => { :tag => 'td', :content => /jsmith/ }, |
|
115 | 116 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
116 | 117 | end |
|
118 | else | |
|
119 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" | |
|
120 | def test_fake; assert true end | |
|
121 | end | |
|
117 | 122 | end |
General Comments 0
You need to be logged in to leave comments.
Login now