##// END OF EJS Templates
Rails3: scm: cvs: fix error of test_entries_invalid_path at unit model test...
Toshi MARUYAMA -
r7014:fa3f93f2a065
parent child
Show More
@@ -1,170 +1,172
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 require 'pp'
19 require 'pp'
20 class RepositoryCvsTest < ActiveSupport::TestCase
20 class RepositoryCvsTest < ActiveSupport::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
23 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
24 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
24 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
25 # CVS module
25 # CVS module
26 MODULE_NAME = 'test'
26 MODULE_NAME = 'test'
27 CHANGESETS_NUM = 7
27 CHANGESETS_NUM = 7
28
28
29 def setup
29 def setup
30 @project = Project.find(3)
30 @project = Project.find(3)
31 @repository = Repository::Cvs.create(:project => @project,
31 @repository = Repository::Cvs.create(:project => @project,
32 :root_url => REPOSITORY_PATH,
32 :root_url => REPOSITORY_PATH,
33 :url => MODULE_NAME,
33 :url => MODULE_NAME,
34 :log_encoding => 'UTF-8')
34 :log_encoding => 'UTF-8')
35 assert @repository
35 assert @repository
36 end
36 end
37
37
38 if File.directory?(REPOSITORY_PATH)
38 if File.directory?(REPOSITORY_PATH)
39 def test_fetch_changesets_from_scratch
39 def test_fetch_changesets_from_scratch
40 assert_equal 0, @repository.changesets.count
40 assert_equal 0, @repository.changesets.count
41 @repository.fetch_changesets
41 @repository.fetch_changesets
42 @project.reload
42 @project.reload
43
43
44 assert_equal CHANGESETS_NUM, @repository.changesets.count
44 assert_equal CHANGESETS_NUM, @repository.changesets.count
45 assert_equal 16, @repository.changes.count
45 assert_equal 16, @repository.changes.count
46 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
46 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
47
47
48 r2 = @repository.changesets.find_by_revision('2')
48 r2 = @repository.changesets.find_by_revision('2')
49 assert_equal 'v1-20071213-162510', r2.scmid
49 assert_equal 'v1-20071213-162510', r2.scmid
50 end
50 end
51
51
52 def test_fetch_changesets_incremental
52 def test_fetch_changesets_incremental
53 assert_equal 0, @repository.changesets.count
53 assert_equal 0, @repository.changesets.count
54 @repository.fetch_changesets
54 @repository.fetch_changesets
55 # Remove changesets with revision > 3
55 # Remove changesets with revision > 3
56 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
56 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
57 @repository.reload
57 @repository.reload
58 assert_equal 3, @repository.changesets.count
58 assert_equal 3, @repository.changesets.count
59 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
59 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
60
60
61 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
61 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
62 assert_equal '3', rev3_commit.revision
62 assert_equal '3', rev3_commit.revision
63 # 2007-12-14 01:27:22 +0900
63 # 2007-12-14 01:27:22 +0900
64 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
64 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
65 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
65 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
66 assert_equal rev3_committed_on, rev3_commit.committed_on
66 assert_equal rev3_committed_on, rev3_commit.committed_on
67 latest_rev = @repository.latest_changeset
67 latest_rev = @repository.latest_changeset
68 assert_equal rev3_committed_on, latest_rev.committed_on
68 assert_equal rev3_committed_on, latest_rev.committed_on
69
69
70 @repository.fetch_changesets
70 @repository.fetch_changesets
71 @repository.reload
71 @repository.reload
72 assert_equal CHANGESETS_NUM, @repository.changesets.count
72 assert_equal CHANGESETS_NUM, @repository.changesets.count
73
73
74 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
74 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
75 rev5_commit = @repository.changesets.find_by_revision('5')
75 rev5_commit = @repository.changesets.find_by_revision('5')
76 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
76 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
77 # 2007-12-14 01:30:01 +0900
77 # 2007-12-14 01:30:01 +0900
78 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
78 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
79 assert_equal rev5_committed_on, rev5_commit.committed_on
79 assert_equal rev5_committed_on, rev5_commit.committed_on
80 end
80 end
81
81
82 def test_deleted_files_should_not_be_listed
82 def test_deleted_files_should_not_be_listed
83 assert_equal 0, @repository.changesets.count
83 assert_equal 0, @repository.changesets.count
84 @repository.fetch_changesets
84 @repository.fetch_changesets
85 @project.reload
85 @project.reload
86 assert_equal CHANGESETS_NUM, @repository.changesets.count
86 assert_equal CHANGESETS_NUM, @repository.changesets.count
87
87
88 entries = @repository.entries('sources')
88 entries = @repository.entries('sources')
89 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
89 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
90 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
90 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
91 end
91 end
92
92
93 def test_entries_rev3
93 def test_entries_rev3
94 assert_equal 0, @repository.changesets.count
94 assert_equal 0, @repository.changesets.count
95 @repository.fetch_changesets
95 @repository.fetch_changesets
96 @project.reload
96 @project.reload
97 assert_equal CHANGESETS_NUM, @repository.changesets.count
97 assert_equal CHANGESETS_NUM, @repository.changesets.count
98 entries = @repository.entries('', '3')
98 entries = @repository.entries('', '3')
99 assert_equal 3, entries.size
99 assert_equal 3, entries.size
100 assert_equal entries[2].name, "README"
100 assert_equal entries[2].name, "README"
101 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
101 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
102 assert_equal entries[2].lastrev.identifier, '3'
102 assert_equal entries[2].lastrev.identifier, '3'
103 assert_equal entries[2].lastrev.revision, '3'
103 assert_equal entries[2].lastrev.revision, '3'
104 assert_equal entries[2].lastrev.author, 'LANG'
104 assert_equal entries[2].lastrev.author, 'LANG'
105 end
105 end
106
106
107 def test_entries_invalid_path
107 def test_entries_invalid_path
108 assert_equal 0, @repository.changesets.count
108 @repository.fetch_changesets
109 @repository.fetch_changesets
109 @repository.reload
110 @project.reload
111 assert_equal CHANGESETS_NUM, @repository.changesets.count
110 assert_nil @repository.entries('missing')
112 assert_nil @repository.entries('missing')
111 assert_nil @repository.entries('missing', '3')
113 assert_nil @repository.entries('missing', '3')
112 end
114 end
113
115
114 def test_entries_invalid_revision
116 def test_entries_invalid_revision
115 @repository.fetch_changesets
117 @repository.fetch_changesets
116 @repository.reload
118 @repository.reload
117 assert_nil @repository.entries('', '123')
119 assert_nil @repository.entries('', '123')
118 end
120 end
119
121
120 def test_cat
122 def test_cat
121 @repository.fetch_changesets
123 @repository.fetch_changesets
122 @repository.reload
124 @repository.reload
123 buf = @repository.cat('README')
125 buf = @repository.cat('README')
124 assert buf
126 assert buf
125 lines = buf.split("\n")
127 lines = buf.split("\n")
126 assert_equal 3, lines.length
128 assert_equal 3, lines.length
127 buf = lines[1].gsub(/\r$/, "")
129 buf = lines[1].gsub(/\r$/, "")
128 assert_equal 'with one change', buf
130 assert_equal 'with one change', buf
129 buf = @repository.cat('README', '1')
131 buf = @repository.cat('README', '1')
130 assert buf
132 assert buf
131 lines = buf.split("\n")
133 lines = buf.split("\n")
132 assert_equal 1, lines.length
134 assert_equal 1, lines.length
133 buf = lines[0].gsub(/\r$/, "")
135 buf = lines[0].gsub(/\r$/, "")
134 assert_equal 'CVS test repository', buf
136 assert_equal 'CVS test repository', buf
135 assert_nil @repository.cat('missing.rb')
137 assert_nil @repository.cat('missing.rb')
136
138
137 # sources/welcome_controller.rb is removed at revision 5.
139 # sources/welcome_controller.rb is removed at revision 5.
138 assert @repository.cat('sources/welcome_controller.rb', '4')
140 assert @repository.cat('sources/welcome_controller.rb', '4')
139 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
141 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
140
142
141 # invalid revision
143 # invalid revision
142 assert @repository.cat('README', '123').blank?
144 assert @repository.cat('README', '123').blank?
143 end
145 end
144
146
145 def test_annotate
147 def test_annotate
146 @repository.fetch_changesets
148 @repository.fetch_changesets
147 @repository.reload
149 @repository.reload
148 ann = @repository.annotate('README')
150 ann = @repository.annotate('README')
149 assert ann
151 assert ann
150 assert_equal 3, ann.revisions.length
152 assert_equal 3, ann.revisions.length
151 assert_equal '1.2', ann.revisions[1].revision
153 assert_equal '1.2', ann.revisions[1].revision
152 assert_equal 'LANG', ann.revisions[1].author
154 assert_equal 'LANG', ann.revisions[1].author
153 assert_equal 'with one change', ann.lines[1]
155 assert_equal 'with one change', ann.lines[1]
154
156
155 ann = @repository.annotate('README', '1')
157 ann = @repository.annotate('README', '1')
156 assert ann
158 assert ann
157 assert_equal 1, ann.revisions.length
159 assert_equal 1, ann.revisions.length
158 assert_equal '1.1', ann.revisions[0].revision
160 assert_equal '1.1', ann.revisions[0].revision
159 assert_equal 'LANG', ann.revisions[0].author
161 assert_equal 'LANG', ann.revisions[0].author
160 assert_equal 'CVS test repository', ann.lines[0]
162 assert_equal 'CVS test repository', ann.lines[0]
161
163
162 # invalid revision
164 # invalid revision
163 assert_nil @repository.annotate('README', '123')
165 assert_nil @repository.annotate('README', '123')
164 end
166 end
165
167
166 else
168 else
167 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
169 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
168 def test_fake; assert true end
170 def test_fake; assert true end
169 end
171 end
170 end
172 end
General Comments 0
You need to be logged in to leave comments. Login now