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

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

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

@ -30,36 +30,33 @@
require File.expand_path('../../../../../../test_helper', __FILE__)
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
@adapter = Redmine::Scm::Adapters::FilesystemAdapter.new(REPOSITORY_PATH)
end
before do
skip 'Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS.' unless File.directory?(fs_repository_path)
it 'should entries' do
assert_equal 3, @adapter.entries.size
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
@adapter = Redmine::Scm::Adapters::FilesystemAdapter.new(fs_repository_path)
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)
it 'should entries' do
assert_equal 3, @adapter.entries.size
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
else
puts 'Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS.'
it 'should fake' do; assert true 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
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

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

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

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

Loading…
Cancel
Save