##// END OF EJS Templates
Merged r4635 from trunk....
Toshi MARUYAMA -
r4521:ea60705ca74a
parent child
Show More
@@ -1,157 +1,171
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26
26
27 # No '..' in the repository path
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
29
29
30 def setup
30 def setup
31 @controller = RepositoriesController.new
31 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new
32 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new
33 @response = ActionController::TestResponse.new
34 User.current = nil
34 User.current = nil
35 Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
35 Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 end
36 end
37
37
38 if File.directory?(REPOSITORY_PATH)
38 if File.directory?(REPOSITORY_PATH)
39 def test_show
39 def test_show
40 get :show, :id => 3
40 get :show, :id => 3
41 assert_response :success
41 assert_response :success
42 assert_template 'show'
42 assert_template 'show'
43 assert_not_nil assigns(:entries)
43 assert_not_nil assigns(:entries)
44 assert_not_nil assigns(:changesets)
44 assert_not_nil assigns(:changesets)
45 end
45 end
46
46
47 def test_show_root
47 def test_show_root
48 get :show, :id => 3
48 get :show, :id => 3
49 assert_response :success
49 assert_response :success
50 assert_template 'show'
50 assert_template 'show'
51 assert_not_nil assigns(:entries)
51 assert_not_nil assigns(:entries)
52 assert_equal 4, assigns(:entries).size
52 assert_equal 4, assigns(:entries).size
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
56 end
56 end
57
57
58 def test_show_directory
58 def test_show_directory
59 get :show, :id => 3, :path => ['images']
59 get :show, :id => 3, :path => ['images']
60 assert_response :success
60 assert_response :success
61 assert_template 'show'
61 assert_template 'show'
62 assert_not_nil assigns(:entries)
62 assert_not_nil assigns(:entries)
63 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
63 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
65 assert_not_nil entry
65 assert_not_nil entry
66 assert_equal 'file', entry.kind
66 assert_equal 'file', entry.kind
67 assert_equal 'images/edit.png', entry.path
67 assert_equal 'images/edit.png', entry.path
68 end
68 end
69
69
70 def test_show_at_given_revision
70 def test_show_at_given_revision
71 get :show, :id => 3, :path => ['images'], :rev => 0
71 get :show, :id => 3, :path => ['images'], :rev => 0
72 assert_response :success
72 assert_response :success
73 assert_template 'show'
73 assert_template 'show'
74 assert_not_nil assigns(:entries)
74 assert_not_nil assigns(:entries)
75 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
75 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
76 end
76 end
77
77
78 def test_show_directory_sql_escape_percent
79 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => 13
80 assert_response :success
81 assert_template 'show'
82
83 assert_not_nil assigns(:entries)
84 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
85 changesets = assigns(:changesets)
86
87 ## This is not yet implemented.
88 # assert_not_nil changesets
89 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
90 end
91
78 def test_changes
92 def test_changes
79 get :changes, :id => 3, :path => ['images', 'edit.png']
93 get :changes, :id => 3, :path => ['images', 'edit.png']
80 assert_response :success
94 assert_response :success
81 assert_template 'changes'
95 assert_template 'changes'
82 assert_tag :tag => 'h2', :content => 'edit.png'
96 assert_tag :tag => 'h2', :content => 'edit.png'
83 end
97 end
84
98
85 def test_entry_show
99 def test_entry_show
86 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
100 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
87 assert_response :success
101 assert_response :success
88 assert_template 'entry'
102 assert_template 'entry'
89 # Line 10
103 # Line 10
90 assert_tag :tag => 'th',
104 assert_tag :tag => 'th',
91 :content => '10',
105 :content => '10',
92 :attributes => { :class => 'line-num' },
106 :attributes => { :class => 'line-num' },
93 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
107 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
94 end
108 end
95
109
96 def test_entry_download
110 def test_entry_download
97 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
111 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
98 assert_response :success
112 assert_response :success
99 # File content
113 # File content
100 assert @response.body.include?('WITHOUT ANY WARRANTY')
114 assert @response.body.include?('WITHOUT ANY WARRANTY')
101 end
115 end
102
116
103 def test_directory_entry
117 def test_directory_entry
104 get :entry, :id => 3, :path => ['sources']
118 get :entry, :id => 3, :path => ['sources']
105 assert_response :success
119 assert_response :success
106 assert_template 'show'
120 assert_template 'show'
107 assert_not_nil assigns(:entry)
121 assert_not_nil assigns(:entry)
108 assert_equal 'sources', assigns(:entry).name
122 assert_equal 'sources', assigns(:entry).name
109 end
123 end
110
124
111 def test_diff
125 def test_diff
112 # Full diff of changeset 4
126 # Full diff of changeset 4
113 get :diff, :id => 3, :rev => 4
127 get :diff, :id => 3, :rev => 4
114 assert_response :success
128 assert_response :success
115 assert_template 'diff'
129 assert_template 'diff'
116 # Line 22 removed
130 # Line 22 removed
117 assert_tag :tag => 'th',
131 assert_tag :tag => 'th',
118 :content => '22',
132 :content => '22',
119 :sibling => { :tag => 'td',
133 :sibling => { :tag => 'td',
120 :attributes => { :class => /diff_out/ },
134 :attributes => { :class => /diff_out/ },
121 :content => /def remove/ }
135 :content => /def remove/ }
122 end
136 end
123
137
124 def test_annotate
138 def test_annotate
125 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
139 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
126 assert_response :success
140 assert_response :success
127 assert_template 'annotate'
141 assert_template 'annotate'
128 # Line 23, revision 4:def6d2f1254a
142 # Line 23, revision 4:def6d2f1254a
129 assert_tag :tag => 'th',
143 assert_tag :tag => 'th',
130 :content => '23',
144 :content => '23',
131 :attributes => { :class => 'line-num' },
145 :attributes => { :class => 'line-num' },
132 :sibling =>
146 :sibling =>
133 {
147 {
134 :tag => 'td',
148 :tag => 'td',
135 :attributes => { :class => 'revision' },
149 :attributes => { :class => 'revision' },
136 :child => { :tag => 'a', :content => '4' }
150 :child => { :tag => 'a', :content => '4' }
137 # :child => { :tag => 'a', :content => /4:def6d2f1/ }
151 # :child => { :tag => 'a', :content => /4:def6d2f1/ }
138 }
152 }
139 assert_tag :tag => 'th',
153 assert_tag :tag => 'th',
140 :content => '23',
154 :content => '23',
141 :attributes => { :class => 'line-num' },
155 :attributes => { :class => 'line-num' },
142 :sibling =>
156 :sibling =>
143 {
157 {
144 :tag => 'td' ,
158 :tag => 'td' ,
145 :content => 'jsmith' ,
159 :content => 'jsmith' ,
146 :attributes => { :class => 'author' },
160 :attributes => { :class => 'author' },
147 }
161 }
148 assert_tag :tag => 'th',
162 assert_tag :tag => 'th',
149 :content => '23',
163 :content => '23',
150 :attributes => { :class => 'line-num' },
164 :attributes => { :class => 'line-num' },
151 :sibling => { :tag => 'td', :content => /watcher =/ }
165 :sibling => { :tag => 'td', :content => /watcher =/ }
152 end
166 end
153 else
167 else
154 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
168 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
155 def test_fake; assert true end
169 def test_fake; assert true end
156 end
170 end
157 end
171 end
@@ -1,87 +1,103
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 RepositoryMercurialTest < ActiveSupport::TestCase
20 class RepositoryMercurialTest < 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/mercurial_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
25
25
26 def setup
26 def setup
27 @project = Project.find(1)
27 @project = Project.find(1)
28 assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
28 assert @repository = Repository::Mercurial.create(:project => @project, :url => REPOSITORY_PATH)
29 end
29 end
30
30
31 if File.directory?(REPOSITORY_PATH)
31 if File.directory?(REPOSITORY_PATH)
32 def test_fetch_changesets_from_scratch
32 def test_fetch_changesets_from_scratch
33 @repository.fetch_changesets
33 @repository.fetch_changesets
34 @repository.reload
34 @repository.reload
35
35
36 assert_equal 17, @repository.changesets.count
36 assert_equal 17, @repository.changesets.count
37 assert_equal 25, @repository.changes.count
37 assert_equal 25, @repository.changes.count
38 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
38 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find_by_revision('0').comments
39 end
39 end
40
40
41 def test_fetch_changesets_incremental
41 def test_fetch_changesets_incremental
42 @repository.fetch_changesets
42 @repository.fetch_changesets
43 # Remove changesets with revision > 2
43 # Remove changesets with revision > 2
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
44 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
45 @repository.reload
45 @repository.reload
46 assert_equal 3, @repository.changesets.count
46 assert_equal 3, @repository.changesets.count
47
47
48 @repository.fetch_changesets
48 @repository.fetch_changesets
49 assert_equal 17, @repository.changesets.count
49 assert_equal 17, @repository.changesets.count
50 end
50 end
51
51
52 def test_entries
52 def test_entries
53 assert_equal 2, @repository.entries("sources", 2).size
53 assert_equal 2, @repository.entries("sources", 2).size
54 assert_equal 1, @repository.entries("sources", 3).size
54 assert_equal 1, @repository.entries("sources", 3).size
55 end
55 end
56
56
57 def test_locate_on_outdated_repository
57 def test_locate_on_outdated_repository
58 assert_equal 1, @repository.entries("images", 0).size
58 assert_equal 1, @repository.entries("images", 0).size
59 assert_equal 2, @repository.entries("images").size
59 assert_equal 2, @repository.entries("images").size
60 assert_equal 2, @repository.entries("images", 2).size
60 assert_equal 2, @repository.entries("images", 2).size
61 end
61 end
62
62
63 def test_isodatesec
63 def test_isodatesec
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
64 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
65 if @repository.scm.class.client_version_above?([1, 0])
65 if @repository.scm.class.client_version_above?([1, 0])
66 @repository.fetch_changesets
66 @repository.fetch_changesets
67 @repository.reload
67 @repository.reload
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
68 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
69 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
70 end
70 end
71 end
71 end
72
72
73 def test_changeset_order_by_revision
73 def test_changeset_order_by_revision
74 @repository.fetch_changesets
74 @repository.fetch_changesets
75 @repository.reload
75 @repository.reload
76
76
77 c0 = @repository.latest_changeset
77 c0 = @repository.latest_changeset
78 c1 = @repository.changesets.find_by_revision('0')
78 c1 = @repository.changesets.find_by_revision('0')
79 # sorted by revision (id), not by date
79 # sorted by revision (id), not by date
80 assert c0.revision.to_i > c1.revision.to_i
80 assert c0.revision.to_i > c1.revision.to_i
81 assert c0.committed_on < c1.committed_on
81 assert c0.committed_on < c1.committed_on
82 end
82 end
83
84 def test_latest_changesets
85 @repository.fetch_changesets
86 @repository.reload
87
88 # with_limit
89 changesets = @repository.latest_changesets('', nil, 2)
90 assert_equal @repository.latest_changesets('', nil)[0, 2], changesets
91
92 # with_filepath
93 changesets = @repository.latest_changesets('/sql_escape/percent%dir/percent%file1.txt', nil)
94 assert_equal %w|11 10 9|, changesets.collect(&:revision)
95
96 changesets = @repository.latest_changesets('/sql_escape/underscore_dir/understrike_file.txt', nil)
97 assert_equal %w|12 9|, changesets.collect(&:revision)
98 end
83 else
99 else
84 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
100 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
85 def test_fake; assert true end
101 def test_fake; assert true end
86 end
102 end
87 end
103 end
General Comments 0
You need to be logged in to leave comments. Login now