##// END OF EJS Templates
scm: add compatible functional test fof changing diff revisions label at SCM adapter level....
Toshi MARUYAMA -
r4545:e4f72a8e3afb
parent child
Show More
@@ -1,164 +1,183
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 '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 RepositoriesGitControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30
31 31 def setup
32 32 @controller = RepositoriesController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 User.current = nil
36 Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 @repository = Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
37 assert @repository
37 38 end
38
39
39 40 if File.directory?(REPOSITORY_PATH)
40 41 def test_show
41 42 get :show, :id => 3
42 43 assert_response :success
43 44 assert_template 'show'
44 45 assert_not_nil assigns(:entries)
45 46 assert_not_nil assigns(:changesets)
46 47 end
47 48
48 49 def test_browse_root
49 50 get :show, :id => 3
50 51 assert_response :success
51 52 assert_template 'show'
52 53 assert_not_nil assigns(:entries)
53 54 assert_equal 9, assigns(:entries).size
54 55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 56 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
56 57 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
57 58 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
58 59 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
59 60 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
60 61 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
61 62 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
62 63 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
63 64 end
64 65
65 66 def test_browse_branch
66 67 get :show, :id => 3, :rev => 'test_branch'
67 68 assert_response :success
68 69 assert_template 'show'
69 70 assert_not_nil assigns(:entries)
70 71 assert_equal 4, assigns(:entries).size
71 72 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
72 73 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
73 74 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
74 75 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
75 76 end
76 77
77 78 def test_browse_directory
78 79 get :show, :id => 3, :path => ['images']
79 80 assert_response :success
80 81 assert_template 'show'
81 82 assert_not_nil assigns(:entries)
82 83 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
83 84 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
84 85 assert_not_nil entry
85 86 assert_equal 'file', entry.kind
86 87 assert_equal 'images/edit.png', entry.path
87 88 end
88 89
89 90 def test_browse_at_given_revision
90 91 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
91 92 assert_response :success
92 93 assert_template 'show'
93 94 assert_not_nil assigns(:entries)
94 95 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
95 96 end
96 97
97 98 def test_changes
98 99 get :changes, :id => 3, :path => ['images', 'edit.png']
99 100 assert_response :success
100 101 assert_template 'changes'
101 102 assert_tag :tag => 'h2', :content => 'edit.png'
102 103 end
103 104
104 105 def test_entry_show
105 106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
106 107 assert_response :success
107 108 assert_template 'entry'
108 109 # Line 19
109 110 assert_tag :tag => 'th',
110 111 :content => /11/,
111 112 :attributes => { :class => /line-num/ },
112 113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
113 114 end
114 115
115 116 def test_entry_download
116 117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
117 118 assert_response :success
118 119 # File content
119 120 assert @response.body.include?('WITHOUT ANY WARRANTY')
120 121 end
121 122
122 123 def test_directory_entry
123 124 get :entry, :id => 3, :path => ['sources']
124 125 assert_response :success
125 126 assert_template 'show'
126 127 assert_not_nil assigns(:entry)
127 128 assert_equal 'sources', assigns(:entry).name
128 129 end
129
130
130 131 def test_diff
132 @repository.fetch_changesets
133 @repository.reload
134
131 135 # Full diff of changeset 2f9c0091
132 136 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
133 137 assert_response :success
134 138 assert_template 'diff'
135 139 # Line 22 removed
136 140 assert_tag :tag => 'th',
137 141 :content => /22/,
138 142 :sibling => { :tag => 'td',
139 143 :attributes => { :class => /diff_out/ },
140 144 :content => /def remove/ }
145 assert_tag :tag => 'h2', :content => /2f9c0091/
146 end
147
148 def test_diff_two_revs
149 @repository.fetch_changesets
150 @repository.reload
151
152 get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
153 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
154 assert_response :success
155 assert_template 'diff'
156
157 diff = assigns(:diff)
158 assert_not_nil diff
159 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
141 160 end
142 161
143 162 def test_annotate
144 163 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
145 164 assert_response :success
146 165 assert_template 'annotate'
147 166 # Line 23, changeset 2f9c0091
148 167 assert_tag :tag => 'th', :content => /24/,
149 168 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
150 169 :sibling => { :tag => 'td', :content => /jsmith/ },
151 170 :sibling => { :tag => 'td', :content => /watcher =/ }
152 171 end
153
172
154 173 def test_annotate_binary_file
155 174 get :annotate, :id => 3, :path => ['images', 'edit.png']
156 175 assert_response 500
157 176 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
158 177 :content => /can not be annotated/
159 178 end
160 179 else
161 180 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
162 181 def test_fake; assert true end
163 182 end
164 183 end
@@ -1,223 +1,227
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 '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 RepositoriesSubversionControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 26 :repositories, :issues, :issue_statuses, :changesets, :changes,
27 27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
28 28
29 29 def setup
30 30 @controller = RepositoriesController.new
31 31 @request = ActionController::TestRequest.new
32 32 @response = ActionController::TestResponse.new
33 33 Setting.default_language = 'en'
34 34 User.current = nil
35 35 end
36 36
37 37 if repository_configured?('subversion')
38 38 def test_show
39 39 get :show, :id => 1
40 40 assert_response :success
41 41 assert_template 'show'
42 42 assert_not_nil assigns(:entries)
43 43 assert_not_nil assigns(:changesets)
44 44 end
45 45
46 46 def test_browse_root
47 47 get :show, :id => 1
48 48 assert_response :success
49 49 assert_template 'show'
50 50 assert_not_nil assigns(:entries)
51 51 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
52 52 assert_equal 'dir', entry.kind
53 53 end
54 54
55 55 def test_browse_directory
56 56 get :show, :id => 1, :path => ['subversion_test']
57 57 assert_response :success
58 58 assert_template 'show'
59 59 assert_not_nil assigns(:entries)
60 60 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
61 61 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
62 62 assert_equal 'file', entry.kind
63 63 assert_equal 'subversion_test/helloworld.c', entry.path
64 64 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
65 65 end
66 66
67 67 def test_browse_at_given_revision
68 68 get :show, :id => 1, :path => ['subversion_test'], :rev => 4
69 69 assert_response :success
70 70 assert_template 'show'
71 71 assert_not_nil assigns(:entries)
72 72 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
73 73 end
74 74
75 75 def test_file_changes
76 76 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
77 77 assert_response :success
78 78 assert_template 'changes'
79 79
80 80 changesets = assigns(:changesets)
81 81 assert_not_nil changesets
82 82 assert_equal %w(6 3 2), changesets.collect(&:revision)
83 83
84 84 # svn properties displayed with svn >= 1.5 only
85 85 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
86 86 assert_not_nil assigns(:properties)
87 87 assert_equal 'native', assigns(:properties)['svn:eol-style']
88 88 assert_tag :ul,
89 89 :child => { :tag => 'li',
90 90 :child => { :tag => 'b', :content => 'svn:eol-style' },
91 91 :child => { :tag => 'span', :content => 'native' } }
92 92 end
93 93 end
94 94
95 95 def test_directory_changes
96 96 get :changes, :id => 1, :path => ['subversion_test', 'folder' ]
97 97 assert_response :success
98 98 assert_template 'changes'
99 99
100 100 changesets = assigns(:changesets)
101 101 assert_not_nil changesets
102 102 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
103 103 end
104 104
105 105 def test_entry
106 106 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
107 107 assert_response :success
108 108 assert_template 'entry'
109 109 end
110 110
111 111 def test_entry_should_send_if_too_big
112 112 # no files in the test repo is larger than 1KB...
113 113 with_settings :file_max_size_displayed => 0 do
114 114 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
115 115 assert_response :success
116 116 assert_template ''
117 117 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
118 118 end
119 119 end
120 120
121 121 def test_entry_at_given_revision
122 122 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
123 123 assert_response :success
124 124 assert_template 'entry'
125 125 # this line was removed in r3 and file was moved in r6
126 126 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
127 127 :content => /Here's the code/
128 128 end
129 129
130 130 def test_entry_not_found
131 131 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
132 132 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
133 133 :content => /The entry or revision was not found in the repository/
134 134 end
135 135
136 136 def test_entry_download
137 137 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
138 138 assert_response :success
139 139 assert_template ''
140 140 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
141 141 end
142 142
143 143 def test_directory_entry
144 144 get :entry, :id => 1, :path => ['subversion_test', 'folder']
145 145 assert_response :success
146 146 assert_template 'show'
147 147 assert_not_nil assigns(:entry)
148 148 assert_equal 'folder', assigns(:entry).name
149 149 end
150 150
151 151 def test_revision
152 152 get :revision, :id => 1, :rev => 2
153 153 assert_response :success
154 154 assert_template 'revision'
155 155 assert_tag :tag => 'ul',
156 156 :child => { :tag => 'li',
157 157 # link to the entry at rev 2
158 158 :child => { :tag => 'a',
159 159 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
160 160 :content => 'repo',
161 161 # link to partial diff
162 162 :sibling => { :tag => 'a',
163 163 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
164 164 }
165 165 }
166 166 }
167 167 end
168 168
169 169 def test_invalid_revision
170 170 get :revision, :id => 1, :rev => 'something_weird'
171 171 assert_response 500
172 172 assert_error_tag :content => /was not found/
173 173 end
174 174
175 175 def test_revision_with_repository_pointing_to_a_subdirectory
176 176 r = Project.find(1).repository
177 177 # Changes repository url to a subdirectory
178 178 r.update_attribute :url, (r.url + '/test/some')
179 179
180 180 get :revision, :id => 1, :rev => 2
181 181 assert_response :success
182 182 assert_template 'revision'
183 183 assert_tag :tag => 'ul',
184 184 :child => { :tag => 'li',
185 185 # link to the entry at rev 2
186 186 :child => { :tag => 'a',
187 187 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
188 188 :content => 'repo',
189 189 # link to partial diff
190 190 :sibling => { :tag => 'a',
191 191 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
192 192 }
193 193 }
194 194 }
195 195 end
196 196
197 197 def test_revision_diff
198 198 get :diff, :id => 1, :rev => 3
199 199 assert_response :success
200 200 assert_template 'diff'
201
202 assert_tag :tag => 'h2', :content => /3/
201 203 end
202 204
203 205 def test_directory_diff
204 206 get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
205 207 assert_response :success
206 208 assert_template 'diff'
207 209
208 210 diff = assigns(:diff)
209 211 assert_not_nil diff
210 212 # 2 files modified
211 213 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
214
215 assert_tag :tag => 'h2', :content => /2:6/
212 216 end
213 217
214 218 def test_annotate
215 219 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
216 220 assert_response :success
217 221 assert_template 'annotate'
218 222 end
219 223 else
220 224 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
221 225 def test_fake; assert true end
222 226 end
223 227 end
General Comments 0
You need to be logged in to leave comments. Login now