annotate .svn/pristine/69/69aea32e67c1e43bf9542a209fc02cf6c1b5854c.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
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 RepositoriesBazaarControllerTest < 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/bazaar_repository/trunk').to_s
Chris@909 29 PRJ_ID = 3
Chris@909 30
Chris@909 31 def setup
Chris@909 32 @controller = RepositoriesController.new
Chris@909 33 @request = ActionController::TestRequest.new
Chris@909 34 @response = ActionController::TestResponse.new
Chris@909 35 User.current = nil
Chris@909 36 @project = Project.find(PRJ_ID)
Chris@909 37 @repository = Repository::Bazaar.create(
Chris@909 38 :project => @project,
Chris@909 39 :url => REPOSITORY_PATH,
Chris@909 40 :log_encoding => 'UTF-8')
Chris@909 41 assert @repository
Chris@909 42 end
Chris@909 43
Chris@909 44 if File.directory?(REPOSITORY_PATH)
Chris@909 45 def test_browse_root
Chris@909 46 get :show, :id => PRJ_ID
Chris@909 47 assert_response :success
Chris@909 48 assert_template 'show'
Chris@909 49 assert_not_nil assigns(:entries)
Chris@909 50 assert_equal 2, assigns(:entries).size
Chris@909 51 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
Chris@909 52 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
Chris@909 53 end
Chris@909 54
Chris@909 55 def test_browse_directory
Chris@909 56 get :show, :id => PRJ_ID, :path => ['directory']
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 ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
Chris@909 61 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@909 62 assert_not_nil entry
Chris@909 63 assert_equal 'file', entry.kind
Chris@909 64 assert_equal 'directory/edit.png', entry.path
Chris@909 65 end
Chris@909 66
Chris@909 67 def test_browse_at_given_revision
Chris@909 68 get :show, :id => PRJ_ID, :path => [], :rev => 3
Chris@909 69 assert_response :success
Chris@909 70 assert_template 'show'
Chris@909 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@909 74 end
Chris@909 75
Chris@909 76 def test_changes
Chris@909 77 get :changes, :id => PRJ_ID, :path => ['doc-mkdir.txt']
Chris@909 78 assert_response :success
Chris@909 79 assert_template 'changes'
Chris@909 80 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
Chris@909 81 end
Chris@909 82
Chris@909 83 def test_entry_show
Chris@909 84 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt']
Chris@909 85 assert_response :success
Chris@909 86 assert_template 'entry'
Chris@909 87 # Line 19
Chris@909 88 assert_tag :tag => 'th',
Chris@909 89 :content => /29/,
Chris@909 90 :attributes => { :class => /line-num/ },
Chris@909 91 :sibling => { :tag => 'td', :content => /Show help message/ }
Chris@909 92 end
Chris@909 93
Chris@909 94 def test_entry_download
Chris@909 95 get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'], :format => 'raw'
Chris@909 96 assert_response :success
Chris@909 97 # File content
Chris@909 98 assert @response.body.include?('Show help message')
Chris@909 99 end
Chris@909 100
Chris@909 101 def test_directory_entry
Chris@909 102 get :entry, :id => PRJ_ID, :path => ['directory']
Chris@909 103 assert_response :success
Chris@909 104 assert_template 'show'
Chris@909 105 assert_not_nil assigns(:entry)
Chris@909 106 assert_equal 'directory', assigns(:entry).name
Chris@909 107 end
Chris@909 108
Chris@909 109 def test_diff
Chris@909 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@909 122 end
Chris@909 123
Chris@909 124 def test_annotate
Chris@909 125 get :annotate, :id => PRJ_ID, :path => ['doc-mkdir.txt']
Chris@909 126 assert_response :success
Chris@909 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@909 147 :sibling => { :tag => 'td', :content => /Main purpose/ }
Chris@909 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@909 189 else
Chris@909 190 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
Chris@909 191 def test_fake; assert true end
Chris@909 192 end
Chris@909 193 end