##// END OF EJS Templates
scm: bazaar: add asserting entries root path at unit model test...
Toshi MARUYAMA -
r10215:53e2eb186799
parent child
Show More
@@ -1,149 +1,151
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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
20 20 class RepositoryBazaarTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
26 26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
27 27 NUM_REV = 4
28 28
29 29 def setup
30 30 @project = Project.find(3)
31 31 @repository = Repository::Bazaar.create(
32 32 :project => @project, :url => REPOSITORY_PATH_TRUNK,
33 33 :log_encoding => 'UTF-8')
34 34 assert @repository
35 35 end
36 36
37 37 def test_blank_path_to_repository_error_message
38 38 set_language_if_valid 'en'
39 39 repo = Repository::Bazaar.new(
40 40 :project => @project,
41 41 :identifier => 'test',
42 42 :log_encoding => 'UTF-8'
43 43 )
44 44 assert !repo.save
45 45 assert_include "Path to repository can't be blank",
46 46 repo.errors.full_messages
47 47 end
48 48
49 49 def test_blank_path_to_repository_error_message_fr
50 50 set_language_if_valid 'fr'
51 51 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
52 52 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
53 53 repo = Repository::Bazaar.new(
54 54 :project => @project,
55 55 :url => "",
56 56 :identifier => 'test',
57 57 :log_encoding => 'UTF-8'
58 58 )
59 59 assert !repo.save
60 60 assert_include str, repo.errors.full_messages
61 61 end
62 62
63 63 if File.directory?(REPOSITORY_PATH_TRUNK)
64 64 def test_fetch_changesets_from_scratch
65 65 assert_equal 0, @repository.changesets.count
66 66 @repository.fetch_changesets
67 67 @project.reload
68 68
69 69 assert_equal NUM_REV, @repository.changesets.count
70 70 assert_equal 9, @repository.filechanges.count
71 71 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
72 72 end
73 73
74 74 def test_fetch_changesets_incremental
75 75 assert_equal 0, @repository.changesets.count
76 76 @repository.fetch_changesets
77 77 @project.reload
78 78 assert_equal NUM_REV, @repository.changesets.count
79 79 # Remove changesets with revision > 5
80 80 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
81 81 @project.reload
82 82 assert_equal 2, @repository.changesets.count
83 83
84 84 @repository.fetch_changesets
85 85 @project.reload
86 86 assert_equal NUM_REV, @repository.changesets.count
87 87 end
88 88
89 89 def test_entries
90 90 entries = @repository.entries
91 91 assert_kind_of Redmine::Scm::Adapters::Entries, entries
92 92 assert_equal 2, entries.size
93 93
94 94 assert_equal 'dir', entries[0].kind
95 95 assert_equal 'directory', entries[0].name
96 assert_equal 'directory', entries[0].path
96 97
97 98 assert_equal 'file', entries[1].kind
98 99 assert_equal 'doc-mkdir.txt', entries[1].name
100 assert_equal 'doc-mkdir.txt', entries[1].path
99 101 end
100 102
101 103 def test_entries_in_subdirectory
102 104 entries = @repository.entries('directory')
103 105 assert_equal 3, entries.size
104 106
105 107 assert_equal 'file', entries.last.kind
106 108 assert_equal 'edit.png', entries.last.name
107 109 assert_equal 'directory/edit.png', entries.last.path
108 110 end
109 111
110 112 def test_previous
111 113 assert_equal 0, @repository.changesets.count
112 114 @repository.fetch_changesets
113 115 @project.reload
114 116 assert_equal NUM_REV, @repository.changesets.count
115 117 changeset = @repository.find_changeset_by_name('3')
116 118 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
117 119 end
118 120
119 121 def test_previous_nil
120 122 assert_equal 0, @repository.changesets.count
121 123 @repository.fetch_changesets
122 124 @project.reload
123 125 assert_equal NUM_REV, @repository.changesets.count
124 126 changeset = @repository.find_changeset_by_name('1')
125 127 assert_nil changeset.previous
126 128 end
127 129
128 130 def test_next
129 131 assert_equal 0, @repository.changesets.count
130 132 @repository.fetch_changesets
131 133 @project.reload
132 134 assert_equal NUM_REV, @repository.changesets.count
133 135 changeset = @repository.find_changeset_by_name('2')
134 136 assert_equal @repository.find_changeset_by_name('3'), changeset.next
135 137 end
136 138
137 139 def test_next_nil
138 140 assert_equal 0, @repository.changesets.count
139 141 @repository.fetch_changesets
140 142 @project.reload
141 143 assert_equal NUM_REV, @repository.changesets.count
142 144 changeset = @repository.find_changeset_by_name('4')
143 145 assert_nil changeset.next
144 146 end
145 147 else
146 148 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
147 149 def test_fake; assert true end
148 150 end
149 151 end
General Comments 0
You need to be logged in to leave comments. Login now