Mercurial > hg > soundsoftware-site
comparison test/unit/repository_subversion_test.rb @ 524:1248a47e81b3 feature_36
Merge from branch "luisf"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:39:38 +0100 |
parents | cbce1fd3b1b7 |
children | cbb26bc654de |
comparison
equal
deleted
inserted
replaced
519:3be6bc3c2a17 | 524:1248a47e81b3 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
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 | 19 |
20 class RepositorySubversionTest < ActiveSupport::TestCase | 20 class RepositorySubversionTest < ActiveSupport::TestCase |
21 fixtures :projects, :repositories | 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles |
22 | 22 |
23 def setup | 23 def setup |
24 @project = Project.find(1) | 24 @project = Project.find(3) |
25 assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}") | 25 @repository = Repository::Subversion.create(:project => @project, |
26 :url => self.class.subversion_repository_url) | |
27 assert @repository | |
26 end | 28 end |
27 | 29 |
28 if repository_configured?('subversion') | 30 if repository_configured?('subversion') |
29 def test_fetch_changesets_from_scratch | 31 def test_fetch_changesets_from_scratch |
30 @repository.fetch_changesets | 32 @repository.fetch_changesets |
31 @repository.reload | 33 @repository.reload |
32 | 34 |
33 assert_equal 11, @repository.changesets.count | 35 assert_equal 11, @repository.changesets.count |
34 assert_equal 20, @repository.changes.count | 36 assert_equal 20, @repository.changes.count |
35 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments | 37 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments |
36 end | 38 end |
37 | 39 |
38 def test_fetch_changesets_incremental | 40 def test_fetch_changesets_incremental |
39 @repository.fetch_changesets | 41 @repository.fetch_changesets |
40 # Remove changesets with revision > 5 | 42 # Remove changesets with revision > 5 |
41 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} | 43 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} |
42 @repository.reload | 44 @repository.reload |
43 assert_equal 5, @repository.changesets.count | 45 assert_equal 5, @repository.changesets.count |
44 | 46 |
45 @repository.fetch_changesets | 47 @repository.fetch_changesets |
46 assert_equal 11, @repository.changesets.count | 48 assert_equal 11, @repository.changesets.count |
47 end | 49 end |
48 | 50 |
49 def test_latest_changesets | 51 def test_latest_changesets |
50 @repository.fetch_changesets | 52 @repository.fetch_changesets |
51 | 53 |
52 # with limit | 54 # with limit |
53 changesets = @repository.latest_changesets('', nil, 2) | 55 changesets = @repository.latest_changesets('', nil, 2) |
54 assert_equal 2, changesets.size | 56 assert_equal 2, changesets.size |
55 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets | 57 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets |
56 | 58 |
57 # with path | 59 # with path |
58 changesets = @repository.latest_changesets('subversion_test/folder', nil) | 60 changesets = @repository.latest_changesets('subversion_test/folder', nil) |
59 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision) | 61 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision) |
60 | 62 |
61 # with path and revision | 63 # with path and revision |
62 changesets = @repository.latest_changesets('subversion_test/folder', 8) | 64 changesets = @repository.latest_changesets('subversion_test/folder', 8) |
63 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) | 65 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) |
64 end | 66 end |
65 | 67 |
66 def test_directory_listing_with_square_brackets_in_path | 68 def test_directory_listing_with_square_brackets_in_path |
67 @repository.fetch_changesets | 69 @repository.fetch_changesets |
68 @repository.reload | 70 @repository.reload |
69 | 71 |
70 entries = @repository.entries('subversion_test/[folder_with_brackets]') | 72 entries = @repository.entries('subversion_test/[folder_with_brackets]') |
71 assert_not_nil entries, 'Expect to find entries in folder_with_brackets' | 73 assert_not_nil entries, 'Expect to find entries in folder_with_brackets' |
72 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets' | 74 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets' |
73 assert_equal 'README.txt', entries.first.name | 75 assert_equal 'README.txt', entries.first.name |
74 end | 76 end |
75 | 77 |
76 def test_directory_listing_with_square_brackets_in_base | 78 def test_directory_listing_with_square_brackets_in_base |
77 @project = Project.find(1) | 79 @project = Project.find(3) |
78 @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]") | 80 @repository = Repository::Subversion.create( |
81 :project => @project, | |
82 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]") | |
79 | 83 |
80 @repository.fetch_changesets | 84 @repository.fetch_changesets |
81 @repository.reload | 85 @repository.reload |
82 | 86 |
83 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision' | 87 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision' |
86 entries = @repository.entries('') | 90 entries = @repository.entries('') |
87 assert_not_nil entries, 'Expect to find entries' | 91 assert_not_nil entries, 'Expect to find entries' |
88 assert_equal 1, entries.size, 'Expect a single entry' | 92 assert_equal 1, entries.size, 'Expect a single entry' |
89 assert_equal 'README.txt', entries.first.name | 93 assert_equal 'README.txt', entries.first.name |
90 end | 94 end |
95 | |
96 def test_identifier | |
97 @repository.fetch_changesets | |
98 @repository.reload | |
99 c = @repository.changesets.find_by_revision('1') | |
100 assert_equal c.revision, c.identifier | |
101 end | |
102 | |
103 def test_find_changeset_by_empty_name | |
104 @repository.fetch_changesets | |
105 @repository.reload | |
106 ['', ' ', nil].each do |r| | |
107 assert_nil @repository.find_changeset_by_name(r) | |
108 end | |
109 end | |
110 | |
111 def test_identifier_nine_digit | |
112 c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
113 :revision => '123456789', :comments => 'test') | |
114 assert_equal c.identifier, c.revision | |
115 end | |
116 | |
117 def test_format_identifier | |
118 @repository.fetch_changesets | |
119 @repository.reload | |
120 c = @repository.changesets.find_by_revision('1') | |
121 assert_equal c.format_identifier, c.revision | |
122 end | |
123 | |
124 def test_format_identifier_nine_digit | |
125 c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
126 :revision => '123456789', :comments => 'test') | |
127 assert_equal c.format_identifier, c.revision | |
128 end | |
129 | |
130 def test_activities | |
131 c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
132 :revision => '1', :comments => 'test') | |
133 assert c.event_title.include?('1:') | |
134 assert_equal '1', c.event_url[:rev] | |
135 end | |
136 | |
137 def test_activities_nine_digit | |
138 c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
139 :revision => '123456789', :comments => 'test') | |
140 assert c.event_title.include?('123456789:') | |
141 assert_equal '123456789', c.event_url[:rev] | |
142 end | |
143 | |
144 def test_log_encoding_ignore_setting | |
145 with_settings :commit_logs_encoding => 'windows-1252' do | |
146 s1 = "\xC2\x80" | |
147 s2 = "\xc3\x82\xc2\x80" | |
148 if s1.respond_to?(:force_encoding) | |
149 s1.force_encoding('ISO-8859-1') | |
150 s2.force_encoding('UTF-8') | |
151 assert_equal s1.encode('UTF-8'), s2 | |
152 end | |
153 c = Changeset.new(:repository => @repository, | |
154 :comments => s2, | |
155 :revision => '123', | |
156 :committed_on => Time.now) | |
157 assert c.save | |
158 assert_equal s2, c.comments | |
159 end | |
160 end | |
161 | |
162 def test_previous | |
163 @repository.fetch_changesets | |
164 @repository.reload | |
165 changeset = @repository.find_changeset_by_name('3') | |
166 assert_equal @repository.find_changeset_by_name('2'), changeset.previous | |
167 end | |
168 | |
169 def test_previous_nil | |
170 @repository.fetch_changesets | |
171 @repository.reload | |
172 changeset = @repository.find_changeset_by_name('1') | |
173 assert_nil changeset.previous | |
174 end | |
175 | |
176 def test_next | |
177 @repository.fetch_changesets | |
178 @repository.reload | |
179 changeset = @repository.find_changeset_by_name('2') | |
180 assert_equal @repository.find_changeset_by_name('3'), changeset.next | |
181 end | |
182 | |
183 def test_next_nil | |
184 @repository.fetch_changesets | |
185 @repository.reload | |
186 changeset = @repository.find_changeset_by_name('11') | |
187 assert_nil changeset.next | |
188 end | |
91 else | 189 else |
92 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" | 190 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" |
93 def test_fake; assert true end | 191 def test_fake; assert true end |
94 end | 192 end |
95 end | 193 end |