Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@117
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'repositories_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class RepositoriesController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
|
Chris@0
|
26
|
Chris@0
|
27 # No '..' in the repository path
|
Chris@0
|
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
Chris@0
|
29
|
Chris@0
|
30 def setup
|
Chris@0
|
31 @controller = RepositoriesController.new
|
Chris@0
|
32 @request = ActionController::TestRequest.new
|
Chris@0
|
33 @response = ActionController::TestResponse.new
|
Chris@0
|
34 User.current = nil
|
Chris@0
|
35 Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
|
Chris@0
|
36 end
|
Chris@0
|
37
|
Chris@0
|
38 if File.directory?(REPOSITORY_PATH)
|
Chris@0
|
39 def test_show
|
Chris@0
|
40 get :show, :id => 3
|
Chris@0
|
41 assert_response :success
|
Chris@0
|
42 assert_template 'show'
|
Chris@0
|
43 assert_not_nil assigns(:entries)
|
Chris@0
|
44 assert_not_nil assigns(:changesets)
|
Chris@0
|
45 end
|
Chris@0
|
46
|
Chris@0
|
47 def test_show_root
|
Chris@0
|
48 get :show, :id => 3
|
Chris@0
|
49 assert_response :success
|
Chris@0
|
50 assert_template 'show'
|
Chris@0
|
51 assert_not_nil assigns(:entries)
|
Chris@117
|
52 assert_equal 4, assigns(:entries).size
|
Chris@117
|
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
Chris@0
|
54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
Chris@117
|
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
Chris@0
|
56 end
|
Chris@0
|
57
|
Chris@0
|
58 def test_show_directory
|
Chris@0
|
59 get :show, :id => 3, :path => ['images']
|
Chris@0
|
60 assert_response :success
|
Chris@0
|
61 assert_template 'show'
|
Chris@0
|
62 assert_not_nil assigns(:entries)
|
Chris@0
|
63 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
Chris@0
|
65 assert_not_nil entry
|
Chris@0
|
66 assert_equal 'file', entry.kind
|
Chris@0
|
67 assert_equal 'images/edit.png', entry.path
|
Chris@0
|
68 end
|
Chris@0
|
69
|
Chris@0
|
70 def test_show_at_given_revision
|
Chris@0
|
71 get :show, :id => 3, :path => ['images'], :rev => 0
|
Chris@0
|
72 assert_response :success
|
Chris@0
|
73 assert_template 'show'
|
Chris@0
|
74 assert_not_nil assigns(:entries)
|
Chris@0
|
75 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
76 end
|
Chris@117
|
77
|
Chris@117
|
78 def test_show_directory_sql_escape_percent
|
Chris@117
|
79 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => 13
|
Chris@117
|
80 assert_response :success
|
Chris@117
|
81 assert_template 'show'
|
Chris@117
|
82
|
Chris@117
|
83 assert_not_nil assigns(:entries)
|
Chris@117
|
84 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
|
Chris@117
|
85 changesets = assigns(:changesets)
|
Chris@117
|
86
|
Chris@117
|
87 ## This is not yet implemented.
|
Chris@117
|
88 # assert_not_nil changesets
|
Chris@117
|
89 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
|
Chris@117
|
90 end
|
Chris@117
|
91
|
Chris@0
|
92 def test_changes
|
Chris@0
|
93 get :changes, :id => 3, :path => ['images', 'edit.png']
|
Chris@0
|
94 assert_response :success
|
Chris@0
|
95 assert_template 'changes'
|
Chris@0
|
96 assert_tag :tag => 'h2', :content => 'edit.png'
|
Chris@0
|
97 end
|
Chris@0
|
98
|
Chris@0
|
99 def test_entry_show
|
Chris@0
|
100 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
Chris@0
|
101 assert_response :success
|
Chris@0
|
102 assert_template 'entry'
|
Chris@117
|
103 # Line 10
|
Chris@0
|
104 assert_tag :tag => 'th',
|
Chris@117
|
105 :content => '10',
|
Chris@117
|
106 :attributes => { :class => 'line-num' },
|
Chris@0
|
107 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
|
Chris@0
|
108 end
|
Chris@0
|
109
|
Chris@0
|
110 def test_entry_download
|
Chris@0
|
111 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
|
Chris@0
|
112 assert_response :success
|
Chris@0
|
113 # File content
|
Chris@0
|
114 assert @response.body.include?('WITHOUT ANY WARRANTY')
|
Chris@0
|
115 end
|
Chris@0
|
116
|
Chris@0
|
117 def test_directory_entry
|
Chris@0
|
118 get :entry, :id => 3, :path => ['sources']
|
Chris@0
|
119 assert_response :success
|
Chris@0
|
120 assert_template 'show'
|
Chris@0
|
121 assert_not_nil assigns(:entry)
|
Chris@0
|
122 assert_equal 'sources', assigns(:entry).name
|
Chris@0
|
123 end
|
Chris@0
|
124
|
Chris@0
|
125 def test_diff
|
Chris@0
|
126 # Full diff of changeset 4
|
Chris@0
|
127 get :diff, :id => 3, :rev => 4
|
Chris@0
|
128 assert_response :success
|
Chris@0
|
129 assert_template 'diff'
|
Chris@0
|
130 # Line 22 removed
|
Chris@0
|
131 assert_tag :tag => 'th',
|
Chris@117
|
132 :content => '22',
|
Chris@0
|
133 :sibling => { :tag => 'td',
|
Chris@0
|
134 :attributes => { :class => /diff_out/ },
|
Chris@0
|
135 :content => /def remove/ }
|
Chris@0
|
136 end
|
Chris@0
|
137
|
Chris@0
|
138 def test_annotate
|
Chris@0
|
139 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
|
Chris@0
|
140 assert_response :success
|
Chris@0
|
141 assert_template 'annotate'
|
Chris@117
|
142 # Line 23, revision 4:def6d2f1254a
|
Chris@117
|
143 assert_tag :tag => 'th',
|
Chris@117
|
144 :content => '23',
|
Chris@117
|
145 :attributes => { :class => 'line-num' },
|
Chris@117
|
146 :sibling =>
|
Chris@117
|
147 {
|
Chris@117
|
148 :tag => 'td',
|
Chris@117
|
149 :attributes => { :class => 'revision' },
|
Chris@117
|
150 :child => { :tag => 'a', :content => '4' }
|
Chris@117
|
151 # :child => { :tag => 'a', :content => /4:def6d2f1/ }
|
Chris@117
|
152 }
|
Chris@117
|
153 assert_tag :tag => 'th',
|
Chris@117
|
154 :content => '23',
|
Chris@117
|
155 :attributes => { :class => 'line-num' },
|
Chris@117
|
156 :sibling =>
|
Chris@117
|
157 {
|
Chris@117
|
158 :tag => 'td' ,
|
Chris@117
|
159 :content => 'jsmith' ,
|
Chris@117
|
160 :attributes => { :class => 'author' },
|
Chris@117
|
161 }
|
Chris@117
|
162 assert_tag :tag => 'th',
|
Chris@117
|
163 :content => '23',
|
Chris@117
|
164 :attributes => { :class => 'line-num' },
|
Chris@0
|
165 :sibling => { :tag => 'td', :content => /watcher =/ }
|
Chris@0
|
166 end
|
Chris@0
|
167 else
|
Chris@0
|
168 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
|
Chris@0
|
169 def test_fake; assert true end
|
Chris@0
|
170 end
|
Chris@0
|
171 end
|