annotate .svn/pristine/0f/0fc81c2978046c22ad1fddeadeabe4e288474193.svn-base @ 1494:e248c7af89ec redmine-2.4

Update to Redmine SVN revision 12979 on 2.4-stable branch
author Chris Cannam
date Mon, 17 Mar 2014 08:54:02 +0000
parents 261b3d9a4903
children
rev   line source
Chris@1464 1 # Redmine - project management software
Chris@1464 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1464 3 #
Chris@1464 4 # This program is free software; you can redistribute it and/or
Chris@1464 5 # modify it under the terms of the GNU General Public License
Chris@1464 6 # as published by the Free Software Foundation; either version 2
Chris@1464 7 # of the License, or (at your option) any later version.
Chris@1464 8 #
Chris@1464 9 # This program is distributed in the hope that it will be useful,
Chris@1464 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1464 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1464 12 # GNU General Public License for more details.
Chris@1464 13 #
Chris@1464 14 # You should have received a copy of the GNU General Public License
Chris@1464 15 # along with this program; if not, write to the Free Software
Chris@1464 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1464 17
Chris@1464 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1464 19
Chris@1464 20 class RepositoriesBazaarControllerTest < ActionController::TestCase
Chris@1464 21 tests RepositoriesController
Chris@1464 22
Chris@1464 23 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@1464 24 :repositories, :enabled_modules
Chris@1464 25
Chris@1464 26 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
Chris@1464 27 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
Chris@1464 28 PRJ_ID = 3
Chris@1464 29 CHAR_1_UTF8_HEX = "\xc3\x9c"
Chris@1464 30
Chris@1464 31 def setup
Chris@1464 32 User.current = nil
Chris@1464 33 @project = Project.find(PRJ_ID)
Chris@1464 34 @repository = Repository::Bazaar.create(
Chris@1464 35 :project => @project,
Chris@1464 36 :url => REPOSITORY_PATH_TRUNK,
Chris@1464 37 :log_encoding => 'UTF-8')
Chris@1464 38 assert @repository
Chris@1464 39 @char_1_utf8 = CHAR_1_UTF8_HEX.dup
Chris@1464 40 if @char_1_utf8.respond_to?(:force_encoding)
Chris@1464 41 @char_1_utf8.force_encoding('UTF-8')
Chris@1464 42 end
Chris@1464 43 end
Chris@1464 44
Chris@1464 45 if File.directory?(REPOSITORY_PATH)
Chris@1464 46 def test_get_new
Chris@1464 47 @request.session[:user_id] = 1
Chris@1464 48 @project.repository.destroy
Chris@1464 49 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
Chris@1464 50 assert_response :success
Chris@1464 51 assert_template 'new'
Chris@1464 52 assert_kind_of Repository::Bazaar, assigns(:repository)
Chris@1464 53 assert assigns(:repository).new_record?
Chris@1464 54 end
Chris@1464 55
Chris@1464 56 def test_browse_root
Chris@1464 57 get :show, :id => PRJ_ID
Chris@1464 58 assert_response :success
Chris@1464 59 assert_template 'show'
Chris@1464 60 assert_not_nil assigns(:entries)
Chris@1464 61 assert_equal 2, assigns(:entries).size
Chris@1464 62 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
Chris@1464 63 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
Chris@1464 64 end
Chris@1464 65
Chris@1464 66 def test_browse_directory
Chris@1464 67 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
Chris@1464 68 assert_response :success
Chris@1464 69 assert_template 'show'
Chris@1464 70 assert_not_nil assigns(:entries)
Chris@1464 71 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
Chris@1464 72 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@1464 73 assert_not_nil entry
Chris@1464 74 assert_equal 'file', entry.kind
Chris@1464 75 assert_equal 'directory/edit.png', entry.path
Chris@1464 76 end
Chris@1464 77
Chris@1464 78 def test_browse_at_given_revision
Chris@1464 79 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
Chris@1464 80 :rev => 3
Chris@1464 81 assert_response :success
Chris@1464 82 assert_template 'show'
Chris@1464 83 assert_not_nil assigns(:entries)
Chris@1464 84 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
Chris@1464 85 assigns(:entries).collect(&:name)
Chris@1464 86 end
Chris@1464 87
Chris@1464 88 def test_changes
Chris@1464 89 get :changes, :id => PRJ_ID,
Chris@1464 90 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
Chris@1464 91 assert_response :success
Chris@1464 92 assert_template 'changes'
Chris@1464 93 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
Chris@1464 94 end
Chris@1464 95
Chris@1464 96 def test_entry_show
Chris@1464 97 get :entry, :id => PRJ_ID,
Chris@1464 98 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
Chris@1464 99 assert_response :success
Chris@1464 100 assert_template 'entry'
Chris@1464 101 # Line 19
Chris@1464 102 assert_tag :tag => 'th',
Chris@1464 103 :content => /29/,
Chris@1464 104 :attributes => { :class => /line-num/ },
Chris@1464 105 :sibling => { :tag => 'td', :content => /Show help message/ }
Chris@1464 106 end
Chris@1464 107
Chris@1464 108 def test_entry_download
Chris@1464 109 get :entry, :id => PRJ_ID,
Chris@1464 110 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
Chris@1464 111 :format => 'raw'
Chris@1464 112 assert_response :success
Chris@1464 113 # File content
Chris@1464 114 assert @response.body.include?('Show help message')
Chris@1464 115 end
Chris@1464 116
Chris@1464 117 def test_directory_entry
Chris@1464 118 get :entry, :id => PRJ_ID,
Chris@1464 119 :path => repository_path_hash(['directory'])[:param]
Chris@1464 120 assert_response :success
Chris@1464 121 assert_template 'show'
Chris@1464 122 assert_not_nil assigns(:entry)
Chris@1464 123 assert_equal 'directory', assigns(:entry).name
Chris@1464 124 end
Chris@1464 125
Chris@1464 126 def test_diff
Chris@1464 127 # Full diff of changeset 3
Chris@1464 128 ['inline', 'sbs'].each do |dt|
Chris@1464 129 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
Chris@1464 130 assert_response :success
Chris@1464 131 assert_template 'diff'
Chris@1464 132 # Line 11 removed
Chris@1464 133 assert_tag :tag => 'th',
Chris@1464 134 :content => '11',
Chris@1464 135 :sibling => { :tag => 'td',
Chris@1464 136 :attributes => { :class => /diff_out/ },
Chris@1464 137 :content => /Display more information/ }
Chris@1464 138 end
Chris@1464 139 end
Chris@1464 140
Chris@1464 141 def test_annotate
Chris@1464 142 get :annotate, :id => PRJ_ID,
Chris@1464 143 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
Chris@1464 144 assert_response :success
Chris@1464 145 assert_template 'annotate'
Chris@1464 146 assert_select "th.line-num", :text => '2' do
Chris@1464 147 assert_select "+ td.revision" do
Chris@1464 148 assert_select "a", :text => '3'
Chris@1464 149 assert_select "+ td.author", :text => "jsmith@" do
Chris@1464 150 assert_select "+ td",
Chris@1464 151 :text => "Main purpose:"
Chris@1464 152 end
Chris@1464 153 end
Chris@1464 154 end
Chris@1464 155 end
Chris@1464 156
Chris@1464 157 def test_annotate_author_escaping
Chris@1464 158 repository = Repository::Bazaar.create(
Chris@1464 159 :project => @project,
Chris@1464 160 :url => File.join(REPOSITORY_PATH, "author_escaping"),
Chris@1464 161 :identifier => 'author_escaping',
Chris@1464 162 :log_encoding => 'UTF-8')
Chris@1464 163 assert repository
Chris@1464 164 get :annotate, :id => PRJ_ID, :repository_id => 'author_escaping',
Chris@1464 165 :path => repository_path_hash(['author-escaping-test.txt'])[:param]
Chris@1464 166 assert_response :success
Chris@1464 167 assert_template 'annotate'
Chris@1464 168 assert_select "th.line-num", :text => '1' do
Chris@1464 169 assert_select "+ td.revision" do
Chris@1464 170 assert_select "a", :text => '2'
Chris@1464 171 assert_select "+ td.author", :text => "test &amp;" do
Chris@1464 172 assert_select "+ td",
Chris@1464 173 :text => "author escaping test"
Chris@1464 174 end
Chris@1464 175 end
Chris@1464 176 end
Chris@1464 177 end
Chris@1464 178
Chris@1464 179 if REPOSITORY_PATH.respond_to?(:force_encoding)
Chris@1464 180 def test_annotate_author_non_ascii
Chris@1464 181 log_encoding = nil
Chris@1464 182 if Encoding.locale_charmap == "UTF-8" ||
Chris@1464 183 Encoding.locale_charmap == "ISO-8859-1"
Chris@1464 184 log_encoding = Encoding.locale_charmap
Chris@1464 185 end
Chris@1464 186 unless log_encoding.nil?
Chris@1464 187 repository = Repository::Bazaar.create(
Chris@1464 188 :project => @project,
Chris@1464 189 :url => File.join(REPOSITORY_PATH, "author_non_ascii"),
Chris@1464 190 :identifier => 'author_non_ascii',
Chris@1464 191 :log_encoding => log_encoding)
Chris@1464 192 assert repository
Chris@1464 193 get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii',
Chris@1464 194 :path => repository_path_hash(['author-non-ascii-test.txt'])[:param]
Chris@1464 195 assert_response :success
Chris@1464 196 assert_template 'annotate'
Chris@1464 197 assert_select "th.line-num", :text => '1' do
Chris@1464 198 assert_select "+ td.revision" do
Chris@1464 199 assert_select "a", :text => '2'
Chris@1464 200 assert_select "+ td.author", :text => "test #{@char_1_utf8}" do
Chris@1464 201 assert_select "+ td",
Chris@1464 202 :text => "author non ASCII test"
Chris@1464 203 end
Chris@1464 204 end
Chris@1464 205 end
Chris@1464 206 end
Chris@1464 207 end
Chris@1464 208 end
Chris@1464 209
Chris@1464 210 def test_destroy_valid_repository
Chris@1464 211 @request.session[:user_id] = 1 # admin
Chris@1464 212 assert_equal 0, @repository.changesets.count
Chris@1464 213 @repository.fetch_changesets
Chris@1464 214 assert @repository.changesets.count > 0
Chris@1464 215
Chris@1464 216 assert_difference 'Repository.count', -1 do
Chris@1464 217 delete :destroy, :id => @repository.id
Chris@1464 218 end
Chris@1464 219 assert_response 302
Chris@1464 220 @project.reload
Chris@1464 221 assert_nil @project.repository
Chris@1464 222 end
Chris@1464 223
Chris@1464 224 def test_destroy_invalid_repository
Chris@1464 225 @request.session[:user_id] = 1 # admin
Chris@1464 226 @project.repository.destroy
Chris@1464 227 @repository = Repository::Bazaar.create!(
Chris@1464 228 :project => @project,
Chris@1464 229 :url => "/invalid",
Chris@1464 230 :log_encoding => 'UTF-8')
Chris@1464 231 @repository.fetch_changesets
Chris@1464 232 @repository.reload
Chris@1464 233 assert_equal 0, @repository.changesets.count
Chris@1464 234
Chris@1464 235 assert_difference 'Repository.count', -1 do
Chris@1464 236 delete :destroy, :id => @repository.id
Chris@1464 237 end
Chris@1464 238 assert_response 302
Chris@1464 239 @project.reload
Chris@1464 240 assert_nil @project.repository
Chris@1464 241 end
Chris@1464 242 else
Chris@1464 243 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
Chris@1464 244 def test_fake; assert true end
Chris@1464 245 end
Chris@1464 246 end