comparison test/functional/.svn/text-base/repositories_mercurial_controller_test.rb.svn-base @ 119:8661b858af72

* Update to Redmine trunk rev 4705
author Chris Cannam
date Thu, 13 Jan 2011 14:12:06 +0000
parents 513646585e45
children cd2282d2aa55 07fa8a8b56a8
comparison
equal deleted inserted replaced
39:150ceac17a8d 119:8661b858af72
13 # 13 #
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.dirname(__FILE__) + '/../test_helper' 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller' 19 require 'repositories_controller'
20 20
21 # Re-raise errors caught by the controller. 21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
30 def setup 30 def setup
31 @controller = RepositoriesController.new 31 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new 32 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new 33 @response = ActionController::TestResponse.new
34 User.current = nil 34 User.current = nil
35 Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) 35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 assert @repository
36 end 37 end
37 38
38 if File.directory?(REPOSITORY_PATH) 39 if File.directory?(REPOSITORY_PATH)
39 def test_show 40 def test_show
40 get :show, :id => 3 41 get :show, :id => 3
41 assert_response :success 42 assert_response :success
42 assert_template 'show' 43 assert_template 'show'
47 def test_show_root 48 def test_show_root
48 get :show, :id => 3 49 get :show, :id => 3
49 assert_response :success 50 assert_response :success
50 assert_template 'show' 51 assert_template 'show'
51 assert_not_nil assigns(:entries) 52 assert_not_nil assigns(:entries)
52 assert_equal 3, assigns(:entries).size 53 assert_equal 4, assigns(:entries).size
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} 54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} 55 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} 56 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
56 end 57 end
57 58
58 def test_show_directory 59 def test_show_directory
59 get :show, :id => 3, :path => ['images'] 60 get :show, :id => 3, :path => ['images']
60 assert_response :success 61 assert_response :success
64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} 65 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
65 assert_not_nil entry 66 assert_not_nil entry
66 assert_equal 'file', entry.kind 67 assert_equal 'file', entry.kind
67 assert_equal 'images/edit.png', entry.path 68 assert_equal 'images/edit.png', entry.path
68 end 69 end
69 70
70 def test_show_at_given_revision 71 def test_show_at_given_revision
71 get :show, :id => 3, :path => ['images'], :rev => 0 72 [0, '0', '0885933ad4f6'].each do |r1|
72 assert_response :success 73 get :show, :id => 3, :path => ['images'], :rev => r1
73 assert_template 'show' 74 assert_response :success
74 assert_not_nil assigns(:entries) 75 assert_template 'show'
75 assert_equal ['delete.png'], assigns(:entries).collect(&:name) 76 assert_not_nil assigns(:entries)
76 end 77 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
77 78 end
79 end
80
81 def test_show_directory_sql_escape_percent
82 [13, '13', '3a330eb32958'].each do |r1|
83 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
84 assert_response :success
85 assert_template 'show'
86
87 assert_not_nil assigns(:entries)
88 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
89 changesets = assigns(:changesets)
90
91 ## This is not yet implemented.
92 # assert_not_nil changesets
93 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
94 end
95 end
96
78 def test_changes 97 def test_changes
79 get :changes, :id => 3, :path => ['images', 'edit.png'] 98 get :changes, :id => 3, :path => ['images', 'edit.png']
80 assert_response :success 99 assert_response :success
81 assert_template 'changes' 100 assert_template 'changes'
82 assert_tag :tag => 'h2', :content => 'edit.png' 101 assert_tag :tag => 'h2', :content => 'edit.png'
84 103
85 def test_entry_show 104 def test_entry_show
86 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] 105 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
87 assert_response :success 106 assert_response :success
88 assert_template 'entry' 107 assert_template 'entry'
89 # Line 19 108 # Line 10
90 assert_tag :tag => 'th', 109 assert_tag :tag => 'th',
91 :content => /10/, 110 :content => '10',
92 :attributes => { :class => /line-num/ }, 111 :attributes => { :class => 'line-num' },
93 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } 112 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
94 end 113 end
95 114
96 def test_entry_download 115 def test_entry_download
97 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' 116 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
107 assert_not_nil assigns(:entry) 126 assert_not_nil assigns(:entry)
108 assert_equal 'sources', assigns(:entry).name 127 assert_equal 'sources', assigns(:entry).name
109 end 128 end
110 129
111 def test_diff 130 def test_diff
112 # Full diff of changeset 4 131 @repository.fetch_changesets
113 get :diff, :id => 3, :rev => 4 132 @repository.reload
114 assert_response :success 133
115 assert_template 'diff' 134 [4, '4', 'def6d2f1254a'].each do |r1|
116 # Line 22 removed 135 # Full diff of changeset 4
117 assert_tag :tag => 'th', 136 get :diff, :id => 3, :rev => 4
118 :content => /22/, 137 assert_response :success
119 :sibling => { :tag => 'td', 138 assert_template 'diff'
120 :attributes => { :class => /diff_out/ }, 139
121 :content => /def remove/ } 140 if @repository.scm.class.client_version_above?([1, 2])
122 end 141 # Line 22 removed
123 142 assert_tag :tag => 'th',
143 :content => '22',
144 :sibling => { :tag => 'td',
145 :attributes => { :class => /diff_out/ },
146 :content => /def remove/ }
147 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
148 end
149 end
150 end
151
152 def test_diff_two_revs
153 @repository.fetch_changesets
154 @repository.reload
155
156 [2, '400bb8672109', '400', 400].each do |r1|
157 [4, 'def6d2f1254a'].each do |r2|
158 get :diff, :id => 3, :rev => r1,
159 :rev_to => r2
160 assert_response :success
161 assert_template 'diff'
162
163 diff = assigns(:diff)
164 assert_not_nil diff
165 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
166 end
167 end
168 end
169
124 def test_annotate 170 def test_annotate
125 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] 171 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
126 assert_response :success 172 assert_response :success
127 assert_template 'annotate' 173 assert_template 'annotate'
128 # Line 23, revision 4 174 # Line 23, revision 4:def6d2f1254a
129 assert_tag :tag => 'th', :content => /23/, 175 assert_tag :tag => 'th',
130 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /4/ } }, 176 :content => '23',
131 :sibling => { :tag => 'td', :content => /jsmith/ }, 177 :attributes => { :class => 'line-num' },
178 :sibling =>
179 {
180 :tag => 'td',
181 :attributes => { :class => 'revision' },
182 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
183 }
184 assert_tag :tag => 'th',
185 :content => '23',
186 :attributes => { :class => 'line-num' },
187 :sibling =>
188 {
189 :tag => 'td' ,
190 :content => 'jsmith' ,
191 :attributes => { :class => 'author' },
192 }
193 assert_tag :tag => 'th',
194 :content => '23',
195 :attributes => { :class => 'line-num' },
132 :sibling => { :tag => 'td', :content => /watcher =/ } 196 :sibling => { :tag => 'td', :content => /watcher =/ }
197 end
198
199 def test_empty_revision
200 @repository.fetch_changesets
201 @repository.reload
202 ['', ' ', nil].each do |r|
203 get :revision, :id => 1, :rev => r
204 assert_response 500
205 assert_error_tag :content => /was not found/
206 end
133 end 207 end
134 else 208 else
135 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" 209 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
136 def test_fake; assert true end 210 def test_fake; assert true end
137 end 211 end