scm: fix error on revision page for empty revision (#7307).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4703 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
43f6a62680
commit
98b3a50657
|
@ -139,6 +139,7 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def revision
|
def revision
|
||||||
|
raise ChangesetNotFound if @rev.nil? || @rev.empty?
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
@changeset = @repository.find_changeset_by_name(@rev)
|
||||||
raise ChangesetNotFound unless @changeset
|
raise ChangesetNotFound unless @changeset
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ class Repository < ActiveRecord::Base
|
||||||
|
|
||||||
# Finds and returns a revision with a number or the beginning of a hash
|
# Finds and returns a revision with a number or the beginning of a hash
|
||||||
def find_changeset_by_name(name)
|
def find_changeset_by_name(name)
|
||||||
|
return nil if name.nil? || name.empty?
|
||||||
changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
|
changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -176,6 +176,26 @@ class RepositoriesGitControllerTest < ActionController::TestCase
|
||||||
assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
|
assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
|
||||||
:content => /can not be annotated/
|
:content => /can not be annotated/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_revision
|
||||||
|
@repository.fetch_changesets
|
||||||
|
@repository.reload
|
||||||
|
['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
|
||||||
|
get :revision, :id => 3, :rev => r
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'revision'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_empty_revision
|
||||||
|
@repository.fetch_changesets
|
||||||
|
@repository.reload
|
||||||
|
['', ' ', nil].each do |r|
|
||||||
|
get :revision, :id => 1, :rev => r
|
||||||
|
assert_response 500
|
||||||
|
assert_error_tag :content => /was not found/
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts "Git test repository NOT FOUND. Skipping functional tests !!!"
|
puts "Git test repository NOT FOUND. Skipping functional tests !!!"
|
||||||
def test_fake; assert true end
|
def test_fake; assert true end
|
||||||
|
|
|
@ -171,7 +171,15 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
|
||||||
assert_response 500
|
assert_response 500
|
||||||
assert_error_tag :content => /was not found/
|
assert_error_tag :content => /was not found/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_empty_revision
|
||||||
|
['', ' ', nil].each do |r|
|
||||||
|
get :revision, :id => 1, :rev => r
|
||||||
|
assert_response 500
|
||||||
|
assert_error_tag :content => /was not found/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_revision_with_repository_pointing_to_a_subdirectory
|
def test_revision_with_repository_pointing_to_a_subdirectory
|
||||||
r = Project.find(1).repository
|
r = Project.find(1).repository
|
||||||
# Changes repository url to a subdirectory
|
# Changes repository url to a subdirectory
|
||||||
|
|
|
@ -63,6 +63,23 @@ class RepositoryGitTest < ActiveSupport::TestCase
|
||||||
assert_equal 15, @repository.changesets.count
|
assert_equal 15, @repository.changesets.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_find_changeset_by_name
|
||||||
|
@repository.fetch_changesets
|
||||||
|
@repository.reload
|
||||||
|
['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
|
||||||
|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
|
||||||
|
@repository.find_changeset_by_name(r).revision
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_changeset_by_empty_name
|
||||||
|
@repository.fetch_changesets
|
||||||
|
@repository.reload
|
||||||
|
['', ' ', nil].each do |r|
|
||||||
|
assert_nil @repository.find_changeset_by_name(r)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_identifier
|
def test_identifier
|
||||||
@repository.fetch_changesets
|
@repository.fetch_changesets
|
||||||
@repository.reload
|
@repository.reload
|
||||||
|
|
|
@ -96,6 +96,14 @@ class RepositorySubversionTest < ActiveSupport::TestCase
|
||||||
assert_equal c.revision, c.identifier
|
assert_equal c.revision, c.identifier
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_find_changeset_by_empty_name
|
||||||
|
@repository.fetch_changesets
|
||||||
|
@repository.reload
|
||||||
|
['', ' ', nil].each do |r|
|
||||||
|
assert_nil @repository.find_changeset_by_name(r)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_identifier_nine_digit
|
def test_identifier_nine_digit
|
||||||
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')
|
||||||
|
|
Loading…
Reference in New Issue