comparison test/unit/repository_darcs_test.rb @ 524:1248a47e81b3 feature_36

Merge from branch "luisf"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:39:38 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
519:3be6bc3c2a17 524:1248a47e81b3
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.dirname(__FILE__) + '/../test_helper' 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 # No '..' in the repository path 23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository' 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository'
25 25
26 def setup 26 def setup
27 @project = Project.find(1) 27 @project = Project.find(3)
28 assert @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH) 28 @repository = Repository::Darcs.create(
29 :project => @project, :url => REPOSITORY_PATH,
30 :log_encoding => 'UTF-8')
31 assert @repository
29 end 32 end
30 33
31 if File.directory?(REPOSITORY_PATH) 34 if File.directory?(REPOSITORY_PATH)
32 def test_fetch_changesets_from_scratch 35 def test_fetch_changesets_from_scratch
33 @repository.fetch_changesets 36 @repository.fetch_changesets
34 @repository.reload 37 @repository.reload
35 38
36 assert_equal 6, @repository.changesets.count 39 assert_equal 6, @repository.changesets.count
37 assert_equal 13, @repository.changes.count 40 assert_equal 13, @repository.changes.count
38 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments 41 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
39 end 42 end
40 43
41 def test_fetch_changesets_incremental 44 def test_fetch_changesets_incremental
42 @repository.fetch_changesets 45 @repository.fetch_changesets
43 # Remove changesets with revision > 3 46 # Remove changesets with revision > 3
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3} 47 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
45 @repository.reload 48 @repository.reload
46 assert_equal 3, @repository.changesets.count 49 assert_equal 3, @repository.changesets.count
47 50
48 @repository.fetch_changesets 51 @repository.fetch_changesets
49 assert_equal 6, @repository.changesets.count 52 assert_equal 6, @repository.changesets.count
50 end 53 end
51 54
55 def test_entries_invalid_revision
56 @repository.fetch_changesets
57 @repository.reload
58 assert_nil @repository.entries('', '123')
59 end
60
52 def test_deleted_files_should_not_be_listed 61 def test_deleted_files_should_not_be_listed
62 @repository.fetch_changesets
63 @repository.reload
53 entries = @repository.entries('sources') 64 entries = @repository.entries('sources')
54 assert entries.detect {|e| e.name == 'watchers_controller.rb'} 65 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
55 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'} 66 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
56 end 67 end
57 68
58 def test_cat 69 def test_cat
59 @repository.fetch_changesets 70 if @repository.scm.supports_cat?
60 cat = @repository.cat("sources/welcome_controller.rb", 2) 71 @repository.fetch_changesets
61 assert_not_nil cat 72 cat = @repository.cat("sources/welcome_controller.rb", 2)
62 assert cat.include?('class WelcomeController < ApplicationController') 73 assert_not_nil cat
74 assert cat.include?('class WelcomeController < ApplicationController')
75 end
63 end 76 end
64 else 77 else
65 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!" 78 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
66 def test_fake; assert true end 79 def test_fake; assert true end
67 end 80 end