Mercurial > hg > soundsoftware-site
comparison test/functional/repositories_bazaar_controller_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2008 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 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__) |
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 RepositoriesBazaarControllerTest < ActionController::TestCase | 24 class RepositoriesBazaarControllerTest < ActionController::TestCase |
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules | 25 fixtures :projects, :users, :roles, :members, :member_roles, |
26 :repositories, :enabled_modules | |
26 | 27 |
27 # No '..' in the repository path | 28 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s |
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository' | 29 PRJ_ID = 3 |
29 | 30 |
30 def setup | 31 def setup |
31 @controller = RepositoriesController.new | 32 @controller = RepositoriesController.new |
32 @request = ActionController::TestRequest.new | 33 @request = ActionController::TestRequest.new |
33 @response = ActionController::TestResponse.new | 34 @response = ActionController::TestResponse.new |
34 User.current = nil | 35 User.current = nil |
35 @project = Project.find(3) | 36 @project = Project.find(PRJ_ID) |
36 @repository = Repository::Bazaar.create( | 37 @repository = Repository::Bazaar.create( |
37 :project => @project, :url => REPOSITORY_PATH, | 38 :project => @project, |
39 :url => REPOSITORY_PATH, | |
38 :log_encoding => 'UTF-8') | 40 :log_encoding => 'UTF-8') |
39 assert @repository | 41 assert @repository |
40 end | 42 end |
41 | 43 |
42 if File.directory?(REPOSITORY_PATH) | 44 if File.directory?(REPOSITORY_PATH) |
43 def test_show | |
44 get :show, :id => 3 | |
45 assert_response :success | |
46 assert_template 'show' | |
47 assert_not_nil assigns(:entries) | |
48 assert_not_nil assigns(:changesets) | |
49 end | |
50 | |
51 def test_browse_root | 45 def test_browse_root |
52 get :show, :id => 3 | 46 get :show, :id => PRJ_ID |
53 assert_response :success | 47 assert_response :success |
54 assert_template 'show' | 48 assert_template 'show' |
55 assert_not_nil assigns(:entries) | 49 assert_not_nil assigns(:entries) |
56 assert_equal 2, assigns(:entries).size | 50 assert_equal 2, assigns(:entries).size |
57 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} | 51 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} |
58 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} | 52 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} |
59 end | 53 end |
60 | 54 |
61 def test_browse_directory | 55 def test_browse_directory |
62 get :show, :id => 3, :path => ['directory'] | 56 get :show, :id => PRJ_ID, :path => ['directory'] |
63 assert_response :success | 57 assert_response :success |
64 assert_template 'show' | 58 assert_template 'show' |
65 assert_not_nil assigns(:entries) | 59 assert_not_nil assigns(:entries) |
66 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) | 60 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) |
67 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | 61 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
68 assert_not_nil entry | 62 assert_not_nil entry |
69 assert_equal 'file', entry.kind | 63 assert_equal 'file', entry.kind |
70 assert_equal 'directory/edit.png', entry.path | 64 assert_equal 'directory/edit.png', entry.path |
71 end | 65 end |
72 | 66 |
73 def test_browse_at_given_revision | 67 def test_browse_at_given_revision |
74 get :show, :id => 3, :path => [], :rev => 3 | 68 get :show, :id => PRJ_ID, :path => [], :rev => 3 |
75 assert_response :success | 69 assert_response :success |
76 assert_template 'show' | 70 assert_template 'show' |
77 assert_not_nil assigns(:entries) | 71 assert_not_nil assigns(:entries) |
78 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], assigns(:entries).collect(&:name) | 72 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], |
73 assigns(:entries).collect(&:name) | |
79 end | 74 end |
80 | 75 |
81 def test_changes | 76 def test_changes |
82 get :changes, :id => 3, :path => ['doc-mkdir.txt'] | 77 get :changes, :id => PRJ_ID, :path => ['doc-mkdir.txt'] |
83 assert_response :success | 78 assert_response :success |
84 assert_template 'changes' | 79 assert_template 'changes' |
85 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt' | 80 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt' |
86 end | 81 end |
87 | 82 |
88 def test_entry_show | 83 def test_entry_show |
89 get :entry, :id => 3, :path => ['directory', 'doc-ls.txt'] | 84 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'] |
90 assert_response :success | 85 assert_response :success |
91 assert_template 'entry' | 86 assert_template 'entry' |
92 # Line 19 | 87 # Line 19 |
93 assert_tag :tag => 'th', | 88 assert_tag :tag => 'th', |
94 :content => /29/, | 89 :content => /29/, |
95 :attributes => { :class => /line-num/ }, | 90 :attributes => { :class => /line-num/ }, |
96 :sibling => { :tag => 'td', :content => /Show help message/ } | 91 :sibling => { :tag => 'td', :content => /Show help message/ } |
97 end | 92 end |
98 | 93 |
99 def test_entry_download | 94 def test_entry_download |
100 get :entry, :id => 3, :path => ['directory', 'doc-ls.txt'], :format => 'raw' | 95 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'], :format => 'raw' |
101 assert_response :success | 96 assert_response :success |
102 # File content | 97 # File content |
103 assert @response.body.include?('Show help message') | 98 assert @response.body.include?('Show help message') |
104 end | 99 end |
105 | 100 |
106 def test_directory_entry | 101 def test_directory_entry |
107 get :entry, :id => 3, :path => ['directory'] | 102 get :entry, :id => PRJ_ID, :path => ['directory'] |
108 assert_response :success | 103 assert_response :success |
109 assert_template 'show' | 104 assert_template 'show' |
110 assert_not_nil assigns(:entry) | 105 assert_not_nil assigns(:entry) |
111 assert_equal 'directory', assigns(:entry).name | 106 assert_equal 'directory', assigns(:entry).name |
112 end | 107 end |
113 | 108 |
114 def test_diff | 109 def test_diff |
115 # Full diff of changeset 3 | 110 # Full diff of changeset 3 |
116 get :diff, :id => 3, :rev => 3 | 111 ['inline', 'sbs'].each do |dt| |
117 assert_response :success | 112 get :diff, :id => PRJ_ID, :rev => 3, :type => dt |
118 assert_template 'diff' | 113 assert_response :success |
119 # Line 11 removed | 114 assert_template 'diff' |
120 assert_tag :tag => 'th', | 115 # Line 11 removed |
121 :content => /11/, | 116 assert_tag :tag => 'th', |
122 :sibling => { :tag => 'td', | 117 :content => '11', |
123 :attributes => { :class => /diff_out/ }, | 118 :sibling => { :tag => 'td', |
124 :content => /Display more information/ } | 119 :attributes => { :class => /diff_out/ }, |
120 :content => /Display more information/ } | |
121 end | |
125 end | 122 end |
126 | 123 |
127 def test_annotate | 124 def test_annotate |
128 get :annotate, :id => 3, :path => ['doc-mkdir.txt'] | 125 get :annotate, :id => PRJ_ID, :path => ['doc-mkdir.txt'] |
129 assert_response :success | 126 assert_response :success |
130 assert_template 'annotate' | 127 assert_template 'annotate' |
131 # Line 2, revision 3 | 128 assert_tag :tag => 'th', :content => '2', |
132 assert_tag :tag => 'th', :content => /2/, | 129 :sibling => { |
133 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /3/ } }, | 130 :tag => 'td', |
134 :sibling => { :tag => 'td', :content => /jsmith/ }, | 131 :child => { |
132 :tag => 'a', | |
133 :content => '3' | |
134 } | |
135 } | |
136 assert_tag :tag => 'th', :content => '2', | |
137 :sibling => { :tag => 'td', :content => /jsmith/ } | |
138 assert_tag :tag => 'th', :content => '2', | |
139 :sibling => { | |
140 :tag => 'td', | |
141 :child => { | |
142 :tag => 'a', | |
143 :content => '3' | |
144 } | |
145 } | |
146 assert_tag :tag => 'th', :content => '2', | |
135 :sibling => { :tag => 'td', :content => /Main purpose/ } | 147 :sibling => { :tag => 'td', :content => /Main purpose/ } |
148 end | |
149 | |
150 def test_destroy_valid_repository | |
151 @request.session[:user_id] = 1 # admin | |
152 assert_equal 0, @repository.changesets.count | |
153 @repository.fetch_changesets | |
154 @project.reload | |
155 assert @repository.changesets.count > 0 | |
156 | |
157 get :destroy, :id => PRJ_ID | |
158 assert_response 302 | |
159 @project.reload | |
160 assert_nil @project.repository | |
161 end | |
162 | |
163 def test_destroy_invalid_repository | |
164 @request.session[:user_id] = 1 # admin | |
165 assert_equal 0, @repository.changesets.count | |
166 @repository.fetch_changesets | |
167 @project.reload | |
168 assert @repository.changesets.count > 0 | |
169 | |
170 get :destroy, :id => PRJ_ID | |
171 assert_response 302 | |
172 @project.reload | |
173 assert_nil @project.repository | |
174 | |
175 @repository = Repository::Bazaar.create( | |
176 :project => @project, | |
177 :url => "/invalid", | |
178 :log_encoding => 'UTF-8') | |
179 assert @repository | |
180 @repository.fetch_changesets | |
181 @repository.reload | |
182 assert_equal 0, @repository.changesets.count | |
183 | |
184 get :destroy, :id => PRJ_ID | |
185 assert_response 302 | |
186 @project.reload | |
187 assert_nil @project.repository | |
136 end | 188 end |
137 else | 189 else |
138 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!" | 190 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!" |
139 def test_fake; assert true end | 191 def test_fake; assert true end |
140 end | 192 end |