annotate .svn/pristine/38/385f3eab1c979f41797640419fbb6f558b89820f.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 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 RepositoryBazaarTest < ActiveSupport::TestCase
Chris@1494 21 fixtures :projects
Chris@1494 22
Chris@1494 23 include Redmine::I18n
Chris@1494 24
Chris@1494 25 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
Chris@1494 26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
Chris@1494 27 NUM_REV = 4
Chris@1494 28
Chris@1494 29 REPOSITORY_PATH_NON_ASCII = Rails.root.join(REPOSITORY_PATH + '/' + 'non_ascii').to_s
Chris@1494 30
Chris@1494 31 # Bazaar core does not support xml output such as Subversion and Mercurial.
Chris@1494 32 # "bzr" command output and command line parameter depend on locale.
Chris@1494 33 # So, non ASCII path tests cannot run independent locale.
Chris@1494 34 #
Chris@1494 35 # If you want to run Bazaar non ASCII path tests on Linux *Ruby 1.9*,
Chris@1494 36 # you need to set locale character set "ISO-8859-1".
Chris@1494 37 # E.g. "LANG=en_US.ISO-8859-1".
Chris@1494 38 # On Linux other platforms (e.g. Ruby 1.8, JRuby),
Chris@1494 39 # you need to set "RUN_LATIN1_OUTPUT_TEST = true" manually.
Chris@1494 40 #
Chris@1494 41 # On Windows, because it is too hard to change system locale,
Chris@1494 42 # you cannot run Bazaar non ASCII path tests.
Chris@1494 43 #
Chris@1494 44 RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
Chris@1494 45 REPOSITORY_PATH.respond_to?(:force_encoding) &&
Chris@1494 46 Encoding.locale_charmap == "ISO-8859-1")
Chris@1494 47
Chris@1494 48 CHAR_1_UTF8_HEX = "\xc3\x9c"
Chris@1494 49 CHAR_1_LATIN1_HEX = "\xdc"
Chris@1494 50
Chris@1494 51 def setup
Chris@1494 52 @project = Project.find(3)
Chris@1494 53 @repository = Repository::Bazaar.create(
Chris@1494 54 :project => @project, :url => REPOSITORY_PATH_TRUNK,
Chris@1494 55 :log_encoding => 'UTF-8')
Chris@1494 56 assert @repository
Chris@1494 57 @char_1_utf8 = CHAR_1_UTF8_HEX.dup
Chris@1494 58 @char_1_ascii8bit = CHAR_1_LATIN1_HEX.dup
Chris@1494 59 if @char_1_utf8.respond_to?(:force_encoding)
Chris@1494 60 @char_1_utf8.force_encoding('UTF-8')
Chris@1494 61 @char_1_ascii8bit.force_encoding('ASCII-8BIT')
Chris@1494 62 end
Chris@1494 63 end
Chris@1494 64
Chris@1494 65 def test_blank_path_to_repository_error_message
Chris@1494 66 set_language_if_valid 'en'
Chris@1494 67 repo = Repository::Bazaar.new(
Chris@1494 68 :project => @project,
Chris@1494 69 :identifier => 'test',
Chris@1494 70 :log_encoding => 'UTF-8'
Chris@1494 71 )
Chris@1494 72 assert !repo.save
Chris@1494 73 assert_include "Path to repository can't be blank",
Chris@1494 74 repo.errors.full_messages
Chris@1494 75 end
Chris@1494 76
Chris@1494 77 def test_blank_path_to_repository_error_message_fr
Chris@1494 78 set_language_if_valid 'fr'
Chris@1494 79 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
Chris@1494 80 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
Chris@1494 81 repo = Repository::Bazaar.new(
Chris@1494 82 :project => @project,
Chris@1494 83 :url => "",
Chris@1494 84 :identifier => 'test',
Chris@1494 85 :log_encoding => 'UTF-8'
Chris@1494 86 )
Chris@1494 87 assert !repo.save
Chris@1494 88 assert_include str, repo.errors.full_messages
Chris@1494 89 end
Chris@1494 90
Chris@1494 91 if File.directory?(REPOSITORY_PATH_TRUNK)
Chris@1494 92 def test_fetch_changesets_from_scratch
Chris@1494 93 assert_equal 0, @repository.changesets.count
Chris@1494 94 @repository.fetch_changesets
Chris@1494 95 @project.reload
Chris@1494 96
Chris@1494 97 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 98 assert_equal 9, @repository.filechanges.count
Chris@1494 99 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
Chris@1494 100 end
Chris@1494 101
Chris@1494 102 def test_fetch_changesets_incremental
Chris@1494 103 assert_equal 0, @repository.changesets.count
Chris@1494 104 @repository.fetch_changesets
Chris@1494 105 @project.reload
Chris@1494 106 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 107 # Remove changesets with revision > 5
Chris@1494 108 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
Chris@1494 109 @project.reload
Chris@1494 110 assert_equal 2, @repository.changesets.count
Chris@1494 111
Chris@1494 112 @repository.fetch_changesets
Chris@1494 113 @project.reload
Chris@1494 114 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 115 end
Chris@1494 116
Chris@1494 117 def test_entries
Chris@1494 118 entries = @repository.entries
Chris@1494 119 assert_kind_of Redmine::Scm::Adapters::Entries, entries
Chris@1494 120 assert_equal 2, entries.size
Chris@1494 121
Chris@1494 122 assert_equal 'dir', entries[0].kind
Chris@1494 123 assert_equal 'directory', entries[0].name
Chris@1494 124 assert_equal 'directory', entries[0].path
Chris@1494 125
Chris@1494 126 assert_equal 'file', entries[1].kind
Chris@1494 127 assert_equal 'doc-mkdir.txt', entries[1].name
Chris@1494 128 assert_equal 'doc-mkdir.txt', entries[1].path
Chris@1494 129 end
Chris@1494 130
Chris@1494 131 def test_entries_in_subdirectory
Chris@1494 132 entries = @repository.entries('directory')
Chris@1494 133 assert_equal 3, entries.size
Chris@1494 134
Chris@1494 135 assert_equal 'file', entries.last.kind
Chris@1494 136 assert_equal 'edit.png', entries.last.name
Chris@1494 137 assert_equal 'directory/edit.png', entries.last.path
Chris@1494 138 end
Chris@1494 139
Chris@1494 140 def test_previous
Chris@1494 141 assert_equal 0, @repository.changesets.count
Chris@1494 142 @repository.fetch_changesets
Chris@1494 143 @project.reload
Chris@1494 144 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 145 changeset = @repository.find_changeset_by_name('3')
Chris@1494 146 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
Chris@1494 147 end
Chris@1494 148
Chris@1494 149 def test_previous_nil
Chris@1494 150 assert_equal 0, @repository.changesets.count
Chris@1494 151 @repository.fetch_changesets
Chris@1494 152 @project.reload
Chris@1494 153 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 154 changeset = @repository.find_changeset_by_name('1')
Chris@1494 155 assert_nil changeset.previous
Chris@1494 156 end
Chris@1494 157
Chris@1494 158 def test_next
Chris@1494 159 assert_equal 0, @repository.changesets.count
Chris@1494 160 @repository.fetch_changesets
Chris@1494 161 @project.reload
Chris@1494 162 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 163 changeset = @repository.find_changeset_by_name('2')
Chris@1494 164 assert_equal @repository.find_changeset_by_name('3'), changeset.next
Chris@1494 165 end
Chris@1494 166
Chris@1494 167 def test_next_nil
Chris@1494 168 assert_equal 0, @repository.changesets.count
Chris@1494 169 @repository.fetch_changesets
Chris@1494 170 @project.reload
Chris@1494 171 assert_equal NUM_REV, @repository.changesets.count
Chris@1494 172 changeset = @repository.find_changeset_by_name('4')
Chris@1494 173 assert_nil changeset.next
Chris@1494 174 end
Chris@1494 175
Chris@1494 176 if File.directory?(REPOSITORY_PATH_NON_ASCII) && RUN_LATIN1_OUTPUT_TEST
Chris@1494 177 def test_cat_latin1_path
Chris@1494 178 latin1_repo = create_latin1_repo
Chris@1494 179 buf = latin1_repo.cat(
Chris@1494 180 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
Chris@1494 181 assert buf
Chris@1494 182 lines = buf.split("\n")
Chris@1494 183 assert_equal 2, lines.length
Chris@1494 184 assert_equal 'It is written in Python.', lines[1]
Chris@1494 185
Chris@1494 186 buf = latin1_repo.cat(
Chris@1494 187 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
Chris@1494 188 assert buf
Chris@1494 189 lines = buf.split("\n")
Chris@1494 190 assert_equal 1, lines.length
Chris@1494 191 assert_equal "test-#{@char_1_ascii8bit}.txt", lines[0]
Chris@1494 192 end
Chris@1494 193
Chris@1494 194 def test_annotate_latin1_path
Chris@1494 195 latin1_repo = create_latin1_repo
Chris@1494 196 ann1 = latin1_repo.annotate(
Chris@1494 197 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
Chris@1494 198 assert_equal 2, ann1.lines.size
Chris@1494 199 assert_equal '2', ann1.revisions[0].identifier
Chris@1494 200 assert_equal 'test00@', ann1.revisions[0].author
Chris@1494 201 assert_equal 'It is written in Python.', ann1.lines[1]
Chris@1494 202 ann2 = latin1_repo.annotate(
Chris@1494 203 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
Chris@1494 204 assert_equal 1, ann2.lines.size
Chris@1494 205 assert_equal '2', ann2.revisions[0].identifier
Chris@1494 206 assert_equal 'test00@', ann2.revisions[0].author
Chris@1494 207 assert_equal "test-#{@char_1_ascii8bit}.txt", ann2.lines[0]
Chris@1494 208 end
Chris@1494 209
Chris@1494 210 def test_diff_latin1_path
Chris@1494 211 latin1_repo = create_latin1_repo
Chris@1494 212 diff1 = latin1_repo.diff(
Chris@1494 213 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2, 1)
Chris@1494 214 assert_equal 7, diff1.size
Chris@1494 215 buf = diff1[5].gsub(/\r\n|\r|\n/, "")
Chris@1494 216 assert_equal "+test-#{@char_1_ascii8bit}.txt", buf
Chris@1494 217 end
Chris@1494 218
Chris@1494 219 def test_entries_latin1_path
Chris@1494 220 latin1_repo = create_latin1_repo
Chris@1494 221 entries = latin1_repo.entries("test-#{@char_1_utf8}-dir", 2)
Chris@1494 222 assert_kind_of Redmine::Scm::Adapters::Entries, entries
Chris@1494 223 assert_equal 3, entries.size
Chris@1494 224 assert_equal 'file', entries[1].kind
Chris@1494 225 assert_equal "test-#{@char_1_utf8}-1.txt", entries[0].name
Chris@1494 226 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", entries[0].path
Chris@1494 227 end
Chris@1494 228
Chris@1494 229 def test_entry_latin1_path
Chris@1494 230 latin1_repo = create_latin1_repo
Chris@1494 231 ["test-#{@char_1_utf8}-dir",
Chris@1494 232 "/test-#{@char_1_utf8}-dir",
Chris@1494 233 "/test-#{@char_1_utf8}-dir/"
Chris@1494 234 ].each do |path|
Chris@1494 235 entry = latin1_repo.entry(path, 2)
Chris@1494 236 assert_equal "test-#{@char_1_utf8}-dir", entry.path
Chris@1494 237 assert_equal "dir", entry.kind
Chris@1494 238 end
Chris@1494 239 ["test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
Chris@1494 240 "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt"
Chris@1494 241 ].each do |path|
Chris@1494 242 entry = latin1_repo.entry(path, 2)
Chris@1494 243 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
Chris@1494 244 entry.path
Chris@1494 245 assert_equal "file", entry.kind
Chris@1494 246 end
Chris@1494 247 end
Chris@1494 248
Chris@1494 249 def test_changeset_latin1_path
Chris@1494 250 latin1_repo = create_latin1_repo
Chris@1494 251 assert_equal 0, latin1_repo.changesets.count
Chris@1494 252 latin1_repo.fetch_changesets
Chris@1494 253 @project.reload
Chris@1494 254 assert_equal 3, latin1_repo.changesets.count
Chris@1494 255
Chris@1494 256 cs2 = latin1_repo.changesets.find_by_revision('2')
Chris@1494 257 assert_not_nil cs2
Chris@1494 258 assert_equal "test-#{@char_1_utf8}", cs2.comments
Chris@1494 259 c2 = cs2.filechanges.sort_by(&:path)
Chris@1494 260 assert_equal 4, c2.size
Chris@1494 261 assert_equal 'A', c2[0].action
Chris@1494 262 assert_equal "/test-#{@char_1_utf8}-dir/", c2[0].path
Chris@1494 263 assert_equal 'A', c2[1].action
Chris@1494 264 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", c2[1].path
Chris@1494 265 assert_equal 'A', c2[2].action
Chris@1494 266 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c2[2].path
Chris@1494 267 assert_equal 'A', c2[3].action
Chris@1494 268 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c2[3].path
Chris@1494 269
Chris@1494 270 cs3 = latin1_repo.changesets.find_by_revision('3')
Chris@1494 271 assert_not_nil cs3
Chris@1494 272 assert_equal "modify, move and delete #{@char_1_utf8} files", cs3.comments
Chris@1494 273 c3 = cs3.filechanges.sort_by(&:path)
Chris@1494 274 assert_equal 3, c3.size
Chris@1494 275 assert_equal 'M', c3[0].action
Chris@1494 276 assert_equal "/test-#{@char_1_utf8}-1.txt", c3[0].path
Chris@1494 277 assert_equal 'D', c3[1].action
Chris@1494 278 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c3[1].path
Chris@1494 279 assert_equal 'M', c3[2].action
Chris@1494 280 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c3[2].path
Chris@1494 281 end
Chris@1494 282 else
Chris@1494 283 msg = "Bazaar non ASCII output test cannot run this environment." + "\n"
Chris@1494 284 if msg.respond_to?(:force_encoding)
Chris@1494 285 msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
Chris@1494 286 end
Chris@1494 287 puts msg
Chris@1494 288 end
Chris@1494 289
Chris@1494 290 private
Chris@1494 291
Chris@1494 292 def create_latin1_repo
Chris@1494 293 repo = Repository::Bazaar.create(
Chris@1494 294 :project => @project,
Chris@1494 295 :identifier => 'latin1',
Chris@1494 296 :url => REPOSITORY_PATH_NON_ASCII,
Chris@1494 297 :log_encoding => 'ISO-8859-1'
Chris@1494 298 )
Chris@1494 299 assert repo
Chris@1494 300 repo
Chris@1494 301 end
Chris@1494 302 else
Chris@1494 303 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
Chris@1494 304 def test_fake; assert true end
Chris@1494 305 end
Chris@1494 306 end