##// 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 # 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').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
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 => REPOSITORY_PATH_TRUNK,
32 :project => @project, :url => REPOSITORY_PATH_TRUNK,
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_TRUNK)
63 if File.directory?(REPOSITORY_PATH_TRUNK)
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 assert_equal 'directory', entries[0].path
96
97
97 assert_equal 'file', entries[1].kind
98 assert_equal 'file', entries[1].kind
98 assert_equal 'doc-mkdir.txt', entries[1].name
99 assert_equal 'doc-mkdir.txt', entries[1].name
100 assert_equal 'doc-mkdir.txt', entries[1].path
99 end
101 end
100
102
101 def test_entries_in_subdirectory
103 def test_entries_in_subdirectory
102 entries = @repository.entries('directory')
104 entries = @repository.entries('directory')
103 assert_equal 3, entries.size
105 assert_equal 3, entries.size
104
106
105 assert_equal 'file', entries.last.kind
107 assert_equal 'file', entries.last.kind
106 assert_equal 'edit.png', entries.last.name
108 assert_equal 'edit.png', entries.last.name
107 assert_equal 'directory/edit.png', entries.last.path
109 assert_equal 'directory/edit.png', entries.last.path
108 end
110 end
109
111
110 def test_previous
112 def test_previous
111 assert_equal 0, @repository.changesets.count
113 assert_equal 0, @repository.changesets.count
112 @repository.fetch_changesets
114 @repository.fetch_changesets
113 @project.reload
115 @project.reload
114 assert_equal NUM_REV, @repository.changesets.count
116 assert_equal NUM_REV, @repository.changesets.count
115 changeset = @repository.find_changeset_by_name('3')
117 changeset = @repository.find_changeset_by_name('3')
116 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
118 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
117 end
119 end
118
120
119 def test_previous_nil
121 def test_previous_nil
120 assert_equal 0, @repository.changesets.count
122 assert_equal 0, @repository.changesets.count
121 @repository.fetch_changesets
123 @repository.fetch_changesets
122 @project.reload
124 @project.reload
123 assert_equal NUM_REV, @repository.changesets.count
125 assert_equal NUM_REV, @repository.changesets.count
124 changeset = @repository.find_changeset_by_name('1')
126 changeset = @repository.find_changeset_by_name('1')
125 assert_nil changeset.previous
127 assert_nil changeset.previous
126 end
128 end
127
129
128 def test_next
130 def test_next
129 assert_equal 0, @repository.changesets.count
131 assert_equal 0, @repository.changesets.count
130 @repository.fetch_changesets
132 @repository.fetch_changesets
131 @project.reload
133 @project.reload
132 assert_equal NUM_REV, @repository.changesets.count
134 assert_equal NUM_REV, @repository.changesets.count
133 changeset = @repository.find_changeset_by_name('2')
135 changeset = @repository.find_changeset_by_name('2')
134 assert_equal @repository.find_changeset_by_name('3'), changeset.next
136 assert_equal @repository.find_changeset_by_name('3'), changeset.next
135 end
137 end
136
138
137 def test_next_nil
139 def test_next_nil
138 assert_equal 0, @repository.changesets.count
140 assert_equal 0, @repository.changesets.count
139 @repository.fetch_changesets
141 @repository.fetch_changesets
140 @project.reload
142 @project.reload
141 assert_equal NUM_REV, @repository.changesets.count
143 assert_equal NUM_REV, @repository.changesets.count
142 changeset = @repository.find_changeset_by_name('4')
144 changeset = @repository.find_changeset_by_name('4')
143 assert_nil changeset.next
145 assert_nil changeset.next
144 end
146 end
145 else
147 else
146 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
148 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
147 def test_fake; assert true end
149 def test_fake; assert true end
148 end
150 end
149 end
151 end
General Comments 0
You need to be logged in to leave comments. Login now