##// END OF EJS Templates
use assert_select instead of assert_tag in Bazaar annotate test (#14931)...
Toshi MARUYAMA -
r11911:eaf05a87b475
parent child
Show More
@@ -1,198 +1,187
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/trunk').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
27 PRJ_ID = 3
27 PRJ_ID = 3
28
28
29 def setup
29 def setup
30 User.current = nil
30 User.current = nil
31 @project = Project.find(PRJ_ID)
31 @project = Project.find(PRJ_ID)
32 @repository = Repository::Bazaar.create(
32 @repository = Repository::Bazaar.create(
33 :project => @project,
33 :project => @project,
34 :url => REPOSITORY_PATH,
34 :url => REPOSITORY_PATH,
35 :log_encoding => 'UTF-8')
35 :log_encoding => 'UTF-8')
36 assert @repository
36 assert @repository
37 end
37 end
38
38
39 if File.directory?(REPOSITORY_PATH)
39 if File.directory?(REPOSITORY_PATH)
40 def test_get_new
40 def test_get_new
41 @request.session[:user_id] = 1
41 @request.session[:user_id] = 1
42 @project.repository.destroy
42 @project.repository.destroy
43 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
43 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
44 assert_response :success
44 assert_response :success
45 assert_template 'new'
45 assert_template 'new'
46 assert_kind_of Repository::Bazaar, assigns(:repository)
46 assert_kind_of Repository::Bazaar, assigns(:repository)
47 assert assigns(:repository).new_record?
47 assert assigns(:repository).new_record?
48 end
48 end
49
49
50 def test_browse_root
50 def test_browse_root
51 get :show, :id => PRJ_ID
51 get :show, :id => PRJ_ID
52 assert_response :success
52 assert_response :success
53 assert_template 'show'
53 assert_template 'show'
54 assert_not_nil assigns(:entries)
54 assert_not_nil assigns(:entries)
55 assert_equal 2, assigns(:entries).size
55 assert_equal 2, assigns(:entries).size
56 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
57 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
57 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
58 end
58 end
59
59
60 def test_browse_directory
60 def test_browse_directory
61 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
61 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
62 assert_response :success
62 assert_response :success
63 assert_template 'show'
63 assert_template 'show'
64 assert_not_nil assigns(:entries)
64 assert_not_nil assigns(:entries)
65 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
65 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67 assert_not_nil entry
67 assert_not_nil entry
68 assert_equal 'file', entry.kind
68 assert_equal 'file', entry.kind
69 assert_equal 'directory/edit.png', entry.path
69 assert_equal 'directory/edit.png', entry.path
70 end
70 end
71
71
72 def test_browse_at_given_revision
72 def test_browse_at_given_revision
73 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
73 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
74 :rev => 3
74 :rev => 3
75 assert_response :success
75 assert_response :success
76 assert_template 'show'
76 assert_template 'show'
77 assert_not_nil assigns(:entries)
77 assert_not_nil assigns(:entries)
78 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
78 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
79 assigns(:entries).collect(&:name)
79 assigns(:entries).collect(&:name)
80 end
80 end
81
81
82 def test_changes
82 def test_changes
83 get :changes, :id => PRJ_ID,
83 get :changes, :id => PRJ_ID,
84 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
84 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
85 assert_response :success
85 assert_response :success
86 assert_template 'changes'
86 assert_template 'changes'
87 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
87 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
88 end
88 end
89
89
90 def test_entry_show
90 def test_entry_show
91 get :entry, :id => PRJ_ID,
91 get :entry, :id => PRJ_ID,
92 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
92 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
93 assert_response :success
93 assert_response :success
94 assert_template 'entry'
94 assert_template 'entry'
95 # Line 19
95 # Line 19
96 assert_tag :tag => 'th',
96 assert_tag :tag => 'th',
97 :content => /29/,
97 :content => /29/,
98 :attributes => { :class => /line-num/ },
98 :attributes => { :class => /line-num/ },
99 :sibling => { :tag => 'td', :content => /Show help message/ }
99 :sibling => { :tag => 'td', :content => /Show help message/ }
100 end
100 end
101
101
102 def test_entry_download
102 def test_entry_download
103 get :entry, :id => PRJ_ID,
103 get :entry, :id => PRJ_ID,
104 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
104 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
105 :format => 'raw'
105 :format => 'raw'
106 assert_response :success
106 assert_response :success
107 # File content
107 # File content
108 assert @response.body.include?('Show help message')
108 assert @response.body.include?('Show help message')
109 end
109 end
110
110
111 def test_directory_entry
111 def test_directory_entry
112 get :entry, :id => PRJ_ID,
112 get :entry, :id => PRJ_ID,
113 :path => repository_path_hash(['directory'])[:param]
113 :path => repository_path_hash(['directory'])[:param]
114 assert_response :success
114 assert_response :success
115 assert_template 'show'
115 assert_template 'show'
116 assert_not_nil assigns(:entry)
116 assert_not_nil assigns(:entry)
117 assert_equal 'directory', assigns(:entry).name
117 assert_equal 'directory', assigns(:entry).name
118 end
118 end
119
119
120 def test_diff
120 def test_diff
121 # Full diff of changeset 3
121 # Full diff of changeset 3
122 ['inline', 'sbs'].each do |dt|
122 ['inline', 'sbs'].each do |dt|
123 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
123 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
124 assert_response :success
124 assert_response :success
125 assert_template 'diff'
125 assert_template 'diff'
126 # Line 11 removed
126 # Line 11 removed
127 assert_tag :tag => 'th',
127 assert_tag :tag => 'th',
128 :content => '11',
128 :content => '11',
129 :sibling => { :tag => 'td',
129 :sibling => { :tag => 'td',
130 :attributes => { :class => /diff_out/ },
130 :attributes => { :class => /diff_out/ },
131 :content => /Display more information/ }
131 :content => /Display more information/ }
132 end
132 end
133 end
133 end
134
134
135 def test_annotate
135 def test_annotate
136 get :annotate, :id => PRJ_ID,
136 get :annotate, :id => PRJ_ID,
137 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
137 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
138 assert_response :success
138 assert_response :success
139 assert_template 'annotate'
139 assert_template 'annotate'
140 assert_tag :tag => 'th', :content => '2',
140 assert_select "th.line-num", :text => '2' do
141 :sibling => {
141 assert_select "+ td.revision" do
142 :tag => 'td',
142 assert_select "a", :text => '3'
143 :child => {
143 assert_select "+ td.author", :text => "jsmith@" do
144 :tag => 'a',
144 assert_select "+ td",
145 :content => '3'
145 :text => "Main purpose:"
146 }
146 end
147 }
147 end
148 assert_tag :tag => 'th', :content => '2',
148 end
149 :sibling => { :tag => 'td', :content => /jsmith/ }
150 assert_tag :tag => 'th', :content => '2',
151 :sibling => {
152 :tag => 'td',
153 :child => {
154 :tag => 'a',
155 :content => '3'
156 }
157 }
158 assert_tag :tag => 'th', :content => '2',
159 :sibling => { :tag => 'td', :content => /Main purpose/ }
160 end
149 end
161
150
162 def test_destroy_valid_repository
151 def test_destroy_valid_repository
163 @request.session[:user_id] = 1 # admin
152 @request.session[:user_id] = 1 # admin
164 assert_equal 0, @repository.changesets.count
153 assert_equal 0, @repository.changesets.count
165 @repository.fetch_changesets
154 @repository.fetch_changesets
166 assert @repository.changesets.count > 0
155 assert @repository.changesets.count > 0
167
156
168 assert_difference 'Repository.count', -1 do
157 assert_difference 'Repository.count', -1 do
169 delete :destroy, :id => @repository.id
158 delete :destroy, :id => @repository.id
170 end
159 end
171 assert_response 302
160 assert_response 302
172 @project.reload
161 @project.reload
173 assert_nil @project.repository
162 assert_nil @project.repository
174 end
163 end
175
164
176 def test_destroy_invalid_repository
165 def test_destroy_invalid_repository
177 @request.session[:user_id] = 1 # admin
166 @request.session[:user_id] = 1 # admin
178 @project.repository.destroy
167 @project.repository.destroy
179 @repository = Repository::Bazaar.create!(
168 @repository = Repository::Bazaar.create!(
180 :project => @project,
169 :project => @project,
181 :url => "/invalid",
170 :url => "/invalid",
182 :log_encoding => 'UTF-8')
171 :log_encoding => 'UTF-8')
183 @repository.fetch_changesets
172 @repository.fetch_changesets
184 @repository.reload
173 @repository.reload
185 assert_equal 0, @repository.changesets.count
174 assert_equal 0, @repository.changesets.count
186
175
187 assert_difference 'Repository.count', -1 do
176 assert_difference 'Repository.count', -1 do
188 delete :destroy, :id => @repository.id
177 delete :destroy, :id => @repository.id
189 end
178 end
190 assert_response 302
179 assert_response 302
191 @project.reload
180 @project.reload
192 assert_nil @project.repository
181 assert_nil @project.repository
193 end
182 end
194 else
183 else
195 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
184 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
196 def test_fake; assert true end
185 def test_fake; assert true end
197 end
186 end
198 end
187 end
General Comments 0
You need to be logged in to leave comments. Login now