##// END OF EJS Templates
scm: bazaar: update test repository (#2799, #4741, #8030)....
Toshi MARUYAMA -
r5812:9fa4fff48ae2
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -1,150 +1,151
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesBazaarControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles,
26 26 :repositories, :enabled_modules
27 27
28 28 # No '..' in the repository path
29 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
29 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') +
30 '/tmp/test/bazaar_repository/trunk'
30 31 PRJ_ID = 3
31 32
32 33 def setup
33 34 @controller = RepositoriesController.new
34 35 @request = ActionController::TestRequest.new
35 36 @response = ActionController::TestResponse.new
36 37 User.current = nil
37 38 @project = Project.find(PRJ_ID)
38 39 @repository = Repository::Bazaar.create(
39 40 :project => @project,
40 41 :url => REPOSITORY_PATH,
41 42 :log_encoding => 'UTF-8')
42 43 assert @repository
43 44 end
44 45
45 46 if File.directory?(REPOSITORY_PATH)
46 47 def test_browse_root
47 48 get :show, :id => PRJ_ID
48 49 assert_response :success
49 50 assert_template 'show'
50 51 assert_not_nil assigns(:entries)
51 52 assert_equal 2, assigns(:entries).size
52 53 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
53 54 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
54 55 end
55 56
56 57 def test_browse_directory
57 58 get :show, :id => PRJ_ID, :path => ['directory']
58 59 assert_response :success
59 60 assert_template 'show'
60 61 assert_not_nil assigns(:entries)
61 62 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
62 63 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
63 64 assert_not_nil entry
64 65 assert_equal 'file', entry.kind
65 66 assert_equal 'directory/edit.png', entry.path
66 67 end
67 68
68 69 def test_browse_at_given_revision
69 70 get :show, :id => PRJ_ID, :path => [], :rev => 3
70 71 assert_response :success
71 72 assert_template 'show'
72 73 assert_not_nil assigns(:entries)
73 74 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
74 75 assigns(:entries).collect(&:name)
75 76 end
76 77
77 78 def test_changes
78 79 get :changes, :id => PRJ_ID, :path => ['doc-mkdir.txt']
79 80 assert_response :success
80 81 assert_template 'changes'
81 82 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
82 83 end
83 84
84 85 def test_entry_show
85 86 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt']
86 87 assert_response :success
87 88 assert_template 'entry'
88 89 # Line 19
89 90 assert_tag :tag => 'th',
90 91 :content => /29/,
91 92 :attributes => { :class => /line-num/ },
92 93 :sibling => { :tag => 'td', :content => /Show help message/ }
93 94 end
94 95
95 96 def test_entry_download
96 97 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'], :format => 'raw'
97 98 assert_response :success
98 99 # File content
99 100 assert @response.body.include?('Show help message')
100 101 end
101 102
102 103 def test_directory_entry
103 104 get :entry, :id => PRJ_ID, :path => ['directory']
104 105 assert_response :success
105 106 assert_template 'show'
106 107 assert_not_nil assigns(:entry)
107 108 assert_equal 'directory', assigns(:entry).name
108 109 end
109 110
110 111 def test_diff
111 112 # Full diff of changeset 3
112 113 get :diff, :id => PRJ_ID, :rev => 3
113 114 assert_response :success
114 115 assert_template 'diff'
115 116 # Line 11 removed
116 117 assert_tag :tag => 'th',
117 118 :content => /11/,
118 119 :sibling => { :tag => 'td',
119 120 :attributes => { :class => /diff_out/ },
120 121 :content => /Display more information/ }
121 122 end
122 123
123 124 def test_annotate
124 125 get :annotate, :id => PRJ_ID, :path => ['doc-mkdir.txt']
125 126 assert_response :success
126 127 assert_template 'annotate'
127 128 assert_tag :tag => 'th', :content => '2',
128 129 :sibling => {
129 130 :tag => 'td',
130 131 :child => {
131 132 :tag => 'a',
132 133 :content => /3/
133 134 }
134 135 },
135 136 :sibling => { :tag => 'td', :content => /jsmith/ }
136 137 assert_tag :tag => 'th', :content => '2',
137 138 :sibling => {
138 139 :tag => 'td',
139 140 :child => {
140 141 :tag => 'a',
141 142 :content => /3/
142 143 }
143 144 },
144 145 :sibling => { :tag => 'td', :content => /Main purpose/ }
145 146 end
146 147 else
147 148 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
148 149 def test_fake; assert true end
149 150 end
150 151 end
@@ -1,132 +1,133
1 1 require File.expand_path('../../../../../../test_helper', __FILE__)
2 2 begin
3 3 require 'mocha'
4 4
5 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\/\.\.}, '') +
8 '/tmp/test/bazaar_repository/trunk'
8 9 REPOSITORY_PATH.gsub!(/\/+/, '/')
9 10
10 11 if File.directory?(REPOSITORY_PATH)
11 12 def setup
12 13 @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(REPOSITORY_PATH)
13 14 end
14 15
15 16 def test_scm_version
16 17 to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2],
17 18 "2.1.1\n1.7\n1.8" => [2,1,1],
18 19 "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]}
19 20 to_test.each do |s, v|
20 21 test_scm_version_for(s, v)
21 22 end
22 23 end
23 24
24 25 def test_cat
25 26 cat = @adapter.cat('directory/document.txt')
26 27 assert cat =~ /Write the contents of a file as of a given revision to standard output/
27 28 end
28 29
29 30 def test_cat_path_invalid
30 31 assert_nil @adapter.cat('invalid')
31 32 end
32 33
33 34 def test_cat_revision_invalid
34 35 assert_nil @adapter.cat('doc-mkdir.txt', '12345678')
35 36 end
36 37
37 38 def test_diff_path_invalid
38 39 assert_equal [], @adapter.diff('invalid', 1)
39 40 end
40 41
41 42 def test_diff_revision_invalid
42 43 assert_equal [], @adapter.diff(nil, 12345678)
43 44 assert_equal [], @adapter.diff(nil, 12345678, 87654321)
44 45 end
45 46
46 47 def test_annotate
47 48 annotate = @adapter.annotate('doc-mkdir.txt')
48 49 assert_equal 17, annotate.lines.size
49 50 assert_equal '1', annotate.revisions[0].identifier
50 51 assert_equal 'jsmith@', annotate.revisions[0].author
51 52 assert_equal 'mkdir', annotate.lines[0]
52 53 end
53 54
54 55 def test_annotate_path_invalid
55 56 assert_nil @adapter.annotate('invalid')
56 57 end
57 58
58 59 def test_annotate_revision_invalid
59 60 assert_nil @adapter.annotate('doc-mkdir.txt', '12345678')
60 61 end
61 62
62 63 def test_branch_conf_path
63 64 p = "c:\\test\\test\\"
64 65 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
65 66 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
66 67 p = "c:\\test\\test\\.bzr"
67 68 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
68 69 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
69 70 p = "c:\\test\\test\\.bzr\\"
70 71 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
71 72 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
72 73 p = "c:\\test\\test"
73 74 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
74 75 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
75 76 p = "\\\\server\\test\\test\\"
76 77 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
77 78 assert_equal File.join("\\\\server\\test\\test", ".bzr", "branch", "branch.conf"), bcp
78 79 end
79 80
80 81 def test_append_revisions_only
81 assert_equal false, @adapter.append_revisions_only
82 assert_equal true, @adapter.append_revisions_only
82 83 end
83 84
84 85 def test_info_not_nil
85 86 assert_not_nil @adapter.info
86 87 end
87 88
88 89 def test_info_nil
89 90 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
90 91 "/invalid/invalid/"
91 92 )
92 93 assert_nil adpt.info
93 94 end
94 95
95 96 def test_info
96 97 info = @adapter.info
97 98 assert_equal 4, info.lastrev.identifier.to_i
98 99 end
99 100
100 101 def test_entries_path_invalid
101 102 assert_equal [], @adapter.entries('invalid')
102 103 end
103 104
104 105 def test_entries_revision_invalid
105 106 assert_nil @adapter.entries(nil, 12345678)
106 107 end
107 108
108 109 def test_revisions_path_invalid
109 110 assert_nil @adapter.revisions('invalid')
110 111 end
111 112
112 113 def test_revisions_revision_invalid
113 114 assert_nil @adapter.revisions(nil, 12345678)
114 115 assert_nil @adapter.revisions(nil, 12345678, 87654321)
115 116 end
116 117
117 118 private
118 119
119 120 def test_scm_version_for(scm_command_version, version)
120 121 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
121 122 assert_equal version, @adapter.class.scm_command_version
122 123 end
123 124 else
124 125 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
125 126 def test_fake; assert true end
126 127 end
127 128 end
128 129 rescue LoadError
129 130 class BazaarMochaFake < ActiveSupport::TestCase
130 131 def test_fake; assert(false, "Requires mocha to run those tests") end
131 132 end
132 133 end
@@ -1,106 +1,107
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryBazaarTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 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\/\.\.}, '') +
25 '/tmp/test/bazaar_repository/trunk'
25 26 REPOSITORY_PATH.gsub!(/\/+/, '/')
26 27
27 28 def setup
28 29 @project = Project.find(3)
29 30 @repository = Repository::Bazaar.create(
30 31 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
31 32 :log_encoding => 'UTF-8')
32 33 assert @repository
33 34 end
34 35
35 36 if File.directory?(REPOSITORY_PATH)
36 37 def test_fetch_changesets_from_scratch
37 38 @repository.fetch_changesets
38 39 @repository.reload
39 40
40 41 assert_equal 4, @repository.changesets.count
41 42 assert_equal 9, @repository.changes.count
42 43 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
43 44 end
44 45
45 46 def test_fetch_changesets_incremental
46 47 @repository.fetch_changesets
47 48 # Remove changesets with revision > 5
48 49 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
49 50 @repository.reload
50 51 assert_equal 2, @repository.changesets.count
51 52
52 53 @repository.fetch_changesets
53 54 assert_equal 4, @repository.changesets.count
54 55 end
55 56
56 57 def test_entries
57 58 entries = @repository.entries
58 59 assert_equal 2, entries.size
59 60
60 61 assert_equal 'dir', entries[0].kind
61 62 assert_equal 'directory', entries[0].name
62 63
63 64 assert_equal 'file', entries[1].kind
64 65 assert_equal 'doc-mkdir.txt', entries[1].name
65 66 end
66 67
67 68 def test_entries_in_subdirectory
68 69 entries = @repository.entries('directory')
69 70 assert_equal 3, entries.size
70 71
71 72 assert_equal 'file', entries.last.kind
72 73 assert_equal 'edit.png', entries.last.name
73 74 end
74 75
75 76 def test_previous
76 77 @repository.fetch_changesets
77 78 @repository.reload
78 79 changeset = @repository.find_changeset_by_name('3')
79 80 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
80 81 end
81 82
82 83 def test_previous_nil
83 84 @repository.fetch_changesets
84 85 @repository.reload
85 86 changeset = @repository.find_changeset_by_name('1')
86 87 assert_nil changeset.previous
87 88 end
88 89
89 90 def test_next
90 91 @repository.fetch_changesets
91 92 @repository.reload
92 93 changeset = @repository.find_changeset_by_name('2')
93 94 assert_equal @repository.find_changeset_by_name('3'), changeset.next
94 95 end
95 96
96 97 def test_next_nil
97 98 @repository.fetch_changesets
98 99 @repository.reload
99 100 changeset = @repository.find_changeset_by_name('4')
100 101 assert_nil changeset.next
101 102 end
102 103 else
103 104 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
104 105 def test_fake; assert true end
105 106 end
106 107 end
General Comments 0
You need to be logged in to leave comments. Login now