@@ -1,246 +1,246 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 RepositoriesBazaarControllerTest < ActionController::TestCase |
|
20 | class RepositoriesBazaarControllerTest < ActionController::TestCase | |
21 | tests RepositoriesController |
|
21 | tests RepositoriesController | |
22 |
|
22 | |||
23 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
23 | fixtures :projects, :users, :roles, :members, :member_roles, | |
24 | :repositories, :enabled_modules |
|
24 | :repositories, :enabled_modules | |
25 |
|
25 | |||
26 | REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s |
|
26 | REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s | |
27 | REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk") |
|
27 | REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk") | |
28 | PRJ_ID = 3 |
|
28 | PRJ_ID = 3 | |
29 | CHAR_1_UTF8_HEX = "\xc3\x9c" |
|
29 | CHAR_1_UTF8_HEX = "\xc3\x9c" | |
30 |
|
30 | |||
31 | def setup |
|
31 | def setup | |
32 | User.current = nil |
|
32 | User.current = nil | |
33 | @project = Project.find(PRJ_ID) |
|
33 | @project = Project.find(PRJ_ID) | |
34 | @repository = Repository::Bazaar.create( |
|
34 | @repository = Repository::Bazaar.create( | |
35 | :project => @project, |
|
35 | :project => @project, | |
36 | :url => REPOSITORY_PATH_TRUNK, |
|
36 | :url => REPOSITORY_PATH_TRUNK, | |
37 | :log_encoding => 'UTF-8') |
|
37 | :log_encoding => 'UTF-8') | |
38 | assert @repository |
|
38 | assert @repository | |
39 | @char_1_utf8 = CHAR_1_UTF8_HEX.dup |
|
39 | @char_1_utf8 = CHAR_1_UTF8_HEX.dup | |
40 | if @char_1_utf8.respond_to?(:force_encoding) |
|
40 | if @char_1_utf8.respond_to?(:force_encoding) | |
41 | @char_1_utf8.force_encoding('UTF-8') |
|
41 | @char_1_utf8.force_encoding('UTF-8') | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | if File.directory?(REPOSITORY_PATH) |
|
45 | if File.directory?(REPOSITORY_PATH) | |
46 | def test_get_new |
|
46 | def test_get_new | |
47 | @request.session[:user_id] = 1 |
|
47 | @request.session[:user_id] = 1 | |
48 | @project.repository.destroy |
|
48 | @project.repository.destroy | |
49 | get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar' |
|
49 | get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar' | |
50 | assert_response :success |
|
50 | assert_response :success | |
51 | assert_template 'new' |
|
51 | assert_template 'new' | |
52 | assert_kind_of Repository::Bazaar, assigns(:repository) |
|
52 | assert_kind_of Repository::Bazaar, assigns(:repository) | |
53 | assert assigns(:repository).new_record? |
|
53 | assert assigns(:repository).new_record? | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_browse_root |
|
56 | def test_browse_root | |
57 | get :show, :id => PRJ_ID |
|
57 | get :show, :id => PRJ_ID | |
58 | assert_response :success |
|
58 | assert_response :success | |
59 | assert_template 'show' |
|
59 | assert_template 'show' | |
60 | assert_not_nil assigns(:entries) |
|
60 | assert_not_nil assigns(:entries) | |
61 | assert_equal 2, assigns(:entries).size |
|
61 | assert_equal 2, assigns(:entries).size | |
62 | assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} |
|
62 | assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} | |
63 | assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} |
|
63 | assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_browse_directory |
|
66 | def test_browse_directory | |
67 | get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param] |
|
67 | get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param] | |
68 | assert_response :success |
|
68 | assert_response :success | |
69 | assert_template 'show' |
|
69 | assert_template 'show' | |
70 | assert_not_nil assigns(:entries) |
|
70 | assert_not_nil assigns(:entries) | |
71 | assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) |
|
71 | assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) | |
72 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
72 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
73 | assert_not_nil entry |
|
73 | assert_not_nil entry | |
74 | assert_equal 'file', entry.kind |
|
74 | assert_equal 'file', entry.kind | |
75 | assert_equal 'directory/edit.png', entry.path |
|
75 | assert_equal 'directory/edit.png', entry.path | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_browse_at_given_revision |
|
78 | def test_browse_at_given_revision | |
79 | get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param], |
|
79 | get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param], | |
80 | :rev => 3 |
|
80 | :rev => 3 | |
81 | assert_response :success |
|
81 | assert_response :success | |
82 | assert_template 'show' |
|
82 | assert_template 'show' | |
83 | assert_not_nil assigns(:entries) |
|
83 | assert_not_nil assigns(:entries) | |
84 | assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], |
|
84 | assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], | |
85 | assigns(:entries).collect(&:name) |
|
85 | assigns(:entries).collect(&:name) | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_changes |
|
88 | def test_changes | |
89 | get :changes, :id => PRJ_ID, |
|
89 | get :changes, :id => PRJ_ID, | |
90 | :path => repository_path_hash(['doc-mkdir.txt'])[:param] |
|
90 | :path => repository_path_hash(['doc-mkdir.txt'])[:param] | |
91 | assert_response :success |
|
91 | assert_response :success | |
92 | assert_template 'changes' |
|
92 | assert_template 'changes' | |
93 | assert_tag :tag => 'h2', :content => 'doc-mkdir.txt' |
|
93 | assert_tag :tag => 'h2', :content => 'doc-mkdir.txt' | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def test_entry_show |
|
96 | def test_entry_show | |
97 | get :entry, :id => PRJ_ID, |
|
97 | get :entry, :id => PRJ_ID, | |
98 | :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param] |
|
98 | :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param] | |
99 | assert_response :success |
|
99 | assert_response :success | |
100 | assert_template 'entry' |
|
100 | assert_template 'entry' | |
101 | # Line 19 |
|
101 | # Line 19 | |
102 | assert_tag :tag => 'th', |
|
102 | assert_tag :tag => 'th', | |
103 | :content => /29/, |
|
103 | :content => /29/, | |
104 | :attributes => { :class => /line-num/ }, |
|
104 | :attributes => { :class => /line-num/ }, | |
105 | :sibling => { :tag => 'td', :content => /Show help message/ } |
|
105 | :sibling => { :tag => 'td', :content => /Show help message/ } | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_entry_download |
|
108 | def test_entry_download | |
109 | get :entry, :id => PRJ_ID, |
|
109 | get :entry, :id => PRJ_ID, | |
110 | :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param], |
|
110 | :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param], | |
111 | :format => 'raw' |
|
111 | :format => 'raw' | |
112 | assert_response :success |
|
112 | assert_response :success | |
113 | # File content |
|
113 | # File content | |
114 | assert @response.body.include?('Show help message') |
|
114 | assert @response.body.include?('Show help message') | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def test_directory_entry |
|
117 | def test_directory_entry | |
118 | get :entry, :id => PRJ_ID, |
|
118 | get :entry, :id => PRJ_ID, | |
119 | :path => repository_path_hash(['directory'])[:param] |
|
119 | :path => repository_path_hash(['directory'])[:param] | |
120 | assert_response :success |
|
120 | assert_response :success | |
121 | assert_template 'show' |
|
121 | assert_template 'show' | |
122 | assert_not_nil assigns(:entry) |
|
122 | assert_not_nil assigns(:entry) | |
123 | assert_equal 'directory', assigns(:entry).name |
|
123 | assert_equal 'directory', assigns(:entry).name | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def test_diff |
|
126 | def test_diff | |
127 | # Full diff of changeset 3 |
|
127 | # Full diff of changeset 3 | |
128 | ['inline', 'sbs'].each do |dt| |
|
128 | ['inline', 'sbs'].each do |dt| | |
129 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt |
|
129 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt | |
130 | assert_response :success |
|
130 | assert_response :success | |
131 | assert_template 'diff' |
|
131 | assert_template 'diff' | |
132 | # Line 11 removed |
|
132 | # Line 11 removed | |
133 | assert_tag :tag => 'th', |
|
133 | assert_tag :tag => 'th', | |
134 | :content => '11', |
|
134 | :content => '11', | |
135 | :sibling => { :tag => 'td', |
|
135 | :sibling => { :tag => 'td', | |
136 | :attributes => { :class => /diff_out/ }, |
|
136 | :attributes => { :class => /diff_out/ }, | |
137 | :content => /Display more information/ } |
|
137 | :content => /Display more information/ } | |
138 | end |
|
138 | end | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_annotate |
|
141 | def test_annotate | |
142 | get :annotate, :id => PRJ_ID, |
|
142 | get :annotate, :id => PRJ_ID, | |
143 | :path => repository_path_hash(['doc-mkdir.txt'])[:param] |
|
143 | :path => repository_path_hash(['doc-mkdir.txt'])[:param] | |
144 | assert_response :success |
|
144 | assert_response :success | |
145 | assert_template 'annotate' |
|
145 | assert_template 'annotate' | |
146 | assert_select "th.line-num", :text => '2' do |
|
146 | assert_select "th.line-num", :text => '2' do | |
147 | assert_select "+ td.revision" do |
|
147 | assert_select "+ td.revision" do | |
148 | assert_select "a", :text => '3' |
|
148 | assert_select "a", :text => '3' | |
149 | assert_select "+ td.author", :text => "jsmith@" do |
|
149 | assert_select "+ td.author", :text => "jsmith@" do | |
150 | assert_select "+ td", |
|
150 | assert_select "+ td", | |
151 | :text => "Main purpose:" |
|
151 | :text => "Main purpose:" | |
152 | end |
|
152 | end | |
153 | end |
|
153 | end | |
154 | end |
|
154 | end | |
155 | end |
|
155 | end | |
156 |
|
156 | |||
157 | def test_annotate_author_escaping |
|
157 | def test_annotate_author_escaping | |
158 | repository = Repository::Bazaar.create( |
|
158 | repository = Repository::Bazaar.create( | |
159 | :project => @project, |
|
159 | :project => @project, | |
160 | :url => File.join(REPOSITORY_PATH, "author_escaping"), |
|
160 | :url => File.join(REPOSITORY_PATH, "author_escaping"), | |
161 | :identifier => 'author_escaping', |
|
161 | :identifier => 'author_escaping', | |
162 | :log_encoding => 'UTF-8') |
|
162 | :log_encoding => 'UTF-8') | |
163 | assert repository |
|
163 | assert repository | |
164 | get :annotate, :id => PRJ_ID, :repository_id => 'author_escaping', |
|
164 | get :annotate, :id => PRJ_ID, :repository_id => 'author_escaping', | |
165 | :path => repository_path_hash(['author-escaping-test.txt'])[:param] |
|
165 | :path => repository_path_hash(['author-escaping-test.txt'])[:param] | |
166 | assert_response :success |
|
166 | assert_response :success | |
167 | assert_template 'annotate' |
|
167 | assert_template 'annotate' | |
168 | assert_select "th.line-num", :text => '1' do |
|
168 | assert_select "th.line-num", :text => '1' do | |
169 | assert_select "+ td.revision" do |
|
169 | assert_select "+ td.revision" do | |
170 | assert_select "a", :text => '2' |
|
170 | assert_select "a", :text => '2' | |
171 | assert_select "+ td.author", :text => "test &" do |
|
171 | assert_select "+ td.author", :text => "test &" do | |
172 | assert_select "+ td", |
|
172 | assert_select "+ td", | |
173 | :text => "author escaping test" |
|
173 | :text => "author escaping test" | |
174 | end |
|
174 | end | |
175 | end |
|
175 | end | |
176 | end |
|
176 | end | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | if REPOSITORY_PATH.respond_to?(:force_encoding) |
|
179 | if REPOSITORY_PATH.respond_to?(:force_encoding) | |
180 | def test_annotate_author_non_ascii |
|
180 | def test_annotate_author_non_ascii | |
181 | log_encoding = nil |
|
181 | log_encoding = nil | |
182 |
if Encoding.locale_charmap == "UTF-8" || |
|
182 | if Encoding.locale_charmap == "UTF-8" || | |
183 | Encoding.locale_charmap == "ISO-8859-1" |
|
183 | Encoding.locale_charmap == "ISO-8859-1" | |
184 | log_encoding = Encoding.locale_charmap |
|
184 | log_encoding = Encoding.locale_charmap | |
185 | end |
|
185 | end | |
186 | unless log_encoding.nil? |
|
186 | unless log_encoding.nil? | |
187 | repository = Repository::Bazaar.create( |
|
187 | repository = Repository::Bazaar.create( | |
188 | :project => @project, |
|
188 | :project => @project, | |
189 | :url => File.join(REPOSITORY_PATH, "author_non_ascii"), |
|
189 | :url => File.join(REPOSITORY_PATH, "author_non_ascii"), | |
190 | :identifier => 'author_non_ascii', |
|
190 | :identifier => 'author_non_ascii', | |
191 | :log_encoding => log_encoding) |
|
191 | :log_encoding => log_encoding) | |
192 | assert repository |
|
192 | assert repository | |
193 | get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii', |
|
193 | get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii', | |
194 | :path => repository_path_hash(['author-non-ascii-test.txt'])[:param] |
|
194 | :path => repository_path_hash(['author-non-ascii-test.txt'])[:param] | |
195 | assert_response :success |
|
195 | assert_response :success | |
196 | assert_template 'annotate' |
|
196 | assert_template 'annotate' | |
197 | assert_select "th.line-num", :text => '1' do |
|
197 | assert_select "th.line-num", :text => '1' do | |
198 | assert_select "+ td.revision" do |
|
198 | assert_select "+ td.revision" do | |
199 | assert_select "a", :text => '2' |
|
199 | assert_select "a", :text => '2' | |
200 | assert_select "+ td.author", :text => "test #{@char_1_utf8}" do |
|
200 | assert_select "+ td.author", :text => "test #{@char_1_utf8}" do | |
201 | assert_select "+ td", |
|
201 | assert_select "+ td", | |
202 | :text => "author non ASCII test" |
|
202 | :text => "author non ASCII test" | |
203 | end |
|
203 | end | |
204 | end |
|
204 | end | |
205 | end |
|
205 | end | |
206 | end |
|
206 | end | |
207 | end |
|
207 | end | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def test_destroy_valid_repository |
|
210 | def test_destroy_valid_repository | |
211 | @request.session[:user_id] = 1 # admin |
|
211 | @request.session[:user_id] = 1 # admin | |
212 | assert_equal 0, @repository.changesets.count |
|
212 | assert_equal 0, @repository.changesets.count | |
213 | @repository.fetch_changesets |
|
213 | @repository.fetch_changesets | |
214 | assert @repository.changesets.count > 0 |
|
214 | assert @repository.changesets.count > 0 | |
215 |
|
215 | |||
216 | assert_difference 'Repository.count', -1 do |
|
216 | assert_difference 'Repository.count', -1 do | |
217 | delete :destroy, :id => @repository.id |
|
217 | delete :destroy, :id => @repository.id | |
218 | end |
|
218 | end | |
219 | assert_response 302 |
|
219 | assert_response 302 | |
220 | @project.reload |
|
220 | @project.reload | |
221 | assert_nil @project.repository |
|
221 | assert_nil @project.repository | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def test_destroy_invalid_repository |
|
224 | def test_destroy_invalid_repository | |
225 | @request.session[:user_id] = 1 # admin |
|
225 | @request.session[:user_id] = 1 # admin | |
226 | @project.repository.destroy |
|
226 | @project.repository.destroy | |
227 | @repository = Repository::Bazaar.create!( |
|
227 | @repository = Repository::Bazaar.create!( | |
228 | :project => @project, |
|
228 | :project => @project, | |
229 | :url => "/invalid", |
|
229 | :url => "/invalid", | |
230 | :log_encoding => 'UTF-8') |
|
230 | :log_encoding => 'UTF-8') | |
231 | @repository.fetch_changesets |
|
231 | @repository.fetch_changesets | |
232 | @repository.reload |
|
232 | @repository.reload | |
233 | assert_equal 0, @repository.changesets.count |
|
233 | assert_equal 0, @repository.changesets.count | |
234 |
|
234 | |||
235 | assert_difference 'Repository.count', -1 do |
|
235 | assert_difference 'Repository.count', -1 do | |
236 | delete :destroy, :id => @repository.id |
|
236 | delete :destroy, :id => @repository.id | |
237 | end |
|
237 | end | |
238 | assert_response 302 |
|
238 | assert_response 302 | |
239 | @project.reload |
|
239 | @project.reload | |
240 | assert_nil @project.repository |
|
240 | assert_nil @project.repository | |
241 | end |
|
241 | end | |
242 | else |
|
242 | else | |
243 | puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!" |
|
243 | puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!" | |
244 | def test_fake; assert true end |
|
244 | def test_fake; assert true end | |
245 | end |
|
245 | end | |
246 | end |
|
246 | end |
General Comments 0
You need to be logged in to leave comments.
Login now