@@ -1,223 +1,224 | |||
|
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 RepositoriesMercurialControllerTest < 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/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 = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) |
|
36 | 36 | assert @repository |
|
37 | @diff_c_support = @repository.scm.class.client_version_above?([1, 2]) | |
|
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_show_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 4, 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 == 'sources' && e.kind == 'dir'} |
|
56 | 57 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
57 | 58 | end |
|
58 | 59 | |
|
59 | 60 | def test_show_directory |
|
60 | 61 | get :show, :id => 3, :path => ['images'] |
|
61 | 62 | assert_response :success |
|
62 | 63 | assert_template 'show' |
|
63 | 64 | assert_not_nil assigns(:entries) |
|
64 | 65 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
65 | 66 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
66 | 67 | assert_not_nil entry |
|
67 | 68 | assert_equal 'file', entry.kind |
|
68 | 69 | assert_equal 'images/edit.png', entry.path |
|
69 | 70 | end |
|
70 | 71 | |
|
71 | 72 | def test_show_at_given_revision |
|
72 | 73 | [0, '0', '0885933ad4f6'].each do |r1| |
|
73 | 74 | get :show, :id => 3, :path => ['images'], :rev => r1 |
|
74 | 75 | assert_response :success |
|
75 | 76 | assert_template 'show' |
|
76 | 77 | assert_not_nil assigns(:entries) |
|
77 | 78 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
78 | 79 | end |
|
79 | 80 | end |
|
80 | 81 | |
|
81 | 82 | def test_show_directory_sql_escape_percent |
|
82 | 83 | [13, '13', '3a330eb32958'].each do |r1| |
|
83 | 84 | get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 |
|
84 | 85 | assert_response :success |
|
85 | 86 | assert_template 'show' |
|
86 | 87 | |
|
87 | 88 | assert_not_nil assigns(:entries) |
|
88 | 89 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) |
|
89 | 90 | changesets = assigns(:changesets) |
|
90 | 91 | |
|
91 | 92 | ## This is not yet implemented. |
|
92 | 93 | # assert_not_nil changesets |
|
93 | 94 | # assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
94 | 95 | end |
|
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 10 |
|
109 | 110 | assert_tag :tag => 'th', |
|
110 | 111 | :content => '10', |
|
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 |
|
131 | 132 | @repository.fetch_changesets |
|
132 | 133 | @repository.reload |
|
133 | 134 | |
|
134 | 135 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
135 | 136 | # Full diff of changeset 4 |
|
136 | 137 | get :diff, :id => 3, :rev => r1 |
|
137 | 138 | assert_response :success |
|
138 | 139 | assert_template 'diff' |
|
139 | 140 | |
|
140 | if @repository.scm.class.client_version_above?([1, 2]) | |
|
141 | if @diff_c_support | |
|
141 | 142 | # Line 22 removed |
|
142 | 143 | assert_tag :tag => 'th', |
|
143 | 144 | :content => '22', |
|
144 | 145 | :sibling => { :tag => 'td', |
|
145 | 146 | :attributes => { :class => /diff_out/ }, |
|
146 | 147 | :content => /def remove/ } |
|
147 | 148 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
148 | 149 | end |
|
149 | 150 | end |
|
150 | 151 | end |
|
151 | 152 | |
|
152 | 153 | def test_diff_two_revs |
|
153 | 154 | @repository.fetch_changesets |
|
154 | 155 | @repository.reload |
|
155 | 156 | |
|
156 | 157 | [2, '400bb8672109', '400', 400].each do |r1| |
|
157 | 158 | [4, 'def6d2f1254a'].each do |r2| |
|
158 | 159 | get :diff, :id => 3, :rev => r1, |
|
159 | 160 | :rev_to => r2 |
|
160 | 161 | assert_response :success |
|
161 | 162 | assert_template 'diff' |
|
162 | 163 | |
|
163 | 164 | diff = assigns(:diff) |
|
164 | 165 | assert_not_nil diff |
|
165 | 166 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ |
|
166 | 167 | end |
|
167 | 168 | end |
|
168 | 169 | end |
|
169 | 170 | |
|
170 | 171 | def test_annotate |
|
171 | 172 | get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] |
|
172 | 173 | assert_response :success |
|
173 | 174 | assert_template 'annotate' |
|
174 | 175 | # Line 23, revision 4:def6d2f1254a |
|
175 | 176 | assert_tag :tag => 'th', |
|
176 | 177 | :content => '23', |
|
177 | 178 | :attributes => { :class => 'line-num' }, |
|
178 | 179 | :sibling => |
|
179 | 180 | { |
|
180 | 181 | :tag => 'td', |
|
181 | 182 | :attributes => { :class => 'revision' }, |
|
182 | 183 | :child => { :tag => 'a', :content => '4:def6d2f1254a' } |
|
183 | 184 | } |
|
184 | 185 | assert_tag :tag => 'th', |
|
185 | 186 | :content => '23', |
|
186 | 187 | :attributes => { :class => 'line-num' }, |
|
187 | 188 | :sibling => |
|
188 | 189 | { |
|
189 | 190 | :tag => 'td' , |
|
190 | 191 | :content => 'jsmith' , |
|
191 | 192 | :attributes => { :class => 'author' }, |
|
192 | 193 | } |
|
193 | 194 | assert_tag :tag => 'th', |
|
194 | 195 | :content => '23', |
|
195 | 196 | :attributes => { :class => 'line-num' }, |
|
196 | 197 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
197 | 198 | end |
|
198 | 199 | |
|
199 | 200 | def test_annotate_at_given_revision |
|
200 | 201 | @repository.fetch_changesets |
|
201 | 202 | @repository.reload |
|
202 | 203 | [2, '400bb8672109', '400', 400].each do |r1| |
|
203 | 204 | get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb'] |
|
204 | 205 | assert_response :success |
|
205 | 206 | assert_template 'annotate' |
|
206 | 207 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
207 | 208 | end |
|
208 | 209 | end |
|
209 | 210 | |
|
210 | 211 | def test_empty_revision |
|
211 | 212 | @repository.fetch_changesets |
|
212 | 213 | @repository.reload |
|
213 | 214 | ['', ' ', nil].each do |r| |
|
214 | 215 | get :revision, :id => 3, :rev => r |
|
215 | 216 | assert_response 404 |
|
216 | 217 | assert_error_tag :content => /was not found/ |
|
217 | 218 | end |
|
218 | 219 | end |
|
219 | 220 | else |
|
220 | 221 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
221 | 222 | def test_fake; assert true end |
|
222 | 223 | end |
|
223 | 224 | end |
@@ -1,191 +1,192 | |||
|
1 | 1 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
2 | 2 | begin |
|
3 | 3 | require 'mocha' |
|
4 | 4 | |
|
5 | 5 | class MercurialAdapterTest < ActiveSupport::TestCase |
|
6 | 6 | |
|
7 | 7 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR |
|
8 | 8 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME |
|
9 | 9 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
|
10 | 10 | |
|
11 | 11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
|
12 | 12 | |
|
13 | 13 | if File.directory?(REPOSITORY_PATH) |
|
14 | 14 | def setup |
|
15 | 15 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) |
|
16 | @diff_c_support = @adapter.class.client_version_above?([1, 2]) | |
|
16 | 17 | end |
|
17 | 18 | |
|
18 | 19 | def test_hgversion |
|
19 | 20 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
20 | 21 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
21 | 22 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
22 | 23 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
23 | 24 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
24 | 25 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
25 | 26 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
26 | 27 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
27 | 28 | |
|
28 | 29 | to_test.each do |s, v| |
|
29 | 30 | test_hgversion_for(s, v) |
|
30 | 31 | end |
|
31 | 32 | end |
|
32 | 33 | |
|
33 | 34 | def test_template_path |
|
34 | 35 | to_test = { [0,9,5] => "0.9.5", |
|
35 | 36 | [1,0] => "1.0", |
|
36 | 37 | [] => "1.0", |
|
37 | 38 | [1,0,1] => "1.0", |
|
38 | 39 | [1,7] => "1.0", |
|
39 | 40 | [1,7,1] => "1.0" } |
|
40 | 41 | to_test.each do |v, template| |
|
41 | 42 | test_template_path_for(v, template) |
|
42 | 43 | end |
|
43 | 44 | end |
|
44 | 45 | |
|
45 | 46 | def test_info |
|
46 | 47 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
47 | 48 | REPOSITORY_PATH + "//"].each do |repo| |
|
48 | 49 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
49 | 50 | assert_equal REPOSITORY_PATH, adp.info.root_url |
|
50 | 51 | assert_equal '16', adp.info.lastrev.revision |
|
51 | 52 | assert_equal '4cddb4e45f52',adp.info.lastrev.scmid |
|
52 | 53 | end |
|
53 | 54 | end |
|
54 | 55 | |
|
55 | 56 | def test_revisions |
|
56 | 57 | revisions = @adapter.revisions(nil, 2, 4) |
|
57 | 58 | assert_equal 3, revisions.size |
|
58 | 59 | assert_equal '2', revisions[0].revision |
|
59 | 60 | assert_equal '400bb8672109', revisions[0].scmid |
|
60 | 61 | assert_equal '4', revisions[2].revision |
|
61 | 62 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
62 | 63 | |
|
63 | 64 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
64 | 65 | assert_equal 2, revisions.size |
|
65 | 66 | assert_equal '2', revisions[0].revision |
|
66 | 67 | assert_equal '400bb8672109', revisions[0].scmid |
|
67 | 68 | end |
|
68 | 69 | |
|
69 | 70 | def test_diff |
|
70 | 71 | if @adapter.class.client_version_above?([1, 2]) |
|
71 | 72 | assert_nil @adapter.diff(nil, '100000') |
|
72 | 73 | end |
|
73 | 74 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
74 | 75 | [2, '400bb8672109', '400', 400].each do |r1| |
|
75 | 76 | diff1 = @adapter.diff(nil, r1) |
|
76 | if @adapter.class.client_version_above?([1, 2]) | |
|
77 | if @diff_c_support | |
|
77 | 78 | assert_equal 28, diff1.size |
|
78 | 79 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
79 | 80 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
80 | 81 | else |
|
81 | 82 | assert_equal 0, diff1.size |
|
82 | 83 | end |
|
83 | 84 | [4, 'def6d2f1254a'].each do |r2| |
|
84 | 85 | diff2 = @adapter.diff(nil,r1,r2) |
|
85 | 86 | assert_equal 49, diff2.size |
|
86 | 87 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
87 | 88 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
88 | 89 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
89 | 90 | assert_equal 20, diff3.size |
|
90 | 91 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
91 | 92 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
92 | 93 | end |
|
93 | 94 | end |
|
94 | 95 | end |
|
95 | 96 | |
|
96 | 97 | def test_diff_made_by_revision |
|
97 | if @adapter.class.client_version_above?([1, 2]) | |
|
98 | if @diff_c_support | |
|
98 | 99 | [16, '16', '4cddb4e45f52'].each do |r1| |
|
99 | 100 | diff1 = @adapter.diff(nil, r1) |
|
100 | 101 | assert_equal 5, diff1.size |
|
101 | 102 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
102 | 103 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
103 | 104 | end |
|
104 | 105 | end |
|
105 | 106 | end |
|
106 | 107 | |
|
107 | 108 | def test_cat |
|
108 | 109 | [2, '400bb8672109', '400', 400].each do |r| |
|
109 | 110 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
110 | 111 | assert buf |
|
111 | 112 | lines = buf.split("\r\n") |
|
112 | 113 | assert_equal 25, lines.length |
|
113 | 114 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
114 | 115 | end |
|
115 | 116 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
116 | 117 | end |
|
117 | 118 | |
|
118 | 119 | def test_annotate |
|
119 | 120 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
120 | 121 | [2, '400bb8672109', '400', 400].each do |r| |
|
121 | 122 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
122 | 123 | assert ann |
|
123 | 124 | assert_equal '1', ann.revisions[17].revision |
|
124 | 125 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
125 | 126 | assert_equal 'jsmith', ann.revisions[0].author |
|
126 | 127 | assert_equal 25, ann.lines.length |
|
127 | 128 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
128 | 129 | end |
|
129 | 130 | end |
|
130 | 131 | |
|
131 | 132 | # TODO filesize etc. |
|
132 | 133 | def test_entries |
|
133 | 134 | assert_nil @adapter.entries(nil, '100000') |
|
134 | 135 | [2, '400bb8672109', '400', 400].each do |r| |
|
135 | 136 | entries1 = @adapter.entries(nil, r) |
|
136 | 137 | assert entries1 |
|
137 | 138 | assert_equal 3, entries1.size |
|
138 | 139 | assert_equal 'sources', entries1[1].name |
|
139 | 140 | assert_equal 'sources', entries1[1].path |
|
140 | 141 | assert_equal 'dir', entries1[1].kind |
|
141 | 142 | assert_equal 'README', entries1[2].name |
|
142 | 143 | assert_equal 'README', entries1[2].path |
|
143 | 144 | assert_equal 'file', entries1[2].kind |
|
144 | 145 | |
|
145 | 146 | entries2 = @adapter.entries('sources', r) |
|
146 | 147 | assert entries2 |
|
147 | 148 | assert_equal 2, entries2.size |
|
148 | 149 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
149 | 150 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
150 | 151 | assert_equal 'file', entries2[0].kind |
|
151 | 152 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
152 | 153 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
153 | 154 | assert_equal 'file', entries2[1].kind |
|
154 | 155 | end |
|
155 | 156 | end |
|
156 | 157 | |
|
157 | 158 | def test_access_by_nodeid |
|
158 | 159 | path = 'sources/welcome_controller.rb' |
|
159 | 160 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
160 | 161 | end |
|
161 | 162 | |
|
162 | 163 | def test_access_by_fuzzy_nodeid |
|
163 | 164 | path = 'sources/welcome_controller.rb' |
|
164 | 165 | # falls back to nodeid |
|
165 | 166 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
166 | 167 | end |
|
167 | 168 | |
|
168 | 169 | private |
|
169 | 170 | |
|
170 | 171 | def test_hgversion_for(hgversion, version) |
|
171 | 172 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
172 | 173 | assert_equal version, @adapter.class.hgversion |
|
173 | 174 | end |
|
174 | 175 | |
|
175 | 176 | def test_template_path_for(version, template) |
|
176 | 177 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
177 | 178 | @adapter.class.template_path_for(version) |
|
178 | 179 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
179 | 180 | end |
|
180 | 181 | else |
|
181 | 182 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
182 | 183 | def test_fake; assert true end |
|
183 | 184 | end |
|
184 | 185 | end |
|
185 | 186 | |
|
186 | 187 | rescue LoadError |
|
187 | 188 | class MercurialMochaFake < ActiveSupport::TestCase |
|
188 | 189 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
189 | 190 | end |
|
190 | 191 | end |
|
191 | 192 |
General Comments 0
You need to be logged in to leave comments.
Login now