annotate .svn/pristine/99/9948cbe9e3d5de834eb36bf44c3b5e49142db619.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 begin
Chris@1494 20 require 'mocha/setup'
Chris@1494 21
Chris@1494 22 class BazaarAdapterTest < ActiveSupport::TestCase
Chris@1494 23 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
Chris@1494 24 REPOSITORY_PATH.gsub!(/\/+/, '/')
Chris@1494 25
Chris@1494 26 if File.directory?(REPOSITORY_PATH)
Chris@1494 27 def setup
Chris@1494 28 @adapter = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1494 29 File.join(REPOSITORY_PATH, "trunk")
Chris@1494 30 )
Chris@1494 31 end
Chris@1494 32
Chris@1494 33 def test_scm_version
Chris@1494 34 to_test = { "Bazaar (bzr) 2.1.2\n" => [2,1,2],
Chris@1494 35 "2.1.1\n1.7\n1.8" => [2,1,1],
Chris@1494 36 "2.0.1\r\n1.8.1\r\n1.9.1" => [2,0,1]}
Chris@1494 37 to_test.each do |s, v|
Chris@1494 38 test_scm_version_for(s, v)
Chris@1494 39 end
Chris@1494 40 end
Chris@1494 41
Chris@1494 42 def test_cat
Chris@1494 43 cat = @adapter.cat('directory/document.txt')
Chris@1494 44 assert cat =~ /Write the contents of a file as of a given revision to standard output/
Chris@1494 45 end
Chris@1494 46
Chris@1494 47 def test_cat_path_invalid
Chris@1494 48 assert_nil @adapter.cat('invalid')
Chris@1494 49 end
Chris@1494 50
Chris@1494 51 def test_cat_revision_invalid
Chris@1494 52 assert_nil @adapter.cat('doc-mkdir.txt', '12345678')
Chris@1494 53 end
Chris@1494 54
Chris@1494 55 def test_diff
Chris@1494 56 diff1 = @adapter.diff('doc-mkdir.txt', 3, 2)
Chris@1494 57 assert_equal 21, diff1.size
Chris@1494 58 buf = diff1[14].gsub(/\r\n|\r|\n/, "")
Chris@1494 59 assert_equal "-Display more information.", buf
Chris@1494 60 end
Chris@1494 61
Chris@1494 62 def test_diff_path_invalid
Chris@1494 63 assert_equal [], @adapter.diff('invalid', 1)
Chris@1494 64 end
Chris@1494 65
Chris@1494 66 def test_diff_revision_invalid
Chris@1494 67 assert_equal [], @adapter.diff(nil, 12345678)
Chris@1494 68 assert_equal [], @adapter.diff(nil, 12345678, 87654321)
Chris@1494 69 end
Chris@1494 70
Chris@1494 71 def test_annotate
Chris@1494 72 annotate = @adapter.annotate('doc-mkdir.txt')
Chris@1494 73 assert_equal 17, annotate.lines.size
Chris@1494 74 assert_equal '1', annotate.revisions[0].identifier
Chris@1494 75 assert_equal 'jsmith@', annotate.revisions[0].author
Chris@1494 76 assert_equal 'mkdir', annotate.lines[0]
Chris@1494 77 end
Chris@1494 78
Chris@1494 79 def test_annotate_path_invalid
Chris@1494 80 assert_nil @adapter.annotate('invalid')
Chris@1494 81 end
Chris@1494 82
Chris@1494 83 def test_annotate_revision_invalid
Chris@1494 84 assert_nil @adapter.annotate('doc-mkdir.txt', '12345678')
Chris@1494 85 end
Chris@1494 86
Chris@1494 87 def test_branch_conf_path
Chris@1494 88 p = "c:\\test\\test\\"
Chris@1494 89 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1494 90 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1494 91 p = "c:\\test\\test\\.bzr"
Chris@1494 92 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1494 93 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1494 94 p = "c:\\test\\test\\.bzr\\"
Chris@1494 95 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1494 96 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1494 97 p = "c:\\test\\test"
Chris@1494 98 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1494 99 assert_equal File.join("c:\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1494 100 p = "\\\\server\\test\\test\\"
Chris@1494 101 bcp = Redmine::Scm::Adapters::BazaarAdapter.branch_conf_path(p)
Chris@1494 102 assert_equal File.join("\\\\server\\test\\test", ".bzr", "branch", "branch.conf"), bcp
Chris@1494 103 end
Chris@1494 104
Chris@1494 105 def test_append_revisions_only_true
Chris@1494 106 assert_equal true, @adapter.append_revisions_only
Chris@1494 107 end
Chris@1494 108
Chris@1494 109 def test_append_revisions_only_false
Chris@1494 110 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1494 111 File.join(REPOSITORY_PATH, "empty-branch")
Chris@1494 112 )
Chris@1494 113 assert_equal false, adpt.append_revisions_only
Chris@1494 114 end
Chris@1494 115
Chris@1494 116 def test_append_revisions_only_shared_repo
Chris@1494 117 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1494 118 REPOSITORY_PATH
Chris@1494 119 )
Chris@1494 120 assert_equal false, adpt.append_revisions_only
Chris@1494 121 end
Chris@1494 122
Chris@1494 123 def test_info_not_nil
Chris@1494 124 assert_not_nil @adapter.info
Chris@1494 125 end
Chris@1494 126
Chris@1494 127 def test_info_nil
Chris@1494 128 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1494 129 "/invalid/invalid/"
Chris@1494 130 )
Chris@1494 131 assert_nil adpt.info
Chris@1494 132 end
Chris@1494 133
Chris@1494 134 def test_info
Chris@1494 135 info = @adapter.info
Chris@1494 136 assert_equal 4, info.lastrev.identifier.to_i
Chris@1494 137 end
Chris@1494 138
Chris@1494 139 def test_info_emtpy
Chris@1494 140 adpt = Redmine::Scm::Adapters::BazaarAdapter.new(
Chris@1494 141 File.join(REPOSITORY_PATH, "empty-branch")
Chris@1494 142 )
Chris@1494 143 assert_equal 0, adpt.info.lastrev.identifier.to_i
Chris@1494 144 end
Chris@1494 145
Chris@1494 146 def test_entries_path_invalid
Chris@1494 147 assert_equal [], @adapter.entries('invalid')
Chris@1494 148 end
Chris@1494 149
Chris@1494 150 def test_entries_revision_invalid
Chris@1494 151 assert_nil @adapter.entries(nil, 12345678)
Chris@1494 152 end
Chris@1494 153
Chris@1494 154 def test_revisions
Chris@1494 155 revisions = @adapter.revisions(nil, 4, 2)
Chris@1494 156 assert_equal 3, revisions.size
Chris@1494 157 assert_equal 2, revisions[2].identifier
Chris@1494 158 assert_equal 'jsmith@foo.bar-20071203175224-v0eog5d5wrgdrshg', revisions[2].scmid
Chris@1494 159 assert_equal 4, revisions[0].identifier
Chris@1494 160 assert_equal 'jsmith@foo.bar-20071203175422-t40bf8li5zz0c4cg', revisions[0].scmid
Chris@1494 161 assert_equal 2, revisions[0].paths.size
Chris@1494 162 assert_equal 'D', revisions[0].paths[0][:action]
Chris@1494 163 assert_equal '/doc-deleted.txt', revisions[0].paths[0][:path]
Chris@1494 164 assert_equal 'docdeleted.txt-20071203175320-iwwj561ojuubs3gt-1', revisions[0].paths[0][:revision]
Chris@1494 165 assert_equal 'M', revisions[0].paths[1][:action]
Chris@1494 166 assert_equal '/directory/doc-ls.txt', revisions[0].paths[1][:path]
Chris@1494 167 assert_equal 'docls.txt-20071203175005-a3hyc3mn0shl7cgu-1', revisions[0].paths[1][:revision]
Chris@1494 168 end
Chris@1494 169
Chris@1494 170 def test_revisions_path_invalid
Chris@1494 171 assert_nil @adapter.revisions('invalid')
Chris@1494 172 end
Chris@1494 173
Chris@1494 174 def test_revisions_revision_invalid
Chris@1494 175 assert_nil @adapter.revisions(nil, 12345678)
Chris@1494 176 assert_nil @adapter.revisions(nil, 12345678, 87654321)
Chris@1494 177 end
Chris@1494 178
Chris@1494 179 def test_entry
Chris@1494 180 entry = @adapter.entry()
Chris@1494 181 assert_equal "", entry.path
Chris@1494 182 assert_equal "dir", entry.kind
Chris@1494 183 entry = @adapter.entry('')
Chris@1494 184 assert_equal "", entry.path
Chris@1494 185 assert_equal "dir", entry.kind
Chris@1494 186 assert_nil @adapter.entry('invalid')
Chris@1494 187 assert_nil @adapter.entry('/invalid')
Chris@1494 188 assert_nil @adapter.entry('/invalid/')
Chris@1494 189 assert_nil @adapter.entry('invalid/invalid')
Chris@1494 190 assert_nil @adapter.entry('invalid/invalid/')
Chris@1494 191 assert_nil @adapter.entry('/invalid/invalid')
Chris@1494 192 assert_nil @adapter.entry('/invalid/invalid/')
Chris@1494 193 ["doc-ls.txt", "/doc-ls.txt"].each do |path|
Chris@1494 194 entry = @adapter.entry(path, 2)
Chris@1494 195 assert_equal "doc-ls.txt", entry.path
Chris@1494 196 assert_equal "file", entry.kind
Chris@1494 197 end
Chris@1494 198 ["directory", "/directory", "/directory/"].each do |path|
Chris@1494 199 entry = @adapter.entry(path, 2)
Chris@1494 200 assert_equal "directory", entry.path
Chris@1494 201 assert_equal "dir", entry.kind
Chris@1494 202 end
Chris@1494 203 ["directory/document.txt", "/directory/document.txt"].each do |path|
Chris@1494 204 entry = @adapter.entry(path, 2)
Chris@1494 205 assert_equal "directory/document.txt", entry.path
Chris@1494 206 assert_equal "file", entry.kind
Chris@1494 207 end
Chris@1494 208 end
Chris@1494 209
Chris@1494 210 private
Chris@1494 211
Chris@1494 212 def test_scm_version_for(scm_command_version, version)
Chris@1494 213 @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
Chris@1494 214 assert_equal version, @adapter.class.scm_command_version
Chris@1494 215 end
Chris@1494 216 else
Chris@1494 217 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
Chris@1494 218 def test_fake; assert true end
Chris@1494 219 end
Chris@1494 220 end
Chris@1494 221 rescue LoadError
Chris@1494 222 class BazaarMochaFake < ActiveSupport::TestCase
Chris@1494 223 def test_fake; assert(false, "Requires mocha to run those tests") end
Chris@1494 224 end
Chris@1494 225 end