##// END OF EJS Templates
Rails3: scm: bazaar: fix error of test_next at unit model test...
Toshi MARUYAMA -
r6962:99339a7420f6
parent child
Show More
@@ -1,115 +1,117
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 NUM_REV = 4
26
26
27 def setup
27 def setup
28 @project = Project.find(3)
28 @project = Project.find(3)
29 @repository = Repository::Bazaar.create(
29 @repository = Repository::Bazaar.create(
30 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
30 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
31 :log_encoding => 'UTF-8')
31 :log_encoding => 'UTF-8')
32 assert @repository
32 assert @repository
33 end
33 end
34
34
35 if File.directory?(REPOSITORY_PATH)
35 if File.directory?(REPOSITORY_PATH)
36 def test_fetch_changesets_from_scratch
36 def test_fetch_changesets_from_scratch
37 assert_equal 0, @repository.changesets.count
37 assert_equal 0, @repository.changesets.count
38 @repository.fetch_changesets
38 @repository.fetch_changesets
39 @project.reload
39 @project.reload
40
40
41 assert_equal NUM_REV, @repository.changesets.count
41 assert_equal NUM_REV, @repository.changesets.count
42 assert_equal 9, @repository.changes.count
42 assert_equal 9, @repository.changes.count
43 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
43 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
44 end
44 end
45
45
46 def test_fetch_changesets_incremental
46 def test_fetch_changesets_incremental
47 assert_equal 0, @repository.changesets.count
47 assert_equal 0, @repository.changesets.count
48 @repository.fetch_changesets
48 @repository.fetch_changesets
49 @project.reload
49 @project.reload
50 assert_equal NUM_REV, @repository.changesets.count
50 assert_equal NUM_REV, @repository.changesets.count
51 # Remove changesets with revision > 5
51 # Remove changesets with revision > 5
52 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
52 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
53 @project.reload
53 @project.reload
54 assert_equal 2, @repository.changesets.count
54 assert_equal 2, @repository.changesets.count
55
55
56 @repository.fetch_changesets
56 @repository.fetch_changesets
57 @project.reload
57 @project.reload
58 assert_equal NUM_REV, @repository.changesets.count
58 assert_equal NUM_REV, @repository.changesets.count
59 end
59 end
60
60
61 def test_entries
61 def test_entries
62 entries = @repository.entries
62 entries = @repository.entries
63 assert_equal 2, entries.size
63 assert_equal 2, entries.size
64
64
65 assert_equal 'dir', entries[0].kind
65 assert_equal 'dir', entries[0].kind
66 assert_equal 'directory', entries[0].name
66 assert_equal 'directory', entries[0].name
67
67
68 assert_equal 'file', entries[1].kind
68 assert_equal 'file', entries[1].kind
69 assert_equal 'doc-mkdir.txt', entries[1].name
69 assert_equal 'doc-mkdir.txt', entries[1].name
70 end
70 end
71
71
72 def test_entries_in_subdirectory
72 def test_entries_in_subdirectory
73 entries = @repository.entries('directory')
73 entries = @repository.entries('directory')
74 assert_equal 3, entries.size
74 assert_equal 3, entries.size
75
75
76 assert_equal 'file', entries.last.kind
76 assert_equal 'file', entries.last.kind
77 assert_equal 'edit.png', entries.last.name
77 assert_equal 'edit.png', entries.last.name
78 end
78 end
79
79
80 def test_previous
80 def test_previous
81 assert_equal 0, @repository.changesets.count
81 assert_equal 0, @repository.changesets.count
82 @repository.fetch_changesets
82 @repository.fetch_changesets
83 @project.reload
83 @project.reload
84 assert_equal NUM_REV, @repository.changesets.count
84 assert_equal NUM_REV, @repository.changesets.count
85 changeset = @repository.find_changeset_by_name('3')
85 changeset = @repository.find_changeset_by_name('3')
86 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
86 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
87 end
87 end
88
88
89 def test_previous_nil
89 def test_previous_nil
90 assert_equal 0, @repository.changesets.count
90 assert_equal 0, @repository.changesets.count
91 @repository.fetch_changesets
91 @repository.fetch_changesets
92 @project.reload
92 @project.reload
93 assert_equal NUM_REV, @repository.changesets.count
93 assert_equal NUM_REV, @repository.changesets.count
94 changeset = @repository.find_changeset_by_name('1')
94 changeset = @repository.find_changeset_by_name('1')
95 assert_nil changeset.previous
95 assert_nil changeset.previous
96 end
96 end
97
97
98 def test_next
98 def test_next
99 assert_equal 0, @repository.changesets.count
99 @repository.fetch_changesets
100 @repository.fetch_changesets
100 @repository.reload
101 @project.reload
102 assert_equal NUM_REV, @repository.changesets.count
101 changeset = @repository.find_changeset_by_name('2')
103 changeset = @repository.find_changeset_by_name('2')
102 assert_equal @repository.find_changeset_by_name('3'), changeset.next
104 assert_equal @repository.find_changeset_by_name('3'), changeset.next
103 end
105 end
104
106
105 def test_next_nil
107 def test_next_nil
106 @repository.fetch_changesets
108 @repository.fetch_changesets
107 @repository.reload
109 @repository.reload
108 changeset = @repository.find_changeset_by_name('4')
110 changeset = @repository.find_changeset_by_name('4')
109 assert_nil changeset.next
111 assert_nil changeset.next
110 end
112 end
111 else
113 else
112 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
114 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
113 def test_fake; assert true end
115 def test_fake; assert true end
114 end
116 end
115 end
117 end
General Comments 0
You need to be logged in to leave comments. Login now