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