annotate .svn/pristine/7d/7d7a63dac05990ebb68fcd3fce0da9965a2d6f7a.svn-base @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'repositories_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class RepositoriesCvsControllerTest < ActionController::TestCase
Chris@909 25 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 26 :repositories, :enabled_modules
Chris@909 27
Chris@909 28 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
Chris@909 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@909 30 # CVS module
Chris@909 31 MODULE_NAME = 'test'
Chris@909 32 PRJ_ID = 3
Chris@909 33 NUM_REV = 7
Chris@909 34
Chris@909 35 def setup
Chris@909 36 @controller = RepositoriesController.new
Chris@909 37 @request = ActionController::TestRequest.new
Chris@909 38 @response = ActionController::TestResponse.new
Chris@909 39 Setting.default_language = 'en'
Chris@909 40 User.current = nil
Chris@909 41
Chris@909 42 @project = Project.find(PRJ_ID)
Chris@909 43 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
Chris@909 44 :root_url => REPOSITORY_PATH,
Chris@909 45 :url => MODULE_NAME,
Chris@909 46 :log_encoding => 'UTF-8')
Chris@909 47 assert @repository
Chris@909 48 end
Chris@909 49
Chris@909 50 if File.directory?(REPOSITORY_PATH)
Chris@909 51 def test_browse_root
Chris@909 52 assert_equal 0, @repository.changesets.count
Chris@909 53 @repository.fetch_changesets
Chris@909 54 @project.reload
Chris@909 55 assert_equal NUM_REV, @repository.changesets.count
Chris@909 56 get :show, :id => PRJ_ID
Chris@909 57 assert_response :success
Chris@909 58 assert_template 'show'
Chris@909 59 assert_not_nil assigns(:entries)
Chris@909 60 assert_equal 3, assigns(:entries).size
Chris@909 61
Chris@909 62 entry = assigns(:entries).detect {|e| e.name == 'images'}
Chris@909 63 assert_equal 'dir', entry.kind
Chris@909 64
Chris@909 65 entry = assigns(:entries).detect {|e| e.name == 'README'}
Chris@909 66 assert_equal 'file', entry.kind
Chris@909 67
Chris@909 68 assert_not_nil assigns(:changesets)
Chris@909 69 assert assigns(:changesets).size > 0
Chris@909 70 end
Chris@909 71
Chris@909 72 def test_browse_directory
Chris@909 73 assert_equal 0, @repository.changesets.count
Chris@909 74 @repository.fetch_changesets
Chris@909 75 @project.reload
Chris@909 76 assert_equal NUM_REV, @repository.changesets.count
Chris@909 77 get :show, :id => PRJ_ID, :path => ['images']
Chris@909 78 assert_response :success
Chris@909 79 assert_template 'show'
Chris@909 80 assert_not_nil assigns(:entries)
Chris@909 81 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@909 82 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@909 83 assert_not_nil entry
Chris@909 84 assert_equal 'file', entry.kind
Chris@909 85 assert_equal 'images/edit.png', entry.path
Chris@909 86 end
Chris@909 87
Chris@909 88 def test_browse_at_given_revision
Chris@909 89 assert_equal 0, @repository.changesets.count
Chris@909 90 @repository.fetch_changesets
Chris@909 91 @project.reload
Chris@909 92 assert_equal NUM_REV, @repository.changesets.count
Chris@909 93 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
Chris@909 94 assert_response :success
Chris@909 95 assert_template 'show'
Chris@909 96 assert_not_nil assigns(:entries)
Chris@909 97 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@909 98 end
Chris@909 99
Chris@909 100 def test_entry
Chris@909 101 assert_equal 0, @repository.changesets.count
Chris@909 102 @repository.fetch_changesets
Chris@909 103 @project.reload
Chris@909 104 assert_equal NUM_REV, @repository.changesets.count
Chris@909 105 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@909 106 assert_response :success
Chris@909 107 assert_template 'entry'
Chris@909 108 assert_no_tag :tag => 'td',
Chris@909 109 :attributes => { :class => /line-code/},
Chris@909 110 :content => /before_filter/
Chris@909 111 end
Chris@909 112
Chris@909 113 def test_entry_at_given_revision
Chris@909 114 # changesets must be loaded
Chris@909 115 assert_equal 0, @repository.changesets.count
Chris@909 116 @repository.fetch_changesets
Chris@909 117 @project.reload
Chris@909 118 assert_equal NUM_REV, @repository.changesets.count
Chris@909 119 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2
Chris@909 120 assert_response :success
Chris@909 121 assert_template 'entry'
Chris@909 122 # this line was removed in r3
Chris@909 123 assert_tag :tag => 'td',
Chris@909 124 :attributes => { :class => /line-code/},
Chris@909 125 :content => /before_filter/
Chris@909 126 end
Chris@909 127
Chris@909 128 def test_entry_not_found
Chris@909 129 assert_equal 0, @repository.changesets.count
Chris@909 130 @repository.fetch_changesets
Chris@909 131 @project.reload
Chris@909 132 assert_equal NUM_REV, @repository.changesets.count
Chris@909 133 get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c']
Chris@909 134 assert_tag :tag => 'p',
Chris@909 135 :attributes => { :id => /errorExplanation/ },
Chris@909 136 :content => /The entry or revision was not found in the repository/
Chris@909 137 end
Chris@909 138
Chris@909 139 def test_entry_download
Chris@909 140 assert_equal 0, @repository.changesets.count
Chris@909 141 @repository.fetch_changesets
Chris@909 142 @project.reload
Chris@909 143 assert_equal NUM_REV, @repository.changesets.count
Chris@909 144 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
Chris@909 145 :format => 'raw'
Chris@909 146 assert_response :success
Chris@909 147 end
Chris@909 148
Chris@909 149 def test_directory_entry
Chris@909 150 assert_equal 0, @repository.changesets.count
Chris@909 151 @repository.fetch_changesets
Chris@909 152 @project.reload
Chris@909 153 assert_equal NUM_REV, @repository.changesets.count
Chris@909 154 get :entry, :id => PRJ_ID, :path => ['sources']
Chris@909 155 assert_response :success
Chris@909 156 assert_template 'show'
Chris@909 157 assert_not_nil assigns(:entry)
Chris@909 158 assert_equal 'sources', assigns(:entry).name
Chris@909 159 end
Chris@909 160
Chris@909 161 def test_diff
Chris@909 162 assert_equal 0, @repository.changesets.count
Chris@909 163 @repository.fetch_changesets
Chris@909 164 @project.reload
Chris@909 165 assert_equal NUM_REV, @repository.changesets.count
Chris@909 166 ['inline', 'sbs'].each do |dt|
Chris@909 167 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@909 168 assert_response :success
Chris@909 169 assert_template 'diff'
Chris@909 170 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
Chris@909 171 :content => /before_filter :require_login/
Chris@909 172 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@909 173 :content => /with one change/
Chris@909 174 end
Chris@909 175 end
Chris@909 176
Chris@909 177 def test_diff_new_files
Chris@909 178 assert_equal 0, @repository.changesets.count
Chris@909 179 @repository.fetch_changesets
Chris@909 180 @project.reload
Chris@909 181 assert_equal NUM_REV, @repository.changesets.count
Chris@909 182 ['inline', 'sbs'].each do |dt|
Chris@909 183 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
Chris@909 184 assert_response :success
Chris@909 185 assert_template 'diff'
Chris@909 186 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
Chris@909 187 :content => /watched.remove_watcher/
Chris@909 188 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 189 :content => /test\/README/
Chris@909 190 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 191 :content => /test\/images\/delete.png /
Chris@909 192 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 193 :content => /test\/images\/edit.png/
Chris@909 194 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
Chris@909 195 :content => /test\/sources\/watchers_controller.rb/
Chris@909 196 end
Chris@909 197 end
Chris@909 198
Chris@909 199 def test_annotate
Chris@909 200 assert_equal 0, @repository.changesets.count
Chris@909 201 @repository.fetch_changesets
Chris@909 202 @project.reload
Chris@909 203 assert_equal NUM_REV, @repository.changesets.count
Chris@909 204 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@909 205 assert_response :success
Chris@909 206 assert_template 'annotate'
Chris@909 207 # 1.1 line
Chris@909 208 assert_tag :tag => 'th',
Chris@909 209 :attributes => { :class => 'line-num' },
Chris@909 210 :content => '18',
Chris@909 211 :sibling => {
Chris@909 212 :tag => 'td',
Chris@909 213 :attributes => { :class => 'revision' },
Chris@909 214 :content => /1.1/,
Chris@909 215 :sibling => {
Chris@909 216 :tag => 'td',
Chris@909 217 :attributes => { :class => 'author' },
Chris@909 218 :content => /LANG/
Chris@909 219 }
Chris@909 220 }
Chris@909 221 # 1.2 line
Chris@909 222 assert_tag :tag => 'th',
Chris@909 223 :attributes => { :class => 'line-num' },
Chris@909 224 :content => '32',
Chris@909 225 :sibling => {
Chris@909 226 :tag => 'td',
Chris@909 227 :attributes => { :class => 'revision' },
Chris@909 228 :content => /1.2/,
Chris@909 229 :sibling => {
Chris@909 230 :tag => 'td',
Chris@909 231 :attributes => { :class => 'author' },
Chris@909 232 :content => /LANG/
Chris@909 233 }
Chris@909 234 }
Chris@909 235 end
Chris@909 236
Chris@909 237 def test_destroy_valid_repository
Chris@909 238 @request.session[:user_id] = 1 # admin
Chris@909 239 assert_equal 0, @repository.changesets.count
Chris@909 240 @repository.fetch_changesets
Chris@909 241 @project.reload
Chris@909 242 assert_equal NUM_REV, @repository.changesets.count
Chris@909 243
Chris@909 244 get :destroy, :id => PRJ_ID
Chris@909 245 assert_response 302
Chris@909 246 @project.reload
Chris@909 247 assert_nil @project.repository
Chris@909 248 end
Chris@909 249
Chris@909 250 def test_destroy_invalid_repository
Chris@909 251 @request.session[:user_id] = 1 # admin
Chris@909 252 assert_equal 0, @repository.changesets.count
Chris@909 253 @repository.fetch_changesets
Chris@909 254 @project.reload
Chris@909 255 assert_equal NUM_REV, @repository.changesets.count
Chris@909 256
Chris@909 257 get :destroy, :id => PRJ_ID
Chris@909 258 assert_response 302
Chris@909 259 @project.reload
Chris@909 260 assert_nil @project.repository
Chris@909 261
Chris@909 262 @repository = Repository::Cvs.create(
Chris@909 263 :project => Project.find(PRJ_ID),
Chris@909 264 :root_url => "/invalid",
Chris@909 265 :url => MODULE_NAME,
Chris@909 266 :log_encoding => 'UTF-8'
Chris@909 267 )
Chris@909 268 assert @repository
Chris@909 269 @repository.fetch_changesets
Chris@909 270 @project.reload
Chris@909 271 assert_equal 0, @repository.changesets.count
Chris@909 272
Chris@909 273 get :destroy, :id => PRJ_ID
Chris@909 274 assert_response 302
Chris@909 275 @project.reload
Chris@909 276 assert_nil @project.repository
Chris@909 277 end
Chris@909 278 else
Chris@909 279 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
Chris@909 280 def test_fake; assert true end
Chris@909 281 end
Chris@909 282 end