##// END OF EJS Templates
scm: bazaar: add asserting entries subdirectory path at unit app test...
Toshi MARUYAMA -
r10203:4a7e148affe7
parent child
Show More
@@ -1,148 +1,149
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/trunk').to_s
26 26 REPOSITORY_PATH.gsub!(/\/+/, '/')
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 => "file:///#{REPOSITORY_PATH}",
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)
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 96
97 97 assert_equal 'file', entries[1].kind
98 98 assert_equal 'doc-mkdir.txt', entries[1].name
99 99 end
100 100
101 101 def test_entries_in_subdirectory
102 102 entries = @repository.entries('directory')
103 103 assert_equal 3, entries.size
104 104
105 105 assert_equal 'file', entries.last.kind
106 106 assert_equal 'edit.png', entries.last.name
107 assert_equal 'directory/edit.png', entries.last.path
107 108 end
108 109
109 110 def test_previous
110 111 assert_equal 0, @repository.changesets.count
111 112 @repository.fetch_changesets
112 113 @project.reload
113 114 assert_equal NUM_REV, @repository.changesets.count
114 115 changeset = @repository.find_changeset_by_name('3')
115 116 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
116 117 end
117 118
118 119 def test_previous_nil
119 120 assert_equal 0, @repository.changesets.count
120 121 @repository.fetch_changesets
121 122 @project.reload
122 123 assert_equal NUM_REV, @repository.changesets.count
123 124 changeset = @repository.find_changeset_by_name('1')
124 125 assert_nil changeset.previous
125 126 end
126 127
127 128 def test_next
128 129 assert_equal 0, @repository.changesets.count
129 130 @repository.fetch_changesets
130 131 @project.reload
131 132 assert_equal NUM_REV, @repository.changesets.count
132 133 changeset = @repository.find_changeset_by_name('2')
133 134 assert_equal @repository.find_changeset_by_name('3'), changeset.next
134 135 end
135 136
136 137 def test_next_nil
137 138 assert_equal 0, @repository.changesets.count
138 139 @repository.fetch_changesets
139 140 @project.reload
140 141 assert_equal NUM_REV, @repository.changesets.count
141 142 changeset = @repository.find_changeset_by_name('4')
142 143 assert_nil changeset.next
143 144 end
144 145 else
145 146 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
146 147 def test_fake; assert true end
147 148 end
148 149 end
General Comments 0
You need to be logged in to leave comments. Login now