@@ -1,220 +1,217 | |||||
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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
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 RepositoriesSubversionControllerTest < ActionController::TestCase |
|
24 | class RepositoriesSubversionControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, |
|
25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, | |
26 | :repositories, :issues, :issue_statuses, :changesets, :changes, |
|
26 | :repositories, :issues, :issue_statuses, :changesets, :changes, | |
27 | :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers |
|
27 | :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers | |
28 |
|
28 | |||
29 | # No '..' in the repository path for svn |
|
|||
30 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository' |
|
|||
31 |
|
||||
32 | def setup |
|
29 | def setup | |
33 | @controller = RepositoriesController.new |
|
30 | @controller = RepositoriesController.new | |
34 | @request = ActionController::TestRequest.new |
|
31 | @request = ActionController::TestRequest.new | |
35 | @response = ActionController::TestResponse.new |
|
32 | @response = ActionController::TestResponse.new | |
36 | Setting.default_language = 'en' |
|
33 | Setting.default_language = 'en' | |
37 | User.current = nil |
|
34 | User.current = nil | |
38 | end |
|
35 | end | |
39 |
|
36 | |||
40 | if File.directory?(REPOSITORY_PATH) |
|
37 | if repository_configured?('subversion') | |
41 | def test_show |
|
38 | def test_show | |
42 | get :show, :id => 1 |
|
39 | get :show, :id => 1 | |
43 | assert_response :success |
|
40 | assert_response :success | |
44 | assert_template 'show' |
|
41 | assert_template 'show' | |
45 | assert_not_nil assigns(:entries) |
|
42 | assert_not_nil assigns(:entries) | |
46 | assert_not_nil assigns(:changesets) |
|
43 | assert_not_nil assigns(:changesets) | |
47 | end |
|
44 | end | |
48 |
|
45 | |||
49 | def test_browse_root |
|
46 | def test_browse_root | |
50 | get :show, :id => 1 |
|
47 | get :show, :id => 1 | |
51 | assert_response :success |
|
48 | assert_response :success | |
52 | assert_template 'show' |
|
49 | assert_template 'show' | |
53 | assert_not_nil assigns(:entries) |
|
50 | assert_not_nil assigns(:entries) | |
54 | entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} |
|
51 | entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} | |
55 | assert_equal 'dir', entry.kind |
|
52 | assert_equal 'dir', entry.kind | |
56 | end |
|
53 | end | |
57 |
|
54 | |||
58 | def test_browse_directory |
|
55 | def test_browse_directory | |
59 | get :show, :id => 1, :path => ['subversion_test'] |
|
56 | get :show, :id => 1, :path => ['subversion_test'] | |
60 | assert_response :success |
|
57 | assert_response :success | |
61 | assert_template 'show' |
|
58 | assert_template 'show' | |
62 | assert_not_nil assigns(:entries) |
|
59 | assert_not_nil assigns(:entries) | |
63 | assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name) |
|
60 | assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name) | |
64 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} |
|
61 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} | |
65 | assert_equal 'file', entry.kind |
|
62 | assert_equal 'file', entry.kind | |
66 | assert_equal 'subversion_test/helloworld.c', entry.path |
|
63 | assert_equal 'subversion_test/helloworld.c', entry.path | |
67 | assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } |
|
64 | assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } | |
68 | end |
|
65 | end | |
69 |
|
66 | |||
70 | def test_browse_at_given_revision |
|
67 | def test_browse_at_given_revision | |
71 | get :show, :id => 1, :path => ['subversion_test'], :rev => 4 |
|
68 | get :show, :id => 1, :path => ['subversion_test'], :rev => 4 | |
72 | assert_response :success |
|
69 | assert_response :success | |
73 | assert_template 'show' |
|
70 | assert_template 'show' | |
74 | assert_not_nil assigns(:entries) |
|
71 | assert_not_nil assigns(:entries) | |
75 | assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) |
|
72 | assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) | |
76 | end |
|
73 | end | |
77 |
|
74 | |||
78 | def test_file_changes |
|
75 | def test_file_changes | |
79 | get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ] |
|
76 | get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ] | |
80 | assert_response :success |
|
77 | assert_response :success | |
81 | assert_template 'changes' |
|
78 | assert_template 'changes' | |
82 |
|
79 | |||
83 | changesets = assigns(:changesets) |
|
80 | changesets = assigns(:changesets) | |
84 | assert_not_nil changesets |
|
81 | assert_not_nil changesets | |
85 | assert_equal %w(6 3 2), changesets.collect(&:revision) |
|
82 | assert_equal %w(6 3 2), changesets.collect(&:revision) | |
86 |
|
83 | |||
87 | # svn properties displayed with svn >= 1.5 only |
|
84 | # svn properties displayed with svn >= 1.5 only | |
88 | if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) |
|
85 | if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) | |
89 | assert_not_nil assigns(:properties) |
|
86 | assert_not_nil assigns(:properties) | |
90 | assert_equal 'native', assigns(:properties)['svn:eol-style'] |
|
87 | assert_equal 'native', assigns(:properties)['svn:eol-style'] | |
91 | assert_tag :ul, |
|
88 | assert_tag :ul, | |
92 | :child => { :tag => 'li', |
|
89 | :child => { :tag => 'li', | |
93 | :child => { :tag => 'b', :content => 'svn:eol-style' }, |
|
90 | :child => { :tag => 'b', :content => 'svn:eol-style' }, | |
94 | :child => { :tag => 'span', :content => 'native' } } |
|
91 | :child => { :tag => 'span', :content => 'native' } } | |
95 | end |
|
92 | end | |
96 | end |
|
93 | end | |
97 |
|
94 | |||
98 | def test_directory_changes |
|
95 | def test_directory_changes | |
99 | get :changes, :id => 1, :path => ['subversion_test', 'folder' ] |
|
96 | get :changes, :id => 1, :path => ['subversion_test', 'folder' ] | |
100 | assert_response :success |
|
97 | assert_response :success | |
101 | assert_template 'changes' |
|
98 | assert_template 'changes' | |
102 |
|
99 | |||
103 | changesets = assigns(:changesets) |
|
100 | changesets = assigns(:changesets) | |
104 | assert_not_nil changesets |
|
101 | assert_not_nil changesets | |
105 | assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) |
|
102 | assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) | |
106 | end |
|
103 | end | |
107 |
|
104 | |||
108 | def test_entry |
|
105 | def test_entry | |
109 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] |
|
106 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] | |
110 | assert_response :success |
|
107 | assert_response :success | |
111 | assert_template 'entry' |
|
108 | assert_template 'entry' | |
112 | end |
|
109 | end | |
113 |
|
110 | |||
114 | def test_entry_should_send_if_too_big |
|
111 | def test_entry_should_send_if_too_big | |
115 | # no files in the test repo is larger than 1KB... |
|
112 | # no files in the test repo is larger than 1KB... | |
116 | with_settings :file_max_size_displayed => 0 do |
|
113 | with_settings :file_max_size_displayed => 0 do | |
117 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] |
|
114 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] | |
118 | assert_response :success |
|
115 | assert_response :success | |
119 | assert_template '' |
|
116 | assert_template '' | |
120 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
|
117 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] | |
121 | end |
|
118 | end | |
122 | end |
|
119 | end | |
123 |
|
120 | |||
124 | def test_entry_at_given_revision |
|
121 | def test_entry_at_given_revision | |
125 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 |
|
122 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 | |
126 | assert_response :success |
|
123 | assert_response :success | |
127 | assert_template 'entry' |
|
124 | assert_template 'entry' | |
128 | # this line was removed in r3 and file was moved in r6 |
|
125 | # this line was removed in r3 and file was moved in r6 | |
129 | assert_tag :tag => 'td', :attributes => { :class => /line-code/}, |
|
126 | assert_tag :tag => 'td', :attributes => { :class => /line-code/}, | |
130 | :content => /Here's the code/ |
|
127 | :content => /Here's the code/ | |
131 | end |
|
128 | end | |
132 |
|
129 | |||
133 | def test_entry_not_found |
|
130 | def test_entry_not_found | |
134 | get :entry, :id => 1, :path => ['subversion_test', 'zzz.c'] |
|
131 | get :entry, :id => 1, :path => ['subversion_test', 'zzz.c'] | |
135 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
132 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
136 | :content => /The entry or revision was not found in the repository/ |
|
133 | :content => /The entry or revision was not found in the repository/ | |
137 | end |
|
134 | end | |
138 |
|
135 | |||
139 | def test_entry_download |
|
136 | def test_entry_download | |
140 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' |
|
137 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' | |
141 | assert_response :success |
|
138 | assert_response :success | |
142 | assert_template '' |
|
139 | assert_template '' | |
143 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
|
140 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] | |
144 | end |
|
141 | end | |
145 |
|
142 | |||
146 | def test_directory_entry |
|
143 | def test_directory_entry | |
147 | get :entry, :id => 1, :path => ['subversion_test', 'folder'] |
|
144 | get :entry, :id => 1, :path => ['subversion_test', 'folder'] | |
148 | assert_response :success |
|
145 | assert_response :success | |
149 | assert_template 'show' |
|
146 | assert_template 'show' | |
150 | assert_not_nil assigns(:entry) |
|
147 | assert_not_nil assigns(:entry) | |
151 | assert_equal 'folder', assigns(:entry).name |
|
148 | assert_equal 'folder', assigns(:entry).name | |
152 | end |
|
149 | end | |
153 |
|
150 | |||
154 | def test_revision |
|
151 | def test_revision | |
155 | get :revision, :id => 1, :rev => 2 |
|
152 | get :revision, :id => 1, :rev => 2 | |
156 | assert_response :success |
|
153 | assert_response :success | |
157 | assert_template 'revision' |
|
154 | assert_template 'revision' | |
158 | assert_tag :tag => 'ul', |
|
155 | assert_tag :tag => 'ul', | |
159 | :child => { :tag => 'li', |
|
156 | :child => { :tag => 'li', | |
160 | # link to the entry at rev 2 |
|
157 | # link to the entry at rev 2 | |
161 | :child => { :tag => 'a', |
|
158 | :child => { :tag => 'a', | |
162 | :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, |
|
159 | :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, | |
163 | :content => 'repo', |
|
160 | :content => 'repo', | |
164 | # link to partial diff |
|
161 | # link to partial diff | |
165 | :sibling => { :tag => 'a', |
|
162 | :sibling => { :tag => 'a', | |
166 | :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } |
|
163 | :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } | |
167 | } |
|
164 | } | |
168 | } |
|
165 | } | |
169 | } |
|
166 | } | |
170 | end |
|
167 | end | |
171 |
|
168 | |||
172 | def test_revision_with_repository_pointing_to_a_subdirectory |
|
169 | def test_revision_with_repository_pointing_to_a_subdirectory | |
173 | r = Project.find(1).repository |
|
170 | r = Project.find(1).repository | |
174 | # Changes repository url to a subdirectory |
|
171 | # Changes repository url to a subdirectory | |
175 | r.update_attribute :url, (r.url + '/test/some') |
|
172 | r.update_attribute :url, (r.url + '/test/some') | |
176 |
|
173 | |||
177 | get :revision, :id => 1, :rev => 2 |
|
174 | get :revision, :id => 1, :rev => 2 | |
178 | assert_response :success |
|
175 | assert_response :success | |
179 | assert_template 'revision' |
|
176 | assert_template 'revision' | |
180 | assert_tag :tag => 'ul', |
|
177 | assert_tag :tag => 'ul', | |
181 | :child => { :tag => 'li', |
|
178 | :child => { :tag => 'li', | |
182 | # link to the entry at rev 2 |
|
179 | # link to the entry at rev 2 | |
183 | :child => { :tag => 'a', |
|
180 | :child => { :tag => 'a', | |
184 | :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, |
|
181 | :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, | |
185 | :content => 'repo', |
|
182 | :content => 'repo', | |
186 | # link to partial diff |
|
183 | # link to partial diff | |
187 | :sibling => { :tag => 'a', |
|
184 | :sibling => { :tag => 'a', | |
188 | :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } |
|
185 | :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } | |
189 | } |
|
186 | } | |
190 | } |
|
187 | } | |
191 | } |
|
188 | } | |
192 | end |
|
189 | end | |
193 |
|
190 | |||
194 | def test_revision_diff |
|
191 | def test_revision_diff | |
195 | get :diff, :id => 1, :rev => 3 |
|
192 | get :diff, :id => 1, :rev => 3 | |
196 | assert_response :success |
|
193 | assert_response :success | |
197 | assert_template 'diff' |
|
194 | assert_template 'diff' | |
198 | end |
|
195 | end | |
199 |
|
196 | |||
200 | def test_directory_diff |
|
197 | def test_directory_diff | |
201 | get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] |
|
198 | get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] | |
202 | assert_response :success |
|
199 | assert_response :success | |
203 | assert_template 'diff' |
|
200 | assert_template 'diff' | |
204 |
|
201 | |||
205 | diff = assigns(:diff) |
|
202 | diff = assigns(:diff) | |
206 | assert_not_nil diff |
|
203 | assert_not_nil diff | |
207 | # 2 files modified |
|
204 | # 2 files modified | |
208 | assert_equal 2, Redmine::UnifiedDiff.new(diff).size |
|
205 | assert_equal 2, Redmine::UnifiedDiff.new(diff).size | |
209 | end |
|
206 | end | |
210 |
|
207 | |||
211 | def test_annotate |
|
208 | def test_annotate | |
212 | get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c'] |
|
209 | get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c'] | |
213 | assert_response :success |
|
210 | assert_response :success | |
214 | assert_template 'annotate' |
|
211 | assert_template 'annotate' | |
215 | end |
|
212 | end | |
216 | else |
|
213 | else | |
217 | puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" |
|
214 | puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" | |
218 | def test_fake; assert true end |
|
215 | def test_fake; assert true end | |
219 | end |
|
216 | end | |
220 | end |
|
217 | end |
@@ -1,145 +1,155 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 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 | ENV["RAILS_ENV"] ||= "test" |
|
18 | ENV["RAILS_ENV"] ||= "test" | |
19 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
|
19 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") | |
20 | require 'test_help' |
|
20 | require 'test_help' | |
21 | require File.expand_path(File.dirname(__FILE__) + '/helper_testcase') |
|
21 | require File.expand_path(File.dirname(__FILE__) + '/helper_testcase') | |
22 | require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb') |
|
22 | require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb') | |
23 |
|
23 | |||
24 | require File.expand_path(File.dirname(__FILE__) + '/object_daddy_helpers') |
|
24 | require File.expand_path(File.dirname(__FILE__) + '/object_daddy_helpers') | |
25 | include ObjectDaddyHelpers |
|
25 | include ObjectDaddyHelpers | |
26 |
|
26 | |||
27 | class ActiveSupport::TestCase |
|
27 | class ActiveSupport::TestCase | |
28 | # Transactional fixtures accelerate your tests by wrapping each test method |
|
28 | # Transactional fixtures accelerate your tests by wrapping each test method | |
29 | # in a transaction that's rolled back on completion. This ensures that the |
|
29 | # in a transaction that's rolled back on completion. This ensures that the | |
30 | # test database remains unchanged so your fixtures don't have to be reloaded |
|
30 | # test database remains unchanged so your fixtures don't have to be reloaded | |
31 | # between every test method. Fewer database queries means faster tests. |
|
31 | # between every test method. Fewer database queries means faster tests. | |
32 | # |
|
32 | # | |
33 | # Read Mike Clark's excellent walkthrough at |
|
33 | # Read Mike Clark's excellent walkthrough at | |
34 | # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting |
|
34 | # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting | |
35 | # |
|
35 | # | |
36 | # Every Active Record database supports transactions except MyISAM tables |
|
36 | # Every Active Record database supports transactions except MyISAM tables | |
37 | # in MySQL. Turn off transactional fixtures in this case; however, if you |
|
37 | # in MySQL. Turn off transactional fixtures in this case; however, if you | |
38 | # don't care one way or the other, switching from MyISAM to InnoDB tables |
|
38 | # don't care one way or the other, switching from MyISAM to InnoDB tables | |
39 | # is recommended. |
|
39 | # is recommended. | |
40 | self.use_transactional_fixtures = true |
|
40 | self.use_transactional_fixtures = true | |
41 |
|
41 | |||
42 | # Instantiated fixtures are slow, but give you @david where otherwise you |
|
42 | # Instantiated fixtures are slow, but give you @david where otherwise you | |
43 | # would need people(:david). If you don't want to migrate your existing |
|
43 | # would need people(:david). If you don't want to migrate your existing | |
44 | # test cases which use the @david style and don't mind the speed hit (each |
|
44 | # test cases which use the @david style and don't mind the speed hit (each | |
45 | # instantiated fixtures translates to a database query per test method), |
|
45 | # instantiated fixtures translates to a database query per test method), | |
46 | # then set this back to true. |
|
46 | # then set this back to true. | |
47 | self.use_instantiated_fixtures = false |
|
47 | self.use_instantiated_fixtures = false | |
48 |
|
48 | |||
49 | # Add more helper methods to be used by all tests here... |
|
49 | # Add more helper methods to be used by all tests here... | |
50 |
|
50 | |||
51 | def log_user(login, password) |
|
51 | def log_user(login, password) | |
52 | User.anonymous |
|
52 | User.anonymous | |
53 | get "/login" |
|
53 | get "/login" | |
54 | assert_equal nil, session[:user_id] |
|
54 | assert_equal nil, session[:user_id] | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_template "account/login" |
|
56 | assert_template "account/login" | |
57 | post "/login", :username => login, :password => password |
|
57 | post "/login", :username => login, :password => password | |
58 | assert_equal login, User.find(session[:user_id]).login |
|
58 | assert_equal login, User.find(session[:user_id]).login | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def uploaded_test_file(name, mime) |
|
61 | def uploaded_test_file(name, mime) | |
62 | ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime) |
|
62 | ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime) | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | # Use a temporary directory for attachment related tests |
|
65 | # Use a temporary directory for attachment related tests | |
66 | def set_tmp_attachments_directory |
|
66 | def set_tmp_attachments_directory | |
67 | Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test") |
|
67 | Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test") | |
68 | Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments") |
|
68 | Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments") | |
69 | Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments" |
|
69 | Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments" | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def with_settings(options, &block) |
|
72 | def with_settings(options, &block) | |
73 | saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h} |
|
73 | saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h} | |
74 | options.each {|k, v| Setting[k] = v} |
|
74 | options.each {|k, v| Setting[k] = v} | |
75 | yield |
|
75 | yield | |
76 | saved_settings.each {|k, v| Setting[k] = v} |
|
76 | saved_settings.each {|k, v| Setting[k] = v} | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def self.ldap_configured? |
|
79 | def self.ldap_configured? | |
80 | @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389) |
|
80 | @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389) | |
81 | return @test_ldap.bind |
|
81 | return @test_ldap.bind | |
82 | rescue Exception => e |
|
82 | rescue Exception => e | |
83 | # LDAP is not listening |
|
83 | # LDAP is not listening | |
84 | return nil |
|
84 | return nil | |
85 | end |
|
85 | end | |
|
86 | ||||
|
87 | # Returns the path to the test +vendor+ repository | |||
|
88 | def self.repository_path(vendor) | |||
|
89 | File.join(RAILS_ROOT.gsub(%r{config\/\.\.}, ''), "/tmp/test/#{vendor.downcase}_repository") | |||
|
90 | end | |||
|
91 | ||||
|
92 | # Returns true if the +vendor+ test repository is configured | |||
|
93 | def self.repository_configured?(vendor) | |||
|
94 | File.directory?(repository_path(vendor)) | |||
|
95 | end | |||
86 |
|
96 | |||
87 | # Shoulda macros |
|
97 | # Shoulda macros | |
88 | def self.should_render_404 |
|
98 | def self.should_render_404 | |
89 | should_respond_with :not_found |
|
99 | should_respond_with :not_found | |
90 | should_render_template 'common/404' |
|
100 | should_render_template 'common/404' | |
91 | end |
|
101 | end | |
92 |
|
102 | |||
93 | def self.should_have_before_filter(expected_method, options = {}) |
|
103 | def self.should_have_before_filter(expected_method, options = {}) | |
94 | should_have_filter('before', expected_method, options) |
|
104 | should_have_filter('before', expected_method, options) | |
95 | end |
|
105 | end | |
96 |
|
106 | |||
97 | def self.should_have_after_filter(expected_method, options = {}) |
|
107 | def self.should_have_after_filter(expected_method, options = {}) | |
98 | should_have_filter('after', expected_method, options) |
|
108 | should_have_filter('after', expected_method, options) | |
99 | end |
|
109 | end | |
100 |
|
110 | |||
101 | def self.should_have_filter(filter_type, expected_method, options) |
|
111 | def self.should_have_filter(filter_type, expected_method, options) | |
102 | description = "have #{filter_type}_filter :#{expected_method}" |
|
112 | description = "have #{filter_type}_filter :#{expected_method}" | |
103 | description << " with #{options.inspect}" unless options.empty? |
|
113 | description << " with #{options.inspect}" unless options.empty? | |
104 |
|
114 | |||
105 | should description do |
|
115 | should description do | |
106 | klass = "action_controller/filters/#{filter_type}_filter".classify.constantize |
|
116 | klass = "action_controller/filters/#{filter_type}_filter".classify.constantize | |
107 | expected = klass.new(:filter, expected_method.to_sym, options) |
|
117 | expected = klass.new(:filter, expected_method.to_sym, options) | |
108 | assert_equal 1, @controller.class.filter_chain.select { |filter| |
|
118 | assert_equal 1, @controller.class.filter_chain.select { |filter| | |
109 | filter.method == expected.method && filter.kind == expected.kind && |
|
119 | filter.method == expected.method && filter.kind == expected.kind && | |
110 | filter.options == expected.options && filter.class == expected.class |
|
120 | filter.options == expected.options && filter.class == expected.class | |
111 | }.size |
|
121 | }.size | |
112 | end |
|
122 | end | |
113 | end |
|
123 | end | |
114 |
|
124 | |||
115 | def self.should_show_the_old_and_new_values_for(prop_key, model, &block) |
|
125 | def self.should_show_the_old_and_new_values_for(prop_key, model, &block) | |
116 | context "" do |
|
126 | context "" do | |
117 | setup do |
|
127 | setup do | |
118 | if block_given? |
|
128 | if block_given? | |
119 | instance_eval &block |
|
129 | instance_eval &block | |
120 | else |
|
130 | else | |
121 | @old_value = model.generate! |
|
131 | @old_value = model.generate! | |
122 | @new_value = model.generate! |
|
132 | @new_value = model.generate! | |
123 | end |
|
133 | end | |
124 | end |
|
134 | end | |
125 |
|
135 | |||
126 | should "use the new value's name" do |
|
136 | should "use the new value's name" do | |
127 | @detail = JournalDetail.generate!(:property => 'attr', |
|
137 | @detail = JournalDetail.generate!(:property => 'attr', | |
128 | :old_value => @old_value.id, |
|
138 | :old_value => @old_value.id, | |
129 | :value => @new_value.id, |
|
139 | :value => @new_value.id, | |
130 | :prop_key => prop_key) |
|
140 | :prop_key => prop_key) | |
131 |
|
141 | |||
132 | assert_match @new_value.name, show_detail(@detail, true) |
|
142 | assert_match @new_value.name, show_detail(@detail, true) | |
133 | end |
|
143 | end | |
134 |
|
144 | |||
135 | should "use the old value's name" do |
|
145 | should "use the old value's name" do | |
136 | @detail = JournalDetail.generate!(:property => 'attr', |
|
146 | @detail = JournalDetail.generate!(:property => 'attr', | |
137 | :old_value => @old_value.id, |
|
147 | :old_value => @old_value.id, | |
138 | :value => @new_value.id, |
|
148 | :value => @new_value.id, | |
139 | :prop_key => prop_key) |
|
149 | :prop_key => prop_key) | |
140 |
|
150 | |||
141 | assert_match @old_value.name, show_detail(@detail, true) |
|
151 | assert_match @old_value.name, show_detail(@detail, true) | |
142 | end |
|
152 | end | |
143 | end |
|
153 | end | |
144 | end |
|
154 | end | |
145 | end |
|
155 | end |
@@ -1,33 +1,31 | |||||
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 'mkmf' |
|
|||
19 |
|
||||
20 | require File.dirname(__FILE__) + '/../../../../../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../../../../../test_helper' | |
21 |
|
19 | |||
22 | class SubversionAdapterTest < ActiveSupport::TestCase |
|
20 | class SubversionAdapterTest < ActiveSupport::TestCase | |
23 |
|
21 | |||
24 | if find_executable0('svn') |
|
22 | if repository_configured?('subversion') | |
25 | def test_client_version |
|
23 | def test_client_version | |
26 | v = Redmine::Scm::Adapters::SubversionAdapter.client_version |
|
24 | v = Redmine::Scm::Adapters::SubversionAdapter.client_version | |
27 | assert v.is_a?(Array) |
|
25 | assert v.is_a?(Array) | |
28 | end |
|
26 | end | |
29 | else |
|
27 | else | |
30 |
puts "Subversion |
|
28 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" | |
31 | def test_fake; assert true end |
|
29 | def test_fake; assert true end | |
32 | end |
|
30 | end | |
33 | end |
|
31 | end |
@@ -1,72 +1,69 | |||||
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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
19 | |||
20 | class RepositorySubversionTest < ActiveSupport::TestCase |
|
20 | class RepositorySubversionTest < ActiveSupport::TestCase | |
21 | fixtures :projects |
|
21 | fixtures :projects | |
22 |
|
22 | |||
23 | # No '..' in the repository path for svn |
|
|||
24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository' |
|
|||
25 |
|
||||
26 | def setup |
|
23 | def setup | |
27 | @project = Project.find(1) |
|
24 | @project = Project.find(1) | |
28 |
assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{ |
|
25 | assert @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}") | |
29 | end |
|
26 | end | |
30 |
|
27 | |||
31 | if File.directory?(REPOSITORY_PATH) |
|
28 | if repository_configured?('subversion') | |
32 | def test_fetch_changesets_from_scratch |
|
29 | def test_fetch_changesets_from_scratch | |
33 | @repository.fetch_changesets |
|
30 | @repository.fetch_changesets | |
34 | @repository.reload |
|
31 | @repository.reload | |
35 |
|
32 | |||
36 | assert_equal 10, @repository.changesets.count |
|
33 | assert_equal 10, @repository.changesets.count | |
37 | assert_equal 18, @repository.changes.count |
|
34 | assert_equal 18, @repository.changes.count | |
38 | assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments |
|
35 | assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments | |
39 | end |
|
36 | end | |
40 |
|
37 | |||
41 | def test_fetch_changesets_incremental |
|
38 | def test_fetch_changesets_incremental | |
42 | @repository.fetch_changesets |
|
39 | @repository.fetch_changesets | |
43 | # Remove changesets with revision > 5 |
|
40 | # Remove changesets with revision > 5 | |
44 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} |
|
41 | @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5} | |
45 | @repository.reload |
|
42 | @repository.reload | |
46 | assert_equal 5, @repository.changesets.count |
|
43 | assert_equal 5, @repository.changesets.count | |
47 |
|
44 | |||
48 | @repository.fetch_changesets |
|
45 | @repository.fetch_changesets | |
49 | assert_equal 10, @repository.changesets.count |
|
46 | assert_equal 10, @repository.changesets.count | |
50 | end |
|
47 | end | |
51 |
|
48 | |||
52 | def test_latest_changesets |
|
49 | def test_latest_changesets | |
53 | @repository.fetch_changesets |
|
50 | @repository.fetch_changesets | |
54 |
|
51 | |||
55 | # with limit |
|
52 | # with limit | |
56 | changesets = @repository.latest_changesets('', nil, 2) |
|
53 | changesets = @repository.latest_changesets('', nil, 2) | |
57 | assert_equal 2, changesets.size |
|
54 | assert_equal 2, changesets.size | |
58 | assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets |
|
55 | assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets | |
59 |
|
56 | |||
60 | # with path |
|
57 | # with path | |
61 | changesets = @repository.latest_changesets('subversion_test/folder', nil) |
|
58 | changesets = @repository.latest_changesets('subversion_test/folder', nil) | |
62 | assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision) |
|
59 | assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision) | |
63 |
|
60 | |||
64 | # with path and revision |
|
61 | # with path and revision | |
65 | changesets = @repository.latest_changesets('subversion_test/folder', 8) |
|
62 | changesets = @repository.latest_changesets('subversion_test/folder', 8) | |
66 | assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) |
|
63 | assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) | |
67 | end |
|
64 | end | |
68 | else |
|
65 | else | |
69 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" |
|
66 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" | |
70 | def test_fake; assert true end |
|
67 | def test_fake; assert true end | |
71 | end |
|
68 | end | |
72 | end |
|
69 | end |
General Comments 0
You need to be logged in to leave comments.
Login now