annotate test/functional/repositories_bazaar_controller_test.rb @ 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 433d4f72a19b
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'repositories_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class RepositoriesBazaarControllerTest < ActionController::TestCase
Chris@909 25 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 26 :repositories, :enabled_modules
Chris@0 27
Chris@909 28 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
Chris@909 29 PRJ_ID = 3
Chris@0 30
Chris@0 31 def setup
Chris@0 32 @controller = RepositoriesController.new
Chris@0 33 @request = ActionController::TestRequest.new
Chris@0 34 @response = ActionController::TestResponse.new
Chris@0 35 User.current = nil
Chris@909 36 @project = Project.find(PRJ_ID)
Chris@245 37 @repository = Repository::Bazaar.create(
Chris@909 38 :project => @project,
Chris@909 39 :url => REPOSITORY_PATH,
Chris@245 40 :log_encoding => 'UTF-8')
Chris@245 41 assert @repository
Chris@0 42 end
Chris@245 43
Chris@0 44 if File.directory?(REPOSITORY_PATH)
Chris@0 45 def test_browse_root
Chris@909 46 get :show, :id => PRJ_ID
Chris@0 47 assert_response :success
Chris@0 48 assert_template 'show'
Chris@0 49 assert_not_nil assigns(:entries)
Chris@0 50 assert_equal 2, assigns(:entries).size
Chris@0 51 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
Chris@0 52 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
Chris@0 53 end
Chris@245 54
Chris@0 55 def test_browse_directory
Chris@909 56 get :show, :id => PRJ_ID, :path => ['directory']
Chris@0 57 assert_response :success
Chris@0 58 assert_template 'show'
Chris@0 59 assert_not_nil assigns(:entries)
Chris@0 60 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 61 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 62 assert_not_nil entry
Chris@0 63 assert_equal 'file', entry.kind
Chris@0 64 assert_equal 'directory/edit.png', entry.path
Chris@0 65 end
Chris@909 66
Chris@0 67 def test_browse_at_given_revision
Chris@909 68 get :show, :id => PRJ_ID, :path => [], :rev => 3
Chris@0 69 assert_response :success
Chris@0 70 assert_template 'show'
Chris@0 71 assert_not_nil assigns(:entries)
Chris@909 72 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
Chris@909 73 assigns(:entries).collect(&:name)
Chris@0 74 end
Chris@909 75
Chris@0 76 def test_changes
Chris@909 77 get :changes, :id => PRJ_ID, :path => ['doc-mkdir.txt']
Chris@0 78 assert_response :success
Chris@0 79 assert_template 'changes'
Chris@0 80 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
Chris@0 81 end
Chris@909 82
Chris@0 83 def test_entry_show
Chris@909 84 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt']
Chris@0 85 assert_response :success
Chris@0 86 assert_template 'entry'
Chris@0 87 # Line 19
Chris@0 88 assert_tag :tag => 'th',
Chris@0 89 :content => /29/,
Chris@0 90 :attributes => { :class => /line-num/ },
Chris@0 91 :sibling => { :tag => 'td', :content => /Show help message/ }
Chris@0 92 end
Chris@909 93
Chris@0 94 def test_entry_download
Chris@909 95 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'], :format => 'raw'
Chris@0 96 assert_response :success
Chris@0 97 # File content
Chris@0 98 assert @response.body.include?('Show help message')
Chris@0 99 end
Chris@909 100
Chris@0 101 def test_directory_entry
Chris@909 102 get :entry, :id => PRJ_ID, :path => ['directory']
Chris@0 103 assert_response :success
Chris@0 104 assert_template 'show'
Chris@0 105 assert_not_nil assigns(:entry)
Chris@0 106 assert_equal 'directory', assigns(:entry).name
Chris@0 107 end
Chris@0 108
Chris@0 109 def test_diff
Chris@0 110 # Full diff of changeset 3
Chris@909 111 ['inline', 'sbs'].each do |dt|
Chris@909 112 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@909 113 assert_response :success
Chris@909 114 assert_template 'diff'
Chris@909 115 # Line 11 removed
Chris@909 116 assert_tag :tag => 'th',
Chris@909 117 :content => '11',
Chris@909 118 :sibling => { :tag => 'td',
Chris@909 119 :attributes => { :class => /diff_out/ },
Chris@909 120 :content => /Display more information/ }
Chris@909 121 end
Chris@0 122 end
Chris@909 123
Chris@0 124 def test_annotate
Chris@909 125 get :annotate, :id => PRJ_ID, :path => ['doc-mkdir.txt']
Chris@0 126 assert_response :success
Chris@0 127 assert_template 'annotate'
Chris@909 128 assert_tag :tag => 'th', :content => '2',
Chris@909 129 :sibling => {
Chris@909 130 :tag => 'td',
Chris@909 131 :child => {
Chris@909 132 :tag => 'a',
Chris@909 133 :content => '3'
Chris@909 134 }
Chris@909 135 }
Chris@909 136 assert_tag :tag => 'th', :content => '2',
Chris@909 137 :sibling => { :tag => 'td', :content => /jsmith/ }
Chris@909 138 assert_tag :tag => 'th', :content => '2',
Chris@909 139 :sibling => {
Chris@909 140 :tag => 'td',
Chris@909 141 :child => {
Chris@909 142 :tag => 'a',
Chris@909 143 :content => '3'
Chris@909 144 }
Chris@909 145 }
Chris@909 146 assert_tag :tag => 'th', :content => '2',
Chris@0 147 :sibling => { :tag => 'td', :content => /Main purpose/ }
Chris@0 148 end
Chris@909 149
Chris@909 150 def test_destroy_valid_repository
Chris@909 151 @request.session[:user_id] = 1 # admin
Chris@909 152 assert_equal 0, @repository.changesets.count
Chris@909 153 @repository.fetch_changesets
Chris@909 154 @project.reload
Chris@909 155 assert @repository.changesets.count > 0
Chris@909 156
Chris@909 157 get :destroy, :id => PRJ_ID
Chris@909 158 assert_response 302
Chris@909 159 @project.reload
Chris@909 160 assert_nil @project.repository
Chris@909 161 end
Chris@909 162
Chris@909 163 def test_destroy_invalid_repository
Chris@909 164 @request.session[:user_id] = 1 # admin
Chris@909 165 assert_equal 0, @repository.changesets.count
Chris@909 166 @repository.fetch_changesets
Chris@909 167 @project.reload
Chris@909 168 assert @repository.changesets.count > 0
Chris@909 169
Chris@909 170 get :destroy, :id => PRJ_ID
Chris@909 171 assert_response 302
Chris@909 172 @project.reload
Chris@909 173 assert_nil @project.repository
Chris@909 174
Chris@909 175 @repository = Repository::Bazaar.create(
Chris@909 176 :project => @project,
Chris@909 177 :url => "/invalid",
Chris@909 178 :log_encoding => 'UTF-8')
Chris@909 179 assert @repository
Chris@909 180 @repository.fetch_changesets
Chris@909 181 @repository.reload
Chris@909 182 assert_equal 0, @repository.changesets.count
Chris@909 183
Chris@909 184 get :destroy, :id => PRJ_ID
Chris@909 185 assert_response 302
Chris@909 186 @project.reload
Chris@909 187 assert_nil @project.repository
Chris@909 188 end
Chris@0 189 else
Chris@0 190 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 191 def test_fake; assert true end
Chris@0 192 end
Chris@0 193 end