comparison test/unit/repository_bazaar_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 RepositoryBazaarTest < ActiveSupport::TestCase 20 class RepositoryBazaarTest < 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/bazaar_repository' 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
25 REPOSITORY_PATH.gsub!(/\/+/, '/') 25 REPOSITORY_PATH.gsub!(/\/+/, '/')
26 26
27 def setup 27 def setup
28 @project = Project.find(1) 28 @project = Project.find(3)
29 assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}") 29 @repository = Repository::Bazaar.create(
30 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
31 :log_encoding => 'UTF-8')
32 assert @repository
30 end 33 end
31 34
32 if File.directory?(REPOSITORY_PATH) 35 if File.directory?(REPOSITORY_PATH)
33 def test_fetch_changesets_from_scratch 36 def test_fetch_changesets_from_scratch
34 @repository.fetch_changesets 37 @repository.fetch_changesets
35 @repository.reload 38 @repository.reload
36 39
37 assert_equal 4, @repository.changesets.count 40 assert_equal 4, @repository.changesets.count
38 assert_equal 9, @repository.changes.count 41 assert_equal 9, @repository.changes.count
39 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments 42 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
40 end 43 end
41 44
42 def test_fetch_changesets_incremental 45 def test_fetch_changesets_incremental
43 @repository.fetch_changesets 46 @repository.fetch_changesets
44 # Remove changesets with revision > 5 47 # Remove changesets with revision > 5
45 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} 48 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
46 @repository.reload 49 @repository.reload
47 assert_equal 2, @repository.changesets.count 50 assert_equal 2, @repository.changesets.count
48 51
49 @repository.fetch_changesets 52 @repository.fetch_changesets
50 assert_equal 4, @repository.changesets.count 53 assert_equal 4, @repository.changesets.count
51 end 54 end
52 55
53 def test_entries 56 def test_entries
54 entries = @repository.entries 57 entries = @repository.entries
55 assert_equal 2, entries.size 58 assert_equal 2, entries.size
56 59
57 assert_equal 'dir', entries[0].kind 60 assert_equal 'dir', entries[0].kind
66 assert_equal 3, entries.size 69 assert_equal 3, entries.size
67 70
68 assert_equal 'file', entries.last.kind 71 assert_equal 'file', entries.last.kind
69 assert_equal 'edit.png', entries.last.name 72 assert_equal 'edit.png', entries.last.name
70 end 73 end
71 74
72 def test_cat 75 def test_previous
73 cat = @repository.scm.cat('directory/document.txt') 76 @repository.fetch_changesets
74 assert cat =~ /Write the contents of a file as of a given revision to standard output/ 77 @repository.reload
78 changeset = @repository.find_changeset_by_name('3')
79 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
75 end 80 end
76 81
77 def test_annotate 82 def test_previous_nil
78 annotate = @repository.scm.annotate('doc-mkdir.txt') 83 @repository.fetch_changesets
79 assert_equal 17, annotate.lines.size 84 @repository.reload
80 assert_equal 1, annotate.revisions[0].identifier 85 changeset = @repository.find_changeset_by_name('1')
81 assert_equal 'jsmith@', annotate.revisions[0].author 86 assert_nil changeset.previous
82 assert_equal 'mkdir', annotate.lines[0] 87 end
88
89 def test_next
90 @repository.fetch_changesets
91 @repository.reload
92 changeset = @repository.find_changeset_by_name('2')
93 assert_equal @repository.find_changeset_by_name('3'), changeset.next
94 end
95
96 def test_next_nil
97 @repository.fetch_changesets
98 @repository.reload
99 changeset = @repository.find_changeset_by_name('4')
100 assert_nil changeset.next
83 end 101 end
84 else 102 else
85 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" 103 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
86 def test_fake; assert true end 104 def test_fake; assert true end
87 end 105 end