##// END OF EJS Templates
scm: bazaar: define NUM_REV as the number of test repository revisions at unit model test...
Toshi MARUYAMA -
r6946:dcc38927faaa
parent child
Show More
@@ -1,105 +1,106
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoryBazaarTest < ActiveSupport::TestCase
20 class RepositoryBazaarTest < ActiveSupport::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
23 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
24 REPOSITORY_PATH.gsub!(/\/+/, '/')
24 REPOSITORY_PATH.gsub!(/\/+/, '/')
25 NUM_REV = 4
25
26
26 def setup
27 def setup
27 @project = Project.find(3)
28 @project = Project.find(3)
28 @repository = Repository::Bazaar.create(
29 @repository = Repository::Bazaar.create(
29 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
30 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
30 :log_encoding => 'UTF-8')
31 :log_encoding => 'UTF-8')
31 assert @repository
32 assert @repository
32 end
33 end
33
34
34 if File.directory?(REPOSITORY_PATH)
35 if File.directory?(REPOSITORY_PATH)
35 def test_fetch_changesets_from_scratch
36 def test_fetch_changesets_from_scratch
36 @repository.fetch_changesets
37 @repository.fetch_changesets
37 @repository.reload
38 @repository.reload
38
39
39 assert_equal 4, @repository.changesets.count
40 assert_equal 4, @repository.changesets.count
40 assert_equal 9, @repository.changes.count
41 assert_equal 9, @repository.changes.count
41 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
42 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
42 end
43 end
43
44
44 def test_fetch_changesets_incremental
45 def test_fetch_changesets_incremental
45 @repository.fetch_changesets
46 @repository.fetch_changesets
46 # Remove changesets with revision > 5
47 # Remove changesets with revision > 5
47 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
48 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
48 @repository.reload
49 @repository.reload
49 assert_equal 2, @repository.changesets.count
50 assert_equal 2, @repository.changesets.count
50
51
51 @repository.fetch_changesets
52 @repository.fetch_changesets
52 assert_equal 4, @repository.changesets.count
53 assert_equal 4, @repository.changesets.count
53 end
54 end
54
55
55 def test_entries
56 def test_entries
56 entries = @repository.entries
57 entries = @repository.entries
57 assert_equal 2, entries.size
58 assert_equal 2, entries.size
58
59
59 assert_equal 'dir', entries[0].kind
60 assert_equal 'dir', entries[0].kind
60 assert_equal 'directory', entries[0].name
61 assert_equal 'directory', entries[0].name
61
62
62 assert_equal 'file', entries[1].kind
63 assert_equal 'file', entries[1].kind
63 assert_equal 'doc-mkdir.txt', entries[1].name
64 assert_equal 'doc-mkdir.txt', entries[1].name
64 end
65 end
65
66
66 def test_entries_in_subdirectory
67 def test_entries_in_subdirectory
67 entries = @repository.entries('directory')
68 entries = @repository.entries('directory')
68 assert_equal 3, entries.size
69 assert_equal 3, entries.size
69
70
70 assert_equal 'file', entries.last.kind
71 assert_equal 'file', entries.last.kind
71 assert_equal 'edit.png', entries.last.name
72 assert_equal 'edit.png', entries.last.name
72 end
73 end
73
74
74 def test_previous
75 def test_previous
75 @repository.fetch_changesets
76 @repository.fetch_changesets
76 @repository.reload
77 @repository.reload
77 changeset = @repository.find_changeset_by_name('3')
78 changeset = @repository.find_changeset_by_name('3')
78 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
79 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
79 end
80 end
80
81
81 def test_previous_nil
82 def test_previous_nil
82 @repository.fetch_changesets
83 @repository.fetch_changesets
83 @repository.reload
84 @repository.reload
84 changeset = @repository.find_changeset_by_name('1')
85 changeset = @repository.find_changeset_by_name('1')
85 assert_nil changeset.previous
86 assert_nil changeset.previous
86 end
87 end
87
88
88 def test_next
89 def test_next
89 @repository.fetch_changesets
90 @repository.fetch_changesets
90 @repository.reload
91 @repository.reload
91 changeset = @repository.find_changeset_by_name('2')
92 changeset = @repository.find_changeset_by_name('2')
92 assert_equal @repository.find_changeset_by_name('3'), changeset.next
93 assert_equal @repository.find_changeset_by_name('3'), changeset.next
93 end
94 end
94
95
95 def test_next_nil
96 def test_next_nil
96 @repository.fetch_changesets
97 @repository.fetch_changesets
97 @repository.reload
98 @repository.reload
98 changeset = @repository.find_changeset_by_name('4')
99 changeset = @repository.find_changeset_by_name('4')
99 assert_nil changeset.next
100 assert_nil changeset.next
100 end
101 end
101 else
102 else
102 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
103 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
103 def test_fake; assert true end
104 def test_fake; assert true end
104 end
105 end
105 end
106 end
General Comments 0
You need to be logged in to leave comments. Login now