annotate .svn/pristine/47/47694602d9a870af8493bfa368efb91080cdc615.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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