Respond with 404 instead of 500 when requesting a wiki diff with invalid versions (#12434).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10877 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-11-24 12:27:00 +00:00
parent 845d7bc645
commit 29fc292b18
2 changed files with 17 additions and 1 deletions

View File

@ -112,7 +112,8 @@ class WikiPage < ActiveRecord::Base
def diff(version_to=nil, version_from=nil)
version_to = version_to ? version_to.to_i : self.content.version
content_to = content.versions.find_by_version(version_to)
content_from = version_from ? content.versions.find_by_version(version_from.to_i) : content_to.previous
content_from = version_from ? content.versions.find_by_version(version_from.to_i) : content_to.try(:previous)
return nil unless content_to && content_from
if content_from.version > content_to.version
content_to, content_from = content_from, content_to

View File

@ -552,6 +552,16 @@ class WikiControllerTest < ActionController::TestCase
assert_select 'span.diff_in', :text => 'Line added'
end
def test_diff_with_invalid_version_should_respond_with_404
get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
assert_response 404
end
def test_diff_with_invalid_version_from_should_respond_with_404
get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98'
assert_response 404
end
def test_annotate
get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
assert_response :success
@ -576,6 +586,11 @@ class WikiControllerTest < ActionController::TestCase
}
end
def test_annotate_with_invalid_version_should_respond_with_404
get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
assert_response 404
end
def test_get_rename
@request.session[:user_id] = 2
get :rename, :project_id => 1, :id => 'Another_page'