Remove REPOSITORY_PATH constants from repo specs

* Use more idiomatic RSpec `skip` for skipping examples.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/2786/head
Alex Coles 10 years ago
parent 6681aa3bf7
commit 75953e21aa
  1. 350
      test/functional/repositories_git_controller_test.rb
  2. 437
      test/functional/repositories_subversion_controller_test.rb
  3. 4
      test/support/legacy_assertions.rb
  4. 51
      test/unit/lib/redmine/scm/adapters/filesystem_adapter_test.rb
  5. 356
      test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
  6. 482
      test/unit/repository_git_test.rb
  7. 269
      test/unit/repository_subversion_test.rb

@ -38,19 +38,24 @@ describe RepositoriesController, 'Git', type: :controller do
fixtures :all fixtures :all
# No '..' in the repository path # No '..' in the repository path
REPOSITORY_PATH = Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' let(:git_repository_path) {
REPOSITORY_PATH.gsub!(/\//, '\\') if Redmine::Platform.mswin? path = Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
path.gsub!(/\//, '\\') if Redmine::Platform.mswin?
path
}
before do before do
skip 'Git test repository NOT FOUND. Skipping functional tests !!!' unless File.directory?(git_repository_path)
@controller = RepositoriesController.new @controller = RepositoriesController.new
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
User.current = nil User.current = nil
@repository = Repository::Git.create( @repository = Repository::Git.create(
project: Project.find(3), project: Project.find(3),
url: REPOSITORY_PATH, url: git_repository_path,
path_encoding: 'ISO-8859-1' path_encoding: 'ISO-8859-1'
) )
# see repositories_subversion_controller_test.rb # see repositories_subversion_controller_test.rb
def @repository.reload def @repository.reload
@ -61,201 +66,196 @@ describe RepositoriesController, 'Git', type: :controller do
assert @repository assert @repository
end end
if File.directory?(REPOSITORY_PATH) it 'should browse root' do
it 'should browse root' do @repository.fetch_changesets
@repository.fetch_changesets @repository.reload
@repository.reload get :show, project_id: 3
get :show, project_id: 3 assert_response :success
assert_response :success assert_template 'show'
assert_template 'show' assert_not_nil assigns(:entries)
assert_not_nil assigns(:entries) assert_equal 9, assigns(:entries).size
assert_equal 9, assigns(:entries).size assert assigns(:entries).detect { |e| e.name == 'images' && e.kind == 'dir' }
assert assigns(:entries).detect { |e| e.name == 'images' && e.kind == 'dir' } assert assigns(:entries).detect { |e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir' }
assert assigns(:entries).detect { |e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir' } assert assigns(:entries).detect { |e| e.name == 'sources' && e.kind == 'dir' }
assert assigns(:entries).detect { |e| e.name == 'sources' && e.kind == 'dir' } assert assigns(:entries).detect { |e| e.name == 'README' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == 'README' && e.kind == 'file' } assert assigns(:entries).detect { |e| e.name == 'copied_README' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == 'copied_README' && e.kind == 'file' } assert assigns(:entries).detect { |e| e.name == 'new_file.txt' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == 'new_file.txt' && e.kind == 'file' } assert assigns(:entries).detect { |e| e.name == 'renamed_test.txt' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == 'renamed_test.txt' && e.kind == 'file' } assert assigns(:entries).detect { |e| e.name == 'filemane with spaces.txt' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == 'filemane with spaces.txt' && e.kind == 'file' } assert assigns(:entries).detect { |e| e.name == ' filename with a leading space.txt ' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == ' filename with a leading space.txt ' && e.kind == 'file' } assert_not_nil assigns(:changesets)
assert_not_nil assigns(:changesets) assigns(:changesets).size > 0
assigns(:changesets).size > 0 end
end
it 'should browse branch' do
@repository.fetch_changesets
@repository.reload
get :show, project_id: 3, rev: 'test_branch'
assert_response :success
assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal 4, assigns(:entries).size
assert assigns(:entries).detect { |e| e.name == 'images' && e.kind == 'dir' }
assert assigns(:entries).detect { |e| e.name == 'sources' && e.kind == 'dir' }
assert assigns(:entries).detect { |e| e.name == 'README' && e.kind == 'file' }
assert assigns(:entries).detect { |e| e.name == 'test.txt' && e.kind == 'file' }
assert_not_nil assigns(:changesets)
assigns(:changesets).size > 0
end
it 'should browse tag' do it 'should browse branch' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
[ get :show, project_id: 3, rev: 'test_branch'
'tag00.lightweight', assert_response :success
'tag01.annotated', assert_template 'show'
].each do |t1| assert_not_nil assigns(:entries)
get :show, project_id: 3, rev: t1 assert_equal 4, assigns(:entries).size
assert_response :success assert assigns(:entries).detect { |e| e.name == 'images' && e.kind == 'dir' }
assert_template 'show' assert assigns(:entries).detect { |e| e.name == 'sources' && e.kind == 'dir' }
assert_not_nil assigns(:entries) assert assigns(:entries).detect { |e| e.name == 'README' && e.kind == 'file' }
assigns(:entries).size > 0 assert assigns(:entries).detect { |e| e.name == 'test.txt' && e.kind == 'file' }
assert_not_nil assigns(:changesets) assert_not_nil assigns(:changesets)
assigns(:changesets).size > 0 assigns(:changesets).size > 0
end end
end
it 'should browse directory' do it 'should browse tag' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :show, project_id: 3, path: 'images' [
'tag00.lightweight',
'tag01.annotated',
].each do |t1|
get :show, project_id: 3, rev: t1
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) assert_not_nil assigns(:entries)
assert_equal ['edit.png'], assigns(:entries).collect(&:name) assigns(:entries).size > 0
entry = assigns(:entries).detect { |e| e.name == 'edit.png' }
assert_not_nil entry
assert_equal 'file', entry.kind
assert_equal 'images/edit.png', entry.path
assert_not_nil assigns(:changesets) assert_not_nil assigns(:changesets)
assigns(:changesets).size > 0 assigns(:changesets).size > 0
end end
end
it 'should browse at given revision' do it 'should browse directory' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :show, project_id: 3, path: 'images', rev: '7234cb2750b63f47bff735edc50a1c0a433c2518' get :show, project_id: 3, path: 'images'
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) assert_not_nil assigns(:entries)
assert_equal ['delete.png'], assigns(:entries).collect(&:name) assert_equal ['edit.png'], assigns(:entries).collect(&:name)
assert_not_nil assigns(:changesets) entry = assigns(:entries).detect { |e| e.name == 'edit.png' }
assigns(:changesets).size > 0 assert_not_nil entry
end assert_equal 'file', entry.kind
assert_equal 'images/edit.png', entry.path
assert_not_nil assigns(:changesets)
assigns(:changesets).size > 0
end
it 'should changes' do it 'should browse at given revision' do
get :changes, project_id: 3, path: 'images/edit.png' @repository.fetch_changesets
assert_response :success @repository.reload
assert_template 'changes' get :show, project_id: 3, path: 'images', rev: '7234cb2750b63f47bff735edc50a1c0a433c2518'
assert_tag tag: 'h2', content: 'edit.png' assert_response :success
end assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
assert_not_nil assigns(:changesets)
assigns(:changesets).size > 0
end
it 'should entry show' do it 'should changes' do
get :entry, project_id: 3, path: 'sources/watchers_controller.rb' get :changes, project_id: 3, path: 'images/edit.png'
assert_response :success assert_response :success
assert_template 'entry' assert_template 'changes'
# Line 19 assert_tag tag: 'h2', content: 'edit.png'
assert_tag tag: 'th', end
content: /11/,
attributes: { class: /line-num/ },
sibling: { tag: 'td', content: /WITHOUT ANY WARRANTY/ }
end
it 'should entry download' do it 'should entry show' do
get :entry, project_id: 3, path: 'sources/watchers_controller.rb', format: 'raw' get :entry, project_id: 3, path: 'sources/watchers_controller.rb'
assert_response :success assert_response :success
# File content assert_template 'entry'
assert @response.body.include?('WITHOUT ANY WARRANTY') # Line 19
end assert_tag tag: 'th',
content: /11/,
attributes: { class: /line-num/ },
sibling: { tag: 'td', content: /WITHOUT ANY WARRANTY/ }
end
it 'should directory entry' do it 'should entry download' do
get :entry, project_id: 3, path: 'sources' get :entry, project_id: 3, path: 'sources/watchers_controller.rb', format: 'raw'
assert_response :success assert_response :success
assert_template 'show' # File content
assert_not_nil assigns(:entry) assert @response.body.include?('WITHOUT ANY WARRANTY')
assert_equal 'sources', assigns(:entry).name end
end
it 'should diff' do it 'should directory entry' do
@repository.fetch_changesets get :entry, project_id: 3, path: 'sources'
@repository.reload assert_response :success
assert_template 'show'
assert_not_nil assigns(:entry)
assert_equal 'sources', assigns(:entry).name
end
# Full diff of changeset 2f9c0091 it 'should diff' do
get :diff, project_id: 3, rev: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' @repository.fetch_changesets
assert_response :success @repository.reload
assert_template 'diff'
# Line 22 removed # Full diff of changeset 2f9c0091
assert_tag tag: 'th', get :diff, project_id: 3, rev: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
content: /22/, assert_response :success
sibling: { tag: 'td', assert_template 'diff'
attributes: { class: /diff_out/ }, # Line 22 removed
content: /def remove/ } assert_tag tag: 'th',
assert_tag tag: 'h2', content: /2f9c0091/ content: /22/,
end sibling: { tag: 'td',
attributes: { class: /diff_out/ },
content: /def remove/ }
assert_tag tag: 'h2', content: /2f9c0091/
end
it 'should diff two revs' do it 'should diff two revs' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :diff, project_id: 3, rev: '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', get :diff, project_id: 3, rev: '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
rev_to: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' rev_to: '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
assert_response :success assert_response :success
assert_template 'diff' assert_template 'diff'
diff = assigns(:diff) diff = assigns(:diff)
assert_not_nil diff assert_not_nil diff
assert_tag tag: 'h2', content: /2f9c0091:61b685fb/ assert_tag tag: 'h2', content: /2f9c0091:61b685fb/
end end
it 'should annotate' do it 'should annotate' do
get :annotate, project_id: 3, path: 'sources/watchers_controller.rb' get :annotate, project_id: 3, path: 'sources/watchers_controller.rb'
assert_response :success assert_response :success
assert_template 'annotate' assert_template 'annotate'
# Line 23, changeset 2f9c0091 # Line 23, changeset 2f9c0091
assert_tag tag: 'th', content: /24/, assert_tag tag: 'th', content: /24/,
sibling: { tag: 'td', child: { tag: 'a', content: /2f9c0091/ } }, sibling: { tag: 'td', child: { tag: 'a', content: /2f9c0091/ } },
sibling: { tag: 'td', content: /jsmith/ }, sibling: { tag: 'td', content: /jsmith/ },
sibling: { tag: 'td', content: /watcher =/ } sibling: { tag: 'td', content: /watcher =/ }
end end
it 'should annotate at given revision' do it 'should annotate at given revision' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :annotate, project_id: 3, rev: 'deff7', path: 'sources/watchers_controller.rb' get :annotate, project_id: 3, rev: 'deff7', path: 'sources/watchers_controller.rb'
assert_response :success assert_response :success
assert_template 'annotate' assert_template 'annotate'
assert_tag tag: 'h2', content: /@ deff712f/ assert_tag tag: 'h2', content: /@ deff712f/
end end
it 'should annotate binary file' do it 'should annotate binary file' do
get :annotate, project_id: 3, path: 'images/edit.png' get :annotate, project_id: 3, path: 'images/edit.png'
assert_response 500 assert_response 500
assert_tag tag: 'div', attributes: { id: /errorExplanation/ }, assert_tag tag: 'div', attributes: { id: /errorExplanation/ },
content: /cannot be annotated/ content: /cannot be annotated/
end end
it 'should revision' do it 'should revision' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
get :revision, project_id: 3, rev: r get :revision, project_id: 3, rev: r
assert_response :success assert_response :success
assert_template 'revision' assert_template 'revision'
end
end end
end
it 'should empty revision' do it 'should empty revision' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
['', ' ', nil].each do |r| ['', ' ', nil].each do |r|
get :revision, project_id: 3, rev: r get :revision, project_id: 3, rev: r
assert_response 404 assert_response 404
assert_error_tag content: /was not found/ assert_error_tag content: /was not found/
end
end end
else
puts 'Git test repository NOT FOUND. Skipping functional tests !!!'
it 'should fake' do; assert true end
end end
end end

@ -40,6 +40,8 @@ describe RepositoriesController, 'Subversion', type: :controller do
PRJ_ID = 3 PRJ_ID = 3
before do before do
skip 'Subversion test repository NOT FOUND. Skipping functional tests !!!' unless repository_configured?('subversion')
@controller = RepositoriesController.new @controller = RepositoriesController.new
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
@ -61,255 +63,250 @@ describe RepositoriesController, 'Subversion', type: :controller do
assert @repository assert @repository
end end
if repository_configured?('subversion') it 'should show' do
it 'should show' do @repository.fetch_changesets
@repository.fetch_changesets @repository.reload
@repository.reload get :show, project_id: PRJ_ID
get :show, project_id: PRJ_ID assert_response :success
assert_response :success assert_template 'show'
assert_template 'show' assert_not_nil assigns(:entries)
assert_not_nil assigns(:entries) assert_not_nil assigns(:changesets)
assert_not_nil assigns(:changesets) end
end
it 'should browse root' do it 'should browse root' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :show, project_id: PRJ_ID get :show, project_id: PRJ_ID
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) assert_not_nil assigns(:entries)
entry = assigns(:entries).detect { |e| e.name == 'subversion_test' } entry = assigns(:entries).detect { |e| e.name == 'subversion_test' }
assert_equal 'dir', entry.kind assert_equal 'dir', entry.kind
end end
it 'should browse directory' do it 'should browse directory' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :show, project_id: PRJ_ID, path: 'subversion_test' get :show, project_id: PRJ_ID, path: 'subversion_test'
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) assert_not_nil assigns(:entries)
assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name) assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect { |e| e.name == 'helloworld.c' } entry = assigns(:entries).detect { |e| e.name == 'helloworld.c' }
assert_equal 'file', entry.kind assert_equal 'file', entry.kind
assert_equal 'subversion_test/helloworld.c', entry.path assert_equal 'subversion_test/helloworld.c', entry.path
assert_tag :a, content: 'helloworld.c', attributes: { class: /text\-x\-c/ } assert_tag :a, content: 'helloworld.c', attributes: { class: /text\-x\-c/ }
end end
it 'should browse at given revision' do it 'should browse at given revision' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :show, project_id: PRJ_ID, path: 'subversion_test', rev: 4 get :show, project_id: PRJ_ID, path: 'subversion_test', rev: 4
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) assert_not_nil assigns(:entries)
assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
end end
it 'should file changes' do it 'should file changes' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :changes, project_id: PRJ_ID, path: 'subversion_test/folder/helloworld.rb' get :changes, project_id: PRJ_ID, path: 'subversion_test/folder/helloworld.rb'
assert_response :success assert_response :success
assert_template 'changes' assert_template 'changes'
changesets = assigns(:changesets) changesets = assigns(:changesets)
assert_not_nil changesets assert_not_nil changesets
assert_equal %w(6 3 2), changesets.collect(&:revision) assert_equal %w(6 3 2), changesets.collect(&:revision)
# svn properties displayed with svn >= 1.5 only # svn properties displayed with svn >= 1.5 only
if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
assert_not_nil assigns(:properties) assert_not_nil assigns(:properties)
assert_equal 'native', assigns(:properties)['svn:eol-style'] assert_equal 'native', assigns(:properties)['svn:eol-style']
assert_tag :ul, assert_tag :ul,
child: { tag: 'li', child: { tag: 'li',
child: { tag: 'b', content: 'svn:eol-style' }, child: { tag: 'b', content: 'svn:eol-style' },
child: { tag: 'span', content: 'native' } } child: { tag: 'span', content: 'native' } }
end
end end
end
it 'should directory changes' do it 'should directory changes' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :changes, project_id: PRJ_ID, path: 'subversion_test/folder' get :changes, project_id: PRJ_ID, path: 'subversion_test/folder'
assert_response :success assert_response :success
assert_template 'changes' assert_template 'changes'
changesets = assigns(:changesets) changesets = assigns(:changesets)
assert_not_nil changesets assert_not_nil changesets
assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
end end
it 'should entry' do
@repository.fetch_changesets
@repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c'
assert_response :success
assert_template 'entry'
end
it 'should entry' do it 'should entry should send if too big' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
# no files in the test repo is larger than 1KB...
with_settings file_max_size_displayed: 0 do
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c' get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c'
assert_response :success assert_response :success
assert_template 'entry' assert_template nil
assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
end end
end
it 'should entry should send if too big' do it 'should entry at given revision' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
# no files in the test repo is larger than 1KB... get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.rb', rev: 2
with_settings file_max_size_displayed: 0 do assert_response :success
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c' assert_template 'entry'
assert_response :success # this line was removed in r3 and file was moved in r6
assert_template nil assert_tag tag: 'td', attributes: { class: /line-code/ },
assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] content: /Here's the code/
end end
end
it 'should entry at given revision' do it 'should entry not found' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.rb', rev: 2 get :entry, project_id: PRJ_ID, path: 'subversion_test/zzz.c'
assert_response :success assert_tag tag: 'div', attributes: { id: /errorExplanation/ },
assert_template 'entry' content: /The entry or revision was not found in the repository/
# this line was removed in r3 and file was moved in r6 end
assert_tag tag: 'td', attributes: { class: /line-code/ },
content: /Here's the code/
end
it 'should entry not found' do it 'should entry download' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/zzz.c' get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c', format: 'raw'
assert_tag tag: 'div', attributes: { id: /errorExplanation/ }, assert_response :success
content: /The entry or revision was not found in the repository/ assert_template nil
end assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
end
it 'should entry download' do it 'should directory entry' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :entry, project_id: PRJ_ID, path: 'subversion_test/helloworld.c', format: 'raw' get :entry, project_id: PRJ_ID, path: 'subversion_test/folder'
assert_response :success assert_response :success
assert_template nil assert_template 'show'
assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] assert_not_nil assigns(:entry)
end assert_equal 'folder', assigns(:entry).name
end
it 'should directory entry' do # TODO: this test needs fixtures.
@repository.fetch_changesets it 'should revision' do
@repository.reload @repository.fetch_changesets
get :entry, project_id: PRJ_ID, path: 'subversion_test/folder' @repository.reload
assert_response :success get :revision, project_id: 1, rev: 2
assert_template 'show' assert_response :success
assert_not_nil assigns(:entry) assert_template 'revision'
assert_equal 'folder', assigns(:entry).name assert_tag tag: 'ul',
end child: { tag: 'li',
# link to the entry at rev 2
child: { tag: 'a',
attributes: { href: '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo' },
content: 'repo',
# link to partial diff
sibling: { tag: 'a',
attributes: { href: '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
}
}
}
end
# TODO: this test needs fixtures. it 'should invalid revision' do
it 'should revision' do @repository.fetch_changesets
@repository.fetch_changesets @repository.reload
@repository.reload get :revision, project_id: PRJ_ID, rev: 'something_weird'
get :revision, project_id: 1, rev: 2 assert_response 404
assert_response :success assert_error_tag content: /was not found/
assert_template 'revision' end
assert_tag tag: 'ul',
child: { tag: 'li',
# link to the entry at rev 2
child: { tag: 'a',
attributes: { href: '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo' },
content: 'repo',
# link to partial diff
sibling: { tag: 'a',
attributes: { href: '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
}
}
}
end
it 'should invalid revision' do it 'should invalid revision diff' do
@repository.fetch_changesets get :diff, project_id: PRJ_ID, rev: '1', rev_to: 'something_weird'
@repository.reload assert_response 404
get :revision, project_id: PRJ_ID, rev: 'something_weird' assert_error_tag content: /was not found/
assert_response 404 end
assert_error_tag content: /was not found/
end
it 'should invalid revision diff' do it 'should empty revision' do
get :diff, project_id: PRJ_ID, rev: '1', rev_to: 'something_weird' @repository.fetch_changesets
@repository.reload
['', ' ', nil].each do |r|
get :revision, project_id: PRJ_ID, rev: r
assert_response 404 assert_response 404
assert_error_tag content: /was not found/ assert_error_tag content: /was not found/
end end
end
it 'should empty revision' do # TODO: this test needs fixtures.
@repository.fetch_changesets it 'should revision with repository pointing to a subdirectory' do
@repository.reload r = Project.find(1).repository
['', ' ', nil].each do |r| # Changes repository url to a subdirectory
get :revision, project_id: PRJ_ID, rev: r r.update_attribute :url, (r.url + '/test/some')
assert_response 404
assert_error_tag content: /was not found/ get :revision, project_id: 1, rev: 2
end assert_response :success
end assert_template 'revision'
assert_tag tag: 'ul',
# TODO: this test needs fixtures. child: { tag: 'li',
it 'should revision with repository pointing to a subdirectory' do # link to the entry at rev 2
r = Project.find(1).repository child: { tag: 'a',
# Changes repository url to a subdirectory attributes: { href: '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo' },
r.update_attribute :url, (r.url + '/test/some') content: 'repo',
# link to partial diff
get :revision, project_id: 1, rev: 2 sibling: { tag: 'a',
assert_response :success attributes: { href: '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
assert_template 'revision' }
assert_tag tag: 'ul', }
child: { tag: 'li', }
# link to the entry at rev 2 end
child: { tag: 'a',
attributes: { href: '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo' },
content: 'repo',
# link to partial diff
sibling: { tag: 'a',
attributes: { href: '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
}
}
}
end
it 'should revision diff' do it 'should revision diff' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :diff, project_id: PRJ_ID, rev: 3 get :diff, project_id: PRJ_ID, rev: 3
assert_response :success assert_response :success
assert_template 'diff' assert_template 'diff'
assert_tag tag: 'h2', content: /3/ assert_tag tag: 'h2', content: /3/
end end
it 'should directory diff' do it 'should directory diff' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :diff, project_id: PRJ_ID, rev: 6, rev_to: 2, path: 'subversion_test/folder' get :diff, project_id: PRJ_ID, rev: 6, rev_to: 2, path: 'subversion_test/folder'
assert_response :success assert_response :success
assert_template 'diff' assert_template 'diff'
diff = assigns(:diff) diff = assigns(:diff)
assert_not_nil diff assert_not_nil diff
# 2 files modified # 2 files modified
assert_equal 2, Redmine::UnifiedDiff.new(diff).size assert_equal 2, Redmine::UnifiedDiff.new(diff).size
assert_tag tag: 'h2', content: /2:6/ assert_tag tag: 'h2', content: /2:6/
end end
it 'should annotate' do it 'should annotate' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :annotate, project_id: PRJ_ID, path: 'subversion_test/helloworld.c' get :annotate, project_id: PRJ_ID, path: 'subversion_test/helloworld.c'
assert_response :success assert_response :success
assert_template 'annotate' assert_template 'annotate'
end end
it 'should annotate at given revision' do it 'should annotate at given revision' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
get :annotate, project_id: PRJ_ID, rev: 8, path: 'subversion_test/helloworld.c' get :annotate, project_id: PRJ_ID, rev: 8, path: 'subversion_test/helloworld.c'
assert_response :success assert_response :success
assert_template 'annotate' assert_template 'annotate'
assert_tag tag: 'h2', content: /@ 8/ assert_tag tag: 'h2', content: /@ 8/
end
else
puts 'Subversion test repository NOT FOUND. Skipping functional tests !!!'
it 'should fake' do; assert true end
end end
end end

@ -234,6 +234,10 @@ module LegacyAssertionsAndHelpers
{ 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(login, password) } { 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(login, password) }
end end
def repository_configured?(vendor)
self.class.repository_configured?(vendor)
end
module ClassMethods module ClassMethods
def ldap_configured? def ldap_configured?
@test_ldap = Net::LDAP.new(host: '127.0.0.1', port: 389) @test_ldap = Net::LDAP.new(host: '127.0.0.1', port: 389)

@ -30,36 +30,33 @@
require File.expand_path('../../../../../../test_helper', __FILE__) require File.expand_path('../../../../../../test_helper', __FILE__)
describe Redmine::Scm::Adapters::FilesystemAdapter, type: :model do describe Redmine::Scm::Adapters::FilesystemAdapter, type: :model do
REPOSITORY_PATH = Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository' let(:fs_repository_path) { Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository' }
if File.directory?(REPOSITORY_PATH) before do
before do skip 'Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS.' unless File.directory?(fs_repository_path)
@adapter = Redmine::Scm::Adapters::FilesystemAdapter.new(REPOSITORY_PATH)
end
it 'should entries' do @adapter = Redmine::Scm::Adapters::FilesystemAdapter.new(fs_repository_path)
assert_equal 3, @adapter.entries.size end
assert_equal ['dir', 'japanese', 'test'], @adapter.entries.collect(&:name)
assert_equal ['dir', 'japanese', 'test'], @adapter.entries(nil).collect(&:name)
assert_equal ['dir', 'japanese', 'test'], @adapter.entries('/').collect(&:name)
['dir', '/dir', '/dir/', 'dir/'].each do |path|
assert_equal ['subdir', 'dirfile'], @adapter.entries(path).collect(&:name)
end
# If y try to use "..", the path is ignored
['/../', 'dir/../', '..', '../', '/..', 'dir/..'].each do |path|
assert_equal ['dir', 'japanese', 'test'], @adapter.entries(path).collect(&:name),
'.. must be ignored in path argument'
end
end
it 'should cat' do it 'should entries' do
assert_equal "TEST CAT\n", @adapter.cat('test') assert_equal 3, @adapter.entries.size
assert_equal "TEST CAT\n", @adapter.cat('/test') assert_equal ['dir', 'japanese', 'test'], @adapter.entries.collect(&:name)
# Revision number is ignored assert_equal ['dir', 'japanese', 'test'], @adapter.entries(nil).collect(&:name)
assert_equal "TEST CAT\n", @adapter.cat('/test', 1) assert_equal ['dir', 'japanese', 'test'], @adapter.entries('/').collect(&:name)
['dir', '/dir', '/dir/', 'dir/'].each do |path|
assert_equal ['subdir', 'dirfile'], @adapter.entries(path).collect(&:name)
end end
else # If y try to use "..", the path is ignored
puts 'Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS.' ['/../', 'dir/../', '..', '../', '/..', 'dir/..'].each do |path|
it 'should fake' do; assert true end assert_equal ['dir', 'japanese', 'test'], @adapter.entries(path).collect(&:name),
'.. must be ignored in path argument'
end
end
it 'should cat' do
assert_equal "TEST CAT\n", @adapter.cat('test')
assert_equal "TEST CAT\n", @adapter.cat('/test')
# Revision number is ignored
assert_equal "TEST CAT\n", @adapter.cat('/test', 1)
end end
end end

@ -33,7 +33,7 @@
require File.expand_path('../../../../../../test_helper', __FILE__) require File.expand_path('../../../../../../test_helper', __FILE__)
describe Redmine::Scm::Adapters::GitAdapter, type: :model do describe Redmine::Scm::Adapters::GitAdapter, type: :model do
REPOSITORY_PATH = Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' let(:git_repository_path) { Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' }
FELIX_UTF8 = 'Felix Schäfer' FELIX_UTF8 = 'Felix Schäfer'
FELIX_HEX = "Felix Sch\xC3\xA4fer" FELIX_HEX = "Felix Sch\xC3\xA4fer"
@ -45,214 +45,210 @@ describe Redmine::Scm::Adapters::GitAdapter, type: :model do
# WINDOWS_PASS = Redmine::Platform.mswin? # WINDOWS_PASS = Redmine::Platform.mswin?
WINDOWS_PASS = false WINDOWS_PASS = false
if File.directory?(REPOSITORY_PATH) before do
before do skip 'Git test repository NOT FOUND. Skipping unit tests !!!' unless File.directory?(git_repository_path)
@adapter = Redmine::Scm::Adapters::GitAdapter.new(
REPOSITORY_PATH, @adapter = Redmine::Scm::Adapters::GitAdapter.new(
nil, git_repository_path,
nil, nil,
nil, nil,
'ISO-8859-1' nil,
) 'ISO-8859-1'
assert @adapter )
@char_1 = CHAR_1_HEX.dup assert @adapter
if @char_1.respond_to?(:force_encoding) @char_1 = CHAR_1_HEX.dup
@char_1.force_encoding('UTF-8') if @char_1.respond_to?(:force_encoding)
end @char_1.force_encoding('UTF-8')
end
it 'should scm version' do
to_test = { "git version 1.7.3.4\n" => [1, 7, 3, 4],
"1.6.1\n1.7\n1.8" => [1, 6, 1],
"1.6.2\r\n1.8.1\r\n1.9.1" => [1, 6, 2] }
to_test.each do |s, v|
test_scm_version_for(s, v)
end
end end
end
it 'should branches' do it 'should scm version' do
assert_equal [ to_test = { "git version 1.7.3.4\n" => [1, 7, 3, 4],
'latin-1-path-encoding', "1.6.1\n1.7\n1.8" => [1, 6, 1],
'master', "1.6.2\r\n1.8.1\r\n1.9.1" => [1, 6, 2] }
'test-latin-1', to_test.each do |s, v|
'test_branch', test_scm_version_for(s, v)
], @adapter.branches
end end
end
it 'should tags' do it 'should branches' do
assert_equal [ assert_equal [
'tag00.lightweight', 'latin-1-path-encoding',
'tag01.annotated', 'master',
], @adapter.tags 'test-latin-1',
end 'test_branch',
], @adapter.branches
end
it 'should getting all revisions' do it 'should tags' do
assert_equal 21, @adapter.revisions('', nil, nil, all: true).length assert_equal [
end 'tag00.lightweight',
'tag01.annotated',
], @adapter.tags
end
it 'should getting certain revisions' do it 'should getting all revisions' do
assert_equal 1, @adapter.revisions('', '899a15d^', '899a15d').length assert_equal 21, @adapter.revisions('', nil, nil, all: true).length
end end
it 'should revisions reverse' do it 'should getting certain revisions' do
revs1 = @adapter.revisions('', nil, nil, all: true, reverse: true) assert_equal 1, @adapter.revisions('', '899a15d^', '899a15d').length
assert_equal 21, revs1.length end
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[20].identifier
since2 = Time.gm(2010, 9, 30, 0, 0, 0) it 'should revisions reverse' do
revs2 = @adapter.revisions('', nil, nil, all: true, since: since2, reverse: true) revs1 = @adapter.revisions('', nil, nil, all: true, reverse: true)
assert_equal 6, revs2.length assert_equal 21, revs1.length
assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[20].identifier
end
since2 = Time.gm(2010, 9, 30, 0, 0, 0)
revs2 = @adapter.revisions('', nil, nil, all: true, since: since2, reverse: true)
assert_equal 6, revs2.length
assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', revs2[0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[5].identifier
end
it 'should getting revisions with spaces in filename' do it 'should getting revisions with spaces in filename' do
assert_equal 1, @adapter.revisions('filemane with spaces.txt', assert_equal 1, @adapter.revisions('filemane with spaces.txt',
nil, nil, all: true).length nil, nil, all: true).length
end end
it 'should getting revisions with leading and trailing spaces in filename' do it 'should getting revisions with leading and trailing spaces in filename' do
assert_equal ' filename with a leading space.txt ', assert_equal ' filename with a leading space.txt ',
@adapter.revisions(' filename with a leading space.txt ', @adapter.revisions(' filename with a leading space.txt ',
nil, nil, all: true)[0].paths[0][:path] nil, nil, all: true)[0].paths[0][:path]
end end
it 'should getting entries with leading and trailing spaces in filename' do it 'should getting entries with leading and trailing spaces in filename' do
assert_equal ' filename with a leading space.txt ', assert_equal ' filename with a leading space.txt ',
@adapter.entries('', @adapter.entries('',
'83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
end end
it 'should annotate' do it 'should annotate' do
annotate = @adapter.annotate('sources/watchers_controller.rb') annotate = @adapter.annotate('sources/watchers_controller.rb')
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
assert_equal 41, annotate.lines.size assert_equal 41, annotate.lines.size
assert_equal '# This program is free software; you can redistribute it and/or', assert_equal '# This program is free software; you can redistribute it and/or',
annotate.lines[4].strip annotate.lines[4].strip
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
annotate.revisions[4].identifier annotate.revisions[4].identifier
assert_equal 'jsmith', annotate.revisions[4].author assert_equal 'jsmith', annotate.revisions[4].author
end end
it 'should annotate moved file' do it 'should annotate moved file' do
annotate = @adapter.annotate('renamed_test.txt') annotate = @adapter.annotate('renamed_test.txt')
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
assert_equal 2, annotate.lines.size assert_equal 2, annotate.lines.size
end end
it 'should last rev' do it 'should last rev' do
last_rev = @adapter.lastrev('README', last_rev = @adapter.lastrev('README',
'4f26664364207fa8b1af9f8722647ab2d4ac5d43') '4f26664364207fa8b1af9f8722647ab2d4ac5d43')
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', last_rev.scmid assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', last_rev.scmid
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', last_rev.identifier assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', last_rev.identifier
assert_equal 'Adam Soltys <asoltys@gmail.com>', last_rev.author assert_equal 'Adam Soltys <asoltys@gmail.com>', last_rev.author
assert_equal '2009-06-24 05:27:38'.to_time, last_rev.time assert_equal '2009-06-24 05:27:38'.to_time, last_rev.time
end end
it 'should last rev with spaces in filename' do it 'should last rev with spaces in filename' do
last_rev = @adapter.lastrev('filemane with spaces.txt', last_rev = @adapter.lastrev('filemane with spaces.txt',
'ed5bb786bbda2dee66a2d50faf51429dbc043a7b') 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
str_felix_utf8 = FELIX_UTF8.dup str_felix_utf8 = FELIX_UTF8.dup
str_felix_hex = FELIX_HEX.dup str_felix_hex = FELIX_HEX.dup
last_rev_author = last_rev.author last_rev_author = last_rev.author
if last_rev_author.respond_to?(:force_encoding) if last_rev_author.respond_to?(:force_encoding)
last_rev_author.force_encoding('UTF-8') last_rev_author.force_encoding('UTF-8')
end end
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', last_rev.scmid assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', last_rev.scmid
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', last_rev.identifier assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', last_rev.identifier
assert_equal "#{str_felix_utf8} <felix@fachschaften.org>", assert_equal "#{str_felix_utf8} <felix@fachschaften.org>",
last_rev.author last_rev.author
assert_equal "#{str_felix_hex} <felix@fachschaften.org>", assert_equal "#{str_felix_hex} <felix@fachschaften.org>",
last_rev.author last_rev.author
assert_equal '2010-09-18 19:59:46'.to_time, last_rev.time assert_equal '2010-09-18 19:59:46'.to_time, last_rev.time
end end
# TODO: need to handle edge cases of non-binary content that isn't UTF-8 # TODO: need to handle edge cases of non-binary content that isn't UTF-8
xit 'test_latin_1_path' do xit 'test_latin_1_path' do
if WINDOWS_PASS if WINDOWS_PASS
# #
else else
p2 = "latin-1-dir/test-#{@char_1}-2.txt" p2 = "latin-1-dir/test-#{@char_1}-2.txt"
['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1| ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
assert @adapter.diff(p2, r1) assert @adapter.diff(p2, r1)
assert @adapter.cat(p2, r1) assert @adapter.cat(p2, r1)
annotation = @adapter.annotate(p2, r1) annotation = @adapter.annotate(p2, r1)
assert annotation.present?, 'No annotation returned' assert annotation.present?, 'No annotation returned'
assert_equal 1, annotation.lines.length assert_equal 1, annotation.lines.length
['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2| ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
assert @adapter.diff(p2, r1, r2) assert @adapter.diff(p2, r1, r2)
end
end end
end end
end end
end
it 'should entries tag' do it 'should entries tag' do
entries1 = @adapter.entries(nil, 'tag01.annotated') entries1 = @adapter.entries(nil, 'tag01.annotated')
assert entries1 assert entries1
assert_equal 3, entries1.size assert_equal 3, entries1.size
assert_equal 'sources', entries1[1].name assert_equal 'sources', entries1[1].name
assert_equal 'sources', entries1[1].path assert_equal 'sources', entries1[1].path
assert_equal 'dir', entries1[1].kind assert_equal 'dir', entries1[1].kind
readme = entries1[2] readme = entries1[2]
assert_equal 'README', readme.name assert_equal 'README', readme.name
assert_equal 'README', readme.path assert_equal 'README', readme.path
assert_equal 'file', readme.kind assert_equal 'file', readme.kind
assert_equal 27, readme.size assert_equal 27, readme.size
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
end end
it 'should entries branch' do it 'should entries branch' do
entries1 = @adapter.entries(nil, 'test_branch') entries1 = @adapter.entries(nil, 'test_branch')
assert entries1 assert entries1
assert_equal 4, entries1.size assert_equal 4, entries1.size
assert_equal 'sources', entries1[1].name assert_equal 'sources', entries1[1].name
assert_equal 'sources', entries1[1].path assert_equal 'sources', entries1[1].path
assert_equal 'dir', entries1[1].kind assert_equal 'dir', entries1[1].kind
readme = entries1[2] readme = entries1[2]
assert_equal 'README', readme.name assert_equal 'README', readme.name
assert_equal 'README', readme.path assert_equal 'README', readme.path
assert_equal 'file', readme.kind assert_equal 'file', readme.kind
assert_equal 159, readme.size assert_equal 159, readme.size
assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
end end
it 'should entries latin 1 files' do it 'should entries latin 1 files' do
entries1 = @adapter.entries('latin-1-dir', '64f1f3e8') entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
assert entries1
assert_equal 3, entries1.size
f1 = entries1[1]
assert_equal "test-#{@char_1}-2.txt", f1.name
assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
assert_equal 'file', f1.kind
end
it 'should entries latin 1 dir' do
if WINDOWS_PASS
#
else
entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
'1ca7f5ed')
assert entries1 assert entries1
assert_equal 3, entries1.size assert_equal 3, entries1.size
f1 = entries1[1] f1 = entries1[1]
assert_equal "test-#{@char_1}-2.txt", f1.name assert_equal "test-#{@char_1}-2.txt", f1.name
assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
assert_equal 'file', f1.kind assert_equal 'file', f1.kind
end end
end
it 'should entries latin 1 dir' do private
if WINDOWS_PASS
#
else
entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
'1ca7f5ed')
assert entries1
assert_equal 3, entries1.size
f1 = entries1[1]
assert_equal "test-#{@char_1}-2.txt", f1.name
assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
assert_equal 'file', f1.kind
end
end
private
def test_scm_version_for(scm_command_version, version)
@adapter.class.should_receive(:scm_version_from_command_line).and_return(scm_command_version)
assert_equal version, @adapter.class.scm_command_version
end
else def test_scm_version_for(scm_command_version, version)
puts 'Git test repository NOT FOUND. Skipping unit tests !!!' @adapter.class.should_receive(:scm_version_from_command_line).and_return(scm_command_version)
it 'should fake' do; assert true end assert_equal version, @adapter.class.scm_command_version
end end
end end

@ -32,8 +32,11 @@ describe Repository::Git, type: :model do
fixtures :all fixtures :all
# No '..' in the repository path # No '..' in the repository path
REPOSITORY_PATH = Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' let(:git_repository_path) {
REPOSITORY_PATH.gsub!(/\//, '\\') if Redmine::Platform.mswin? path = Rails.root.to_s.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
path.gsub!(/\//, '\\') if Redmine::Platform.mswin?
path
}
FELIX_HEX = "Felix Sch\xC3\xA4fer" FELIX_HEX = "Felix Sch\xC3\xA4fer"
CHAR_1_HEX = "\xc3\x9c" CHAR_1_HEX = "\xc3\x9c"
@ -45,12 +48,14 @@ describe Repository::Git, type: :model do
WINDOWS_PASS = false WINDOWS_PASS = false
before do before do
skip 'Git test repository NOT FOUND. Skipping unit tests !!!' unless File.directory?(git_repository_path)
@project = Project.find(3) @project = Project.find(3)
@repository = Repository::Git.create( @repository = Repository::Git.create(
project: @project, project: @project,
url: REPOSITORY_PATH, url: git_repository_path,
path_encoding: 'ISO-8859-1' path_encoding: 'ISO-8859-1'
) )
assert @repository assert @repository
@char_1 = CHAR_1_HEX.dup @char_1 = CHAR_1_HEX.dup
if @char_1.respond_to?(:force_encoding) if @char_1.respond_to?(:force_encoding)
@ -58,272 +63,267 @@ describe Repository::Git, type: :model do
end end
end end
if File.directory?(REPOSITORY_PATH) it 'should fetch changesets from scratch' do
it 'should fetch changesets from scratch' do @repository.fetch_changesets
@repository.fetch_changesets @repository.reload
@repository.reload
assert_equal 21, @repository.changesets.count
assert_equal 21, @repository.changesets.count assert_equal 33, @repository.changes.count
assert_equal 33, @repository.changes.count
commit = @repository.changesets.reorder('committed_on ASC').first
commit = @repository.changesets.reorder('committed_on ASC').first assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments assert_equal 'jsmith <jsmith@foo.bar>', commit.committer
assert_equal 'jsmith <jsmith@foo.bar>', commit.committer assert_equal User.find_by_login('jsmith'), commit.user
assert_equal User.find_by_login('jsmith'), commit.user # TODO: add a commit with commit time <> author time to the test repository
# TODO: add a commit with commit time <> author time to the test repository assert_equal '2007-12-14 09:22:52'.to_time, commit.committed_on
assert_equal '2007-12-14 09:22:52'.to_time, commit.committed_on assert_equal '2007-12-14'.to_date, commit.commit_date
assert_equal '2007-12-14'.to_date, commit.commit_date assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', commit.revision
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', commit.revision assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', commit.scmid
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', commit.scmid assert_equal 3, commit.changes.count
assert_equal 3, commit.changes.count change = commit.changes.sort_by(&:path).first
change = commit.changes.sort_by(&:path).first assert_equal 'README', change.path
assert_equal 'README', change.path assert_equal 'A', change.action
assert_equal 'A', change.action end
end
it 'should fetch changesets incremental' do it 'should fetch changesets incremental' do
@repository.fetch_changesets @repository.fetch_changesets
# Remove the 3 latest changesets # Remove the 3 latest changesets
@repository.changesets.find(:all, order: 'committed_on DESC', limit: 8).each(&:destroy) @repository.changesets.find(:all, order: 'committed_on DESC', limit: 8).each(&:destroy)
@repository.reload @repository.reload
cs1 = @repository.changesets cs1 = @repository.changesets
assert_equal 13, cs1.count assert_equal 13, cs1.count
rev_a_commit = @repository.changesets.find(:first, order: 'committed_on DESC') rev_a_commit = @repository.changesets.find(:first, order: 'committed_on DESC')
assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
# Mon Jul 5 22:34:26 2010 +0200 # Mon Jul 5 22:34:26 2010 +0200
rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
assert_equal rev_a_committed_on, rev_a_commit.committed_on assert_equal rev_a_committed_on, rev_a_commit.committed_on
latest_rev = @repository.latest_changeset latest_rev = @repository.latest_changeset
assert_equal rev_a_committed_on, latest_rev.committed_on assert_equal rev_a_committed_on, latest_rev.committed_on
@repository.fetch_changesets
assert_equal 21, @repository.changesets.count
end
@repository.fetch_changesets it 'should latest changesets' do
assert_equal 21, @repository.changesets.count @repository.fetch_changesets
end @repository.reload
# with limit
changesets = @repository.latest_changesets('', nil, 2)
assert_equal 2, changesets.size
# with path
changesets = @repository.latest_changesets('images', nil)
assert_equal [
'deff712f05a90d96edbd70facc47d944be5897e3',
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', nil)
assert_equal [
'32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
'4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
'713f4944648826f558cf548222f813dabe7cbb04',
'61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
# with path, revision and limit
changesets = @repository.latest_changesets('images', '899a15dba')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('images', '899a15dba', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', '899a15dba')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', '899a15dba', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
# with path, tag and limit
changesets = @repository.latest_changesets('images', 'tag01.annotated')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'tag01.annotated')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
# with path, branch and limit
changesets = @repository.latest_changesets('images', 'test_branch')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('images', 'test_branch', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'test_branch')
assert_equal [
'713f4944648826f558cf548222f813dabe7cbb04',
'61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'test_branch', 2)
assert_equal [
'713f4944648826f558cf548222f813dabe7cbb04',
'61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
], changesets.collect(&:revision)
# latin-1 encoding path
changesets = @repository.latest_changesets(
"latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
assert_equal [
'64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
'4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets(
"latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
assert_equal [
'64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
], changesets.collect(&:revision)
end
it 'should latest changesets' do it 'should latest changesets latin 1 dir' do
if WINDOWS_PASS
#
else
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
# with limit
changesets = @repository.latest_changesets('', nil, 2)
assert_equal 2, changesets.size
# with path
changesets = @repository.latest_changesets('images', nil)
assert_equal [
'deff712f05a90d96edbd70facc47d944be5897e3',
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', nil)
assert_equal [
'32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
'4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
'713f4944648826f558cf548222f813dabe7cbb04',
'61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
# with path, revision and limit
changesets = @repository.latest_changesets('images', '899a15dba')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('images', '899a15dba', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', '899a15dba')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', '899a15dba', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
# with path, tag and limit
changesets = @repository.latest_changesets('images', 'tag01.annotated')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'tag01.annotated')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
# with path, branch and limit
changesets = @repository.latest_changesets('images', 'test_branch')
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('images', 'test_branch', 1)
assert_equal [
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'test_branch')
assert_equal [
'713f4944648826f558cf548222f813dabe7cbb04',
'61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
'899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
'7234cb2750b63f47bff735edc50a1c0a433c2518',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets('README', 'test_branch', 2)
assert_equal [
'713f4944648826f558cf548222f813dabe7cbb04',
'61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
], changesets.collect(&:revision)
# latin-1 encoding path
changesets = @repository.latest_changesets(
"latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
assert_equal [
'64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
'4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
], changesets.collect(&:revision)
changesets = @repository.latest_changesets( changesets = @repository.latest_changesets(
"latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1) "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
assert_equal [ assert_equal [
'64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
], changesets.collect(&:revision) ], changesets.collect(&:revision)
end end
end
it 'should latest changesets latin 1 dir' do it 'should find changeset by name' do
if WINDOWS_PASS @repository.fetch_changesets
# @repository.reload
else ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
@repository.fetch_changesets assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
@repository.reload @repository.find_changeset_by_name(r).revision
changesets = @repository.latest_changesets(
"latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
assert_equal [
'1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
], changesets.collect(&:revision)
end
end
it 'should find changeset by name' do
@repository.fetch_changesets
@repository.reload
['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
@repository.find_changeset_by_name(r).revision
end
end end
end
it 'should find changeset by empty name' do it 'should find changeset by empty name' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
['', ' ', nil].each do |r| ['', ' ', nil].each do |r|
assert_nil @repository.find_changeset_by_name(r) assert_nil @repository.find_changeset_by_name(r)
end
end end
end
it 'should identifier' do it 'should identifier' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
assert_equal c.scmid, c.identifier assert_equal c.scmid, c.identifier
end end
it 'should format identifier' do it 'should format identifier' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
assert_equal '7234cb27', c.format_identifier assert_equal '7234cb27', c.format_identifier
end end
it 'should activities' do it 'should activities' do
c = Changeset.create(repository: @repository, c = Changeset.create(repository: @repository,
committed_on: Time.now, committed_on: Time.now,
revision: 'abc7234cb2750b63f47bff735edc50a1c0a433c2', revision: 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
scmid: 'abc7234cb2750b63f47bff735edc50a1c0a433c2', scmid: 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
comments: 'test') comments: 'test')
event = find_events(User.find(2)).first # manager event = find_events(User.find(2)).first # manager
assert event.event_title.include?('abc7234c:') assert event.event_title.include?('abc7234c:')
assert event.event_path =~ /\?rev=abc7234cb2750b63f47bff735edc50a1c0a433c2$/ assert event.event_path =~ /\?rev=abc7234cb2750b63f47bff735edc50a1c0a433c2$/
end end
it 'should log utf8' do it 'should log utf8' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
str_felix_hex = FELIX_HEX.dup str_felix_hex = FELIX_HEX.dup
if str_felix_hex.respond_to?(:force_encoding) if str_felix_hex.respond_to?(:force_encoding)
str_felix_hex.force_encoding('UTF-8') str_felix_hex.force_encoding('UTF-8')
end
c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
end end
c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
end
it 'should previous' do it 'should previous' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
%w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
changeset = @repository.find_changeset_by_name(r1) changeset = @repository.find_changeset_by_name(r1)
%w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
assert_equal @repository.find_changeset_by_name(r2), changeset.previous assert_equal @repository.find_changeset_by_name(r2), changeset.previous
end
end end
end end
end
it 'should previous nil' do it 'should previous nil' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
%w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1| %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1|
changeset = @repository.find_changeset_by_name(r1) changeset = @repository.find_changeset_by_name(r1)
assert_nil changeset.previous assert_nil changeset.previous
end
end end
end
it 'should next' do it 'should next' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
%w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
changeset = @repository.find_changeset_by_name(r2) changeset = @repository.find_changeset_by_name(r2)
%w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
assert_equal @repository.find_changeset_by_name(r1), changeset.next assert_equal @repository.find_changeset_by_name(r1), changeset.next
end
end end
end end
end
it 'should next nil' do it 'should next nil' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
%w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
changeset = @repository.find_changeset_by_name(r1) changeset = @repository.find_changeset_by_name(r1)
assert_nil changeset.next assert_nil changeset.next
end
end end
else
puts 'Git test repository NOT FOUND. Skipping unit tests !!!'
it 'should fake' do; assert true end
end end
private private

@ -32,176 +32,173 @@ describe Repository::Subversion, type: :model do
fixtures :all fixtures :all
before do before do
skip 'Subversion test repository NOT FOUND. Skipping unit tests !!!' unless repository_configured?('subversion')
@project = Project.find(3) @project = Project.find(3)
@repository = Repository::Subversion.create(project: @project, @repository = Repository::Subversion.create(project: @project,
url: self.class.subversion_repository_url) url: self.class.subversion_repository_url)
assert @repository assert @repository
end end
if repository_configured?('subversion') it 'should fetch changesets from scratch' do
it 'should fetch changesets from scratch' do @repository.fetch_changesets
@repository.fetch_changesets @repository.reload
@repository.reload
assert_equal 11, @repository.changesets.count assert_equal 11, @repository.changesets.count
assert_equal 20, @repository.changes.count assert_equal 20, @repository.changes.count
assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
end end
it 'should fetch changesets incremental' do it 'should fetch changesets incremental' do
@repository.fetch_changesets @repository.fetch_changesets
# Remove changesets with revision > 5 # Remove changesets with revision > 5
@repository.changesets.find(:all).each { |c| c.destroy if c.revision.to_i > 5 } @repository.changesets.find(:all).each { |c| c.destroy if c.revision.to_i > 5 }
@repository.reload @repository.reload
assert_equal 5, @repository.changesets.count assert_equal 5, @repository.changesets.count
@repository.fetch_changesets @repository.fetch_changesets
assert_equal 11, @repository.changesets.count assert_equal 11, @repository.changesets.count
end end
it 'should latest changesets' do it 'should latest changesets' do
@repository.fetch_changesets @repository.fetch_changesets
# with limit # with limit
changesets = @repository.latest_changesets('', nil, 2) changesets = @repository.latest_changesets('', nil, 2)
assert_equal 2, changesets.size assert_equal 2, changesets.size
assert_equal @repository.latest_changesets('', nil).slice(0, 2), changesets assert_equal @repository.latest_changesets('', nil).slice(0, 2), changesets
# with path # with path
changesets = @repository.latest_changesets('subversion_test/folder', nil) changesets = @repository.latest_changesets('subversion_test/folder', nil)
assert_equal ['10', '9', '7', '6', '5', '2'], changesets.collect(&:revision) assert_equal ['10', '9', '7', '6', '5', '2'], changesets.collect(&:revision)
# with path and revision # with path and revision
changesets = @repository.latest_changesets('subversion_test/folder', 8) changesets = @repository.latest_changesets('subversion_test/folder', 8)
assert_equal ['7', '6', '5', '2'], changesets.collect(&:revision) assert_equal ['7', '6', '5', '2'], changesets.collect(&:revision)
end end
it 'should directory listing with square brackets in path' do it 'should directory listing with square brackets in path' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
entries = @repository.entries('subversion_test/[folder_with_brackets]') entries = @repository.entries('subversion_test/[folder_with_brackets]')
assert_not_nil entries, 'Expect to find entries in folder_with_brackets' assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets' assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
assert_equal 'README.txt', entries.first.name assert_equal 'README.txt', entries.first.name
end end
it 'should directory listing with square brackets in base' do it 'should directory listing with square brackets in base' do
@project = Project.find(3) @project = Project.find(3)
@repository = Repository::Subversion.create( @repository = Repository::Subversion.create(
project: @project, project: @project,
url: "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]") url: "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision' assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add' assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
entries = @repository.entries('') entries = @repository.entries('')
assert_not_nil entries, 'Expect to find entries' assert_not_nil entries, 'Expect to find entries'
assert_equal 1, entries.size, 'Expect a single entry' assert_equal 1, entries.size, 'Expect a single entry'
assert_equal 'README.txt', entries.first.name assert_equal 'README.txt', entries.first.name
end end
it 'should identifier' do it 'should identifier' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
c = @repository.changesets.find_by_revision('1') c = @repository.changesets.find_by_revision('1')
assert_equal c.revision, c.identifier assert_equal c.revision, c.identifier
end end
it 'should find changeset by empty name' do it 'should find changeset by empty name' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
['', ' ', nil].each do |r| ['', ' ', nil].each do |r|
assert_nil @repository.find_changeset_by_name(r) assert_nil @repository.find_changeset_by_name(r)
end
end end
end
it 'should identifier nine digit' do it 'should identifier nine digit' do
c = Changeset.new(repository: @repository, committed_on: Time.now, c = Changeset.new(repository: @repository, committed_on: Time.now,
revision: '123456789', comments: 'test') revision: '123456789', comments: 'test')
assert_equal c.identifier, c.revision assert_equal c.identifier, c.revision
end end
it 'should format identifier' do it 'should format identifier' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
c = @repository.changesets.find_by_revision('1') c = @repository.changesets.find_by_revision('1')
assert_equal c.format_identifier, c.revision assert_equal c.format_identifier, c.revision
end end
it 'should format identifier nine digit' do it 'should format identifier nine digit' do
c = Changeset.new(repository: @repository, committed_on: Time.now, c = Changeset.new(repository: @repository, committed_on: Time.now,
revision: '123456789', comments: 'test') revision: '123456789', comments: 'test')
assert_equal c.format_identifier, c.revision assert_equal c.format_identifier, c.revision
end end
it 'should activities' do it 'should activities' do
c = Changeset.create(repository: @repository, committed_on: Time.now, c = Changeset.create(repository: @repository, committed_on: Time.now,
revision: '1', comments: 'test') revision: '1', comments: 'test')
event = find_events(User.find(2)).first # manager event = find_events(User.find(2)).first # manager
assert event.event_title.include?('1:') assert event.event_title.include?('1:')
assert event.event_path =~ /\?rev=1$/ assert event.event_path =~ /\?rev=1$/
end end
it 'should activities nine digit' do it 'should activities nine digit' do
c = Changeset.create(repository: @repository, committed_on: Time.now, c = Changeset.create(repository: @repository, committed_on: Time.now,
revision: '123456789', comments: 'test') revision: '123456789', comments: 'test')
event = find_events(User.find(2)).first # manager event = find_events(User.find(2)).first # manager
assert event.event_title.include?('123456789:') assert event.event_title.include?('123456789:')
assert event.event_path =~ /\?rev=123456789$/ assert event.event_path =~ /\?rev=123456789$/
end end
it 'should log encoding ignore setting' do it 'should log encoding ignore setting' do
with_settings commit_logs_encoding: 'windows-1252' do with_settings commit_logs_encoding: 'windows-1252' do
s1 = "\xC2\x80" s1 = "\xC2\x80"
s2 = "\xc3\x82\xc2\x80" s2 = "\xc3\x82\xc2\x80"
if s1.respond_to?(:force_encoding) if s1.respond_to?(:force_encoding)
s1.force_encoding('ISO-8859-1') s1.force_encoding('ISO-8859-1')
s2.force_encoding('UTF-8') s2.force_encoding('UTF-8')
assert_equal s1.encode('UTF-8'), s2 assert_equal s1.encode('UTF-8'), s2
end
c = Changeset.new(repository: @repository,
comments: s2,
revision: '123',
committed_on: Time.now)
assert c.save
assert_equal s2, c.comments
end end
c = Changeset.new(repository: @repository,
comments: s2,
revision: '123',
committed_on: Time.now)
assert c.save
assert_equal s2, c.comments
end end
end
it 'should previous' do it 'should previous' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
changeset = @repository.find_changeset_by_name('3') changeset = @repository.find_changeset_by_name('3')
assert_equal @repository.find_changeset_by_name('2'), changeset.previous assert_equal @repository.find_changeset_by_name('2'), changeset.previous
end end
it 'should previous nil' do it 'should previous nil' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
changeset = @repository.find_changeset_by_name('1') changeset = @repository.find_changeset_by_name('1')
assert_nil changeset.previous assert_nil changeset.previous
end end
it 'should next' do it 'should next' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
changeset = @repository.find_changeset_by_name('2') changeset = @repository.find_changeset_by_name('2')
assert_equal @repository.find_changeset_by_name('3'), changeset.next assert_equal @repository.find_changeset_by_name('3'), changeset.next
end end
it 'should next nil' do it 'should next nil' do
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
changeset = @repository.find_changeset_by_name('11') changeset = @repository.find_changeset_by_name('11')
assert_nil changeset.next assert_nil changeset.next
end
else
puts 'Subversion test repository NOT FOUND. Skipping unit tests !!!'
it 'should fake' do; assert true end
end end
private private

Loading…
Cancel
Save