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