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