@@ -1,41 +1,54 | |||||
1 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
1 | require File.expand_path('../../../../../../test_helper', __FILE__) | |
2 | begin |
|
2 | begin | |
3 | require 'mocha' |
|
3 | require 'mocha' | |
4 |
|
4 | |||
5 | class BazaarAdapterTest < ActiveSupport::TestCase |
|
5 | class BazaarAdapterTest < ActiveSupport::TestCase | |
6 |
|
6 | |||
7 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository' |
|
7 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository' | |
8 | REPOSITORY_PATH.gsub!(/\/+/, '/') |
|
8 | REPOSITORY_PATH.gsub!(/\/+/, '/') | |
9 |
|
9 | |||
10 | if File.directory?(REPOSITORY_PATH) |
|
10 | if File.directory?(REPOSITORY_PATH) | |
11 | def setup |
|
11 | def setup | |
12 | @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(REPOSITORY_PATH) |
|
12 | @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(REPOSITORY_PATH) | |
13 | end |
|
13 | end | |
14 |
|
14 | |||
15 | def test_scm_version |
|
15 | def test_scm_version | |
16 | to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2], |
|
16 | to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2], | |
17 | "2.1.1\n1.7\n1.8" => [2,1,1], |
|
17 | "2.1.1\n1.7\n1.8" => [2,1,1], | |
18 | "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]} |
|
18 | "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]} | |
19 | to_test.each do |s, v| |
|
19 | to_test.each do |s, v| | |
20 | test_scm_version_for(s, v) |
|
20 | test_scm_version_for(s, v) | |
21 | end |
|
21 | end | |
22 | end |
|
22 | end | |
23 |
|
23 | |||
|
24 | def test_cat | |||
|
25 | cat = @adapter.cat('directory/document.txt') | |||
|
26 | assert cat =~ /Write the contents of a file as of a given revision to standard output/ | |||
|
27 | end | |||
|
28 | ||||
|
29 | def test_annotate | |||
|
30 | annotate = @adapter.annotate('doc-mkdir.txt') | |||
|
31 | assert_equal 17, annotate.lines.size | |||
|
32 | assert_equal '1', annotate.revisions[0].identifier | |||
|
33 | assert_equal 'jsmith@', annotate.revisions[0].author | |||
|
34 | assert_equal 'mkdir', annotate.lines[0] | |||
|
35 | end | |||
|
36 | ||||
24 | private |
|
37 | private | |
25 |
|
38 | |||
26 | def test_scm_version_for(scm_command_version, version) |
|
39 | def test_scm_version_for(scm_command_version, version) | |
27 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) |
|
40 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) | |
28 | assert_equal version, @adapter.class.scm_command_version |
|
41 | assert_equal version, @adapter.class.scm_command_version | |
29 | end |
|
42 | end | |
30 | else |
|
43 | else | |
31 | puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" |
|
44 | puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" | |
32 | def test_fake; assert true end |
|
45 | def test_fake; assert true end | |
33 | end |
|
46 | end | |
34 | end |
|
47 | end | |
35 |
|
48 | |||
36 | rescue LoadError |
|
49 | rescue LoadError | |
37 | class BazaarMochaFake < ActiveSupport::TestCase |
|
50 | class BazaarMochaFake < ActiveSupport::TestCase | |
38 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
51 | def test_fake; assert(false, "Requires mocha to run those tests") end | |
39 | end |
|
52 | end | |
40 | end |
|
53 | end | |
41 |
|
54 |
@@ -1,88 +1,75 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 | # 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(1) | |
29 | assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}") |
|
29 | assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}") | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | if File.directory?(REPOSITORY_PATH) |
|
32 | if File.directory?(REPOSITORY_PATH) | |
33 | def test_fetch_changesets_from_scratch |
|
33 | def test_fetch_changesets_from_scratch | |
34 | @repository.fetch_changesets |
|
34 | @repository.fetch_changesets | |
35 | @repository.reload |
|
35 | @repository.reload | |
36 |
|
36 | |||
37 | assert_equal 4, @repository.changesets.count |
|
37 | assert_equal 4, @repository.changesets.count | |
38 | assert_equal 9, @repository.changes.count |
|
38 | assert_equal 9, @repository.changes.count | |
39 | assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments |
|
39 | assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_fetch_changesets_incremental |
|
42 | def test_fetch_changesets_incremental | |
43 | @repository.fetch_changesets |
|
43 | @repository.fetch_changesets | |
44 | # Remove changesets with revision > 5 |
|
44 | # Remove changesets with revision > 5 | |
45 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
|
45 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | |
46 | @repository.reload |
|
46 | @repository.reload | |
47 | assert_equal 2, @repository.changesets.count |
|
47 | assert_equal 2, @repository.changesets.count | |
48 |
|
48 | |||
49 | @repository.fetch_changesets |
|
49 | @repository.fetch_changesets | |
50 | assert_equal 4, @repository.changesets.count |
|
50 | assert_equal 4, @repository.changesets.count | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_entries |
|
53 | def test_entries | |
54 | entries = @repository.entries |
|
54 | entries = @repository.entries | |
55 | assert_equal 2, entries.size |
|
55 | assert_equal 2, entries.size | |
56 |
|
56 | |||
57 | assert_equal 'dir', entries[0].kind |
|
57 | assert_equal 'dir', entries[0].kind | |
58 | assert_equal 'directory', entries[0].name |
|
58 | assert_equal 'directory', entries[0].name | |
59 |
|
59 | |||
60 | assert_equal 'file', entries[1].kind |
|
60 | assert_equal 'file', entries[1].kind | |
61 | assert_equal 'doc-mkdir.txt', entries[1].name |
|
61 | assert_equal 'doc-mkdir.txt', entries[1].name | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_entries_in_subdirectory |
|
64 | def test_entries_in_subdirectory | |
65 | entries = @repository.entries('directory') |
|
65 | entries = @repository.entries('directory') | |
66 | assert_equal 3, entries.size |
|
66 | assert_equal 3, entries.size | |
67 |
|
67 | |||
68 | assert_equal 'file', entries.last.kind |
|
68 | assert_equal 'file', entries.last.kind | |
69 | assert_equal 'edit.png', entries.last.name |
|
69 | assert_equal 'edit.png', entries.last.name | |
70 | end |
|
70 | end | |
71 |
|
||||
72 | def test_cat |
|
|||
73 | cat = @repository.scm.cat('directory/document.txt') |
|
|||
74 | assert cat =~ /Write the contents of a file as of a given revision to standard output/ |
|
|||
75 | end |
|
|||
76 |
|
||||
77 | def test_annotate |
|
|||
78 | annotate = @repository.scm.annotate('doc-mkdir.txt') |
|
|||
79 | assert_equal 17, annotate.lines.size |
|
|||
80 | assert_equal '1', annotate.revisions[0].identifier |
|
|||
81 | assert_equal 'jsmith@', annotate.revisions[0].author |
|
|||
82 | assert_equal 'mkdir', annotate.lines[0] |
|
|||
83 | end |
|
|||
84 | else |
|
71 | else | |
85 | puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" |
|
72 | puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!" | |
86 | def test_fake; assert true end |
|
73 | def test_fake; assert true end | |
87 | end |
|
74 | end | |
88 | end |
|
75 | end |
General Comments 0
You need to be logged in to leave comments.
Login now