##// END OF EJS Templates
Rails3: scm: darcs: fix error of test_fetch_changesets_incremental at unit model test...
Toshi MARUYAMA -
r6998:fa4a41a65383
parent child
Show More
@@ -1,84 +1,89
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 RepositoryDarcsTest < ActiveSupport::TestCase
20 class RepositoryDarcsTest < ActiveSupport::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
23 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
24 NUM_REV = 6
24 NUM_REV = 6
25
25
26 def setup
26 def setup
27 @project = Project.find(3)
27 @project = Project.find(3)
28 @repository = Repository::Darcs.create(
28 @repository = Repository::Darcs.create(
29 :project => @project,
29 :project => @project,
30 :url => REPOSITORY_PATH,
30 :url => REPOSITORY_PATH,
31 :log_encoding => 'UTF-8'
31 :log_encoding => 'UTF-8'
32 )
32 )
33 assert @repository
33 assert @repository
34 end
34 end
35
35
36 if File.directory?(REPOSITORY_PATH)
36 if File.directory?(REPOSITORY_PATH)
37 def test_fetch_changesets_from_scratch
37 def test_fetch_changesets_from_scratch
38 assert_equal 0, @repository.changesets.count
38 assert_equal 0, @repository.changesets.count
39 @repository.fetch_changesets
39 @repository.fetch_changesets
40 @project.reload
40 @project.reload
41
41
42 assert_equal NUM_REV, @repository.changesets.count
42 assert_equal NUM_REV, @repository.changesets.count
43 assert_equal 13, @repository.changes.count
43 assert_equal 13, @repository.changes.count
44 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
44 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
45 end
45 end
46
46
47 def test_fetch_changesets_incremental
47 def test_fetch_changesets_incremental
48 assert_equal 0, @repository.changesets.count
48 @repository.fetch_changesets
49 @repository.fetch_changesets
50 @project.reload
51 assert_equal NUM_REV, @repository.changesets.count
52
49 # Remove changesets with revision > 3
53 # Remove changesets with revision > 3
50 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
54 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
51 @repository.reload
55 @project.reload
52 assert_equal 3, @repository.changesets.count
56 assert_equal 3, @repository.changesets.count
53
57
54 @repository.fetch_changesets
58 @repository.fetch_changesets
55 assert_equal 6, @repository.changesets.count
59 @project.reload
60 assert_equal NUM_REV, @repository.changesets.count
56 end
61 end
57
62
58 def test_entries_invalid_revision
63 def test_entries_invalid_revision
59 @repository.fetch_changesets
64 @repository.fetch_changesets
60 @repository.reload
65 @repository.reload
61 assert_nil @repository.entries('', '123')
66 assert_nil @repository.entries('', '123')
62 end
67 end
63
68
64 def test_deleted_files_should_not_be_listed
69 def test_deleted_files_should_not_be_listed
65 @repository.fetch_changesets
70 @repository.fetch_changesets
66 @repository.reload
71 @repository.reload
67 entries = @repository.entries('sources')
72 entries = @repository.entries('sources')
68 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
73 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
69 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
74 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
70 end
75 end
71
76
72 def test_cat
77 def test_cat
73 if @repository.scm.supports_cat?
78 if @repository.scm.supports_cat?
74 @repository.fetch_changesets
79 @repository.fetch_changesets
75 cat = @repository.cat("sources/welcome_controller.rb", 2)
80 cat = @repository.cat("sources/welcome_controller.rb", 2)
76 assert_not_nil cat
81 assert_not_nil cat
77 assert cat.include?('class WelcomeController < ApplicationController')
82 assert cat.include?('class WelcomeController < ApplicationController')
78 end
83 end
79 end
84 end
80 else
85 else
81 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
86 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
82 def test_fake; assert true end
87 def test_fake; assert true end
83 end
88 end
84 end
89 end
General Comments 0
You need to be logged in to leave comments. Login now