@@ -1,216 +1,230 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | # This file includes UTF-8 "Felix Schäfer". |
|
4 | 4 | # We need to consider Ruby 1.9 compatibility. |
|
5 | 5 | |
|
6 | 6 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
7 | 7 | begin |
|
8 | 8 | require 'mocha' |
|
9 | 9 | |
|
10 | 10 | class GitAdapterTest < ActiveSupport::TestCase |
|
11 | 11 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' |
|
12 | 12 | |
|
13 | 13 | FELIX_UTF8 = "Felix Schäfer" |
|
14 | 14 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
15 | 15 | CHAR_1_HEX = "\xc3\x9c" |
|
16 | 16 | |
|
17 | 17 | if File.directory?(REPOSITORY_PATH) |
|
18 | 18 | def setup |
|
19 | 19 | @adapter = Redmine::Scm::Adapters::GitAdapter.new( |
|
20 | 20 | REPOSITORY_PATH, |
|
21 | 21 | nil, |
|
22 | 22 | nil, |
|
23 | 23 | nil, |
|
24 | 24 | 'ISO-8859-1' |
|
25 | 25 | ) |
|
26 | 26 | assert @adapter |
|
27 | 27 | @char_1 = CHAR_1_HEX.dup |
|
28 | 28 | if @char_1.respond_to?(:force_encoding) |
|
29 | 29 | @char_1.force_encoding('UTF-8') |
|
30 | 30 | end |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_scm_version |
|
34 | 34 | to_test = { "git version 1.7.3.4\n" => [1,7,3,4], |
|
35 | 35 | "1.6.1\n1.7\n1.8" => [1,6,1], |
|
36 | 36 | "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]} |
|
37 | 37 | to_test.each do |s, v| |
|
38 | 38 | test_scm_version_for(s, v) |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_branches |
|
43 | 43 | assert_equal [ |
|
44 | 44 | 'latin-1-path-encoding', |
|
45 | 45 | 'master', |
|
46 | 46 | 'test-latin-1', |
|
47 | 47 | 'test_branch', |
|
48 | 48 | ], @adapter.branches |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def test_tags |
|
52 | 52 | assert_equal [ |
|
53 | 53 | "tag00.lightweight", |
|
54 | 54 | "tag01.annotated", |
|
55 | 55 | ], @adapter.tags |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_getting_all_revisions |
|
59 | 59 | assert_equal 21, @adapter.revisions('',nil,nil,:all => true).length |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def test_getting_certain_revisions |
|
63 | 63 | assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | def test_revisions_reverse | |
|
67 | revs1 = @adapter.revisions('',nil,nil,{:all => true, :reverse => true }) | |
|
68 | assert_equal 21, revs1.length | |
|
69 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[0].identifier | |
|
70 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[20].identifier | |
|
71 | ||
|
72 | since2 = Time.gm(2010, 9, 30, 0, 0, 0) | |
|
73 | revs2 = @adapter.revisions('',nil,nil,{:all => true, :since => since2, :reverse => true }) | |
|
74 | assert_equal 6, revs2.length | |
|
75 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier | |
|
76 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier | |
|
77 | end | |
|
78 | ||
|
66 | 79 | def test_getting_revisions_with_spaces_in_filename |
|
67 | 80 | assert_equal 1, @adapter.revisions("filemane with spaces.txt", |
|
68 | 81 | nil, nil, :all => true).length |
|
69 | 82 | end |
|
70 | 83 | |
|
71 | 84 | def test_getting_revisions_with_leading_and_trailing_spaces_in_filename |
|
72 | 85 | assert_equal " filename with a leading space.txt ", |
|
73 | 86 | @adapter.revisions(" filename with a leading space.txt ", |
|
74 | 87 | nil, nil, :all => true)[0].paths[0][:path] |
|
75 | 88 | end |
|
76 | 89 | |
|
77 | 90 | def test_getting_entries_with_leading_and_trailing_spaces_in_filename |
|
78 | 91 | assert_equal " filename with a leading space.txt ", |
|
79 | 92 | @adapter.entries('', |
|
80 | 93 | '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name |
|
81 | 94 | end |
|
82 | 95 | |
|
83 | 96 | def test_annotate |
|
84 | 97 | annotate = @adapter.annotate('sources/watchers_controller.rb') |
|
85 | 98 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
86 | 99 | assert_equal 41, annotate.lines.size |
|
87 |
assert_equal "# This program is free software; you can redistribute it and/or", |
|
|
100 | assert_equal "# This program is free software; you can redistribute it and/or", | |
|
101 | annotate.lines[4].strip | |
|
88 | 102 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
89 | 103 | annotate.revisions[4].identifier |
|
90 | 104 | assert_equal "jsmith", annotate.revisions[4].author |
|
91 | 105 | end |
|
92 | 106 | |
|
93 | 107 | def test_annotate_moved_file |
|
94 | 108 | annotate = @adapter.annotate('renamed_test.txt') |
|
95 | 109 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
96 | 110 | assert_equal 2, annotate.lines.size |
|
97 | 111 | end |
|
98 | 112 | |
|
99 | 113 | def test_last_rev |
|
100 | 114 | last_rev = @adapter.lastrev("README", |
|
101 | 115 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43") |
|
102 | 116 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid |
|
103 | 117 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier |
|
104 | 118 | assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author |
|
105 | 119 | assert_equal "2009-06-24 05:27:38".to_time, last_rev.time |
|
106 | 120 | end |
|
107 | 121 | |
|
108 | 122 | def test_last_rev_with_spaces_in_filename |
|
109 | 123 | last_rev = @adapter.lastrev("filemane with spaces.txt", |
|
110 | 124 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b") |
|
111 | 125 | str_felix_utf8 = FELIX_UTF8 |
|
112 | 126 | str_felix_hex = FELIX_HEX |
|
113 | 127 | last_rev_author = last_rev.author |
|
114 | 128 | if last_rev_author.respond_to?(:force_encoding) |
|
115 | 129 | last_rev_author.force_encoding('UTF-8') |
|
116 | 130 | end |
|
117 | 131 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid |
|
118 | 132 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier |
|
119 | 133 | assert_equal "#{str_felix_utf8} <felix@fachschaften.org>", |
|
120 | 134 | last_rev.author |
|
121 | 135 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", |
|
122 | 136 | last_rev.author |
|
123 | 137 | assert_equal "2010-09-18 19:59:46".to_time, last_rev.time |
|
124 | 138 | end |
|
125 | 139 | |
|
126 | 140 | def test_latin_1_path |
|
127 | 141 | if Redmine::Platform.mswin? |
|
128 | 142 | # TODO |
|
129 | 143 | else |
|
130 | 144 | p2 = "latin-1-dir/test-#{@char_1}-2.txt" |
|
131 | 145 | ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1| |
|
132 | 146 | assert @adapter.diff(p2, r1) |
|
133 | 147 | assert @adapter.cat(p2, r1) |
|
134 | 148 | assert_equal 1, @adapter.annotate(p2, r1).lines.length |
|
135 | 149 | ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2| |
|
136 | 150 | assert @adapter.diff(p2, r1, r2) |
|
137 | 151 | end |
|
138 | 152 | end |
|
139 | 153 | end |
|
140 | 154 | end |
|
141 | 155 | |
|
142 | 156 | def test_entries_tag |
|
143 | 157 | entries1 = @adapter.entries(nil, 'tag01.annotated') |
|
144 | 158 | assert entries1 |
|
145 | 159 | assert_equal 3, entries1.size |
|
146 | 160 | assert_equal 'sources', entries1[1].name |
|
147 | 161 | assert_equal 'sources', entries1[1].path |
|
148 | 162 | assert_equal 'dir', entries1[1].kind |
|
149 | 163 | readme = entries1[2] |
|
150 | 164 | assert_equal 'README', readme.name |
|
151 | 165 | assert_equal 'README', readme.path |
|
152 | 166 | assert_equal 'file', readme.kind |
|
153 | 167 | assert_equal 27, readme.size |
|
154 | 168 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier |
|
155 | 169 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
156 | 170 | end |
|
157 | 171 | |
|
158 | 172 | def test_entries_branch |
|
159 | 173 | entries1 = @adapter.entries(nil, 'test_branch') |
|
160 | 174 | assert entries1 |
|
161 | 175 | assert_equal 4, entries1.size |
|
162 | 176 | assert_equal 'sources', entries1[1].name |
|
163 | 177 | assert_equal 'sources', entries1[1].path |
|
164 | 178 | assert_equal 'dir', entries1[1].kind |
|
165 | 179 | readme = entries1[2] |
|
166 | 180 | assert_equal 'README', readme.name |
|
167 | 181 | assert_equal 'README', readme.path |
|
168 | 182 | assert_equal 'file', readme.kind |
|
169 | 183 | assert_equal 159, readme.size |
|
170 | 184 | assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier |
|
171 | 185 | assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time |
|
172 | 186 | end |
|
173 | 187 | |
|
174 | 188 | def test_entries_latin_1_files |
|
175 | 189 | entries1 = @adapter.entries('latin-1-dir', '64f1f3e8') |
|
176 | 190 | assert entries1 |
|
177 | 191 | assert_equal 3, entries1.size |
|
178 | 192 | f1 = entries1[1] |
|
179 | 193 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
180 | 194 | assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path |
|
181 | 195 | assert_equal 'file', f1.kind |
|
182 | 196 | end |
|
183 | 197 | |
|
184 | 198 | def test_entries_latin_1_dir |
|
185 | 199 | if Redmine::Platform.mswin? |
|
186 | 200 | # TODO |
|
187 | 201 | else |
|
188 | 202 | entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed') |
|
189 | 203 | assert entries1 |
|
190 | 204 | assert_equal 3, entries1.size |
|
191 | 205 | f1 = entries1[1] |
|
192 | 206 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
193 | 207 | assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path |
|
194 | 208 | assert_equal 'file', f1.kind |
|
195 | 209 | end |
|
196 | 210 | end |
|
197 | 211 | |
|
198 | 212 | private |
|
199 | 213 | |
|
200 | 214 | def test_scm_version_for(scm_command_version, version) |
|
201 | 215 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) |
|
202 | 216 | assert_equal version, @adapter.class.scm_command_version |
|
203 | 217 | end |
|
204 | 218 | |
|
205 | 219 | else |
|
206 | 220 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
207 | 221 | def test_fake; assert true end |
|
208 | 222 | end |
|
209 | 223 | end |
|
210 | 224 | |
|
211 | 225 | rescue LoadError |
|
212 | 226 | class GitMochaFake < ActiveSupport::TestCase |
|
213 | 227 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
214 | 228 | end |
|
215 | 229 | end |
|
216 | 230 |
General Comments 0
You need to be logged in to leave comments.
Login now