Commit 7824eca7 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Refactor: merged error rendering methods.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4286 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent eea456ed
...@@ -275,39 +275,31 @@ class ApplicationController < ActionController::Base ...@@ -275,39 +275,31 @@ class ApplicationController < ActionController::Base
def render_403(options={}) def render_403(options={})
@project = nil @project = nil
@message = options[:message] || :notice_not_authorized render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
@message = l(@message) if @message.is_a?(Symbol)
respond_to do |format|
format.html { render :template => "common/403", :layout => use_layout, :status => 403 }
format.atom { head 403 }
format.xml { head 403 }
format.js { head 403 }
format.json { head 403 }
end
return false return false
end end
def render_404 def render_404(options={})
respond_to do |format| render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
format.html { render :template => "common/404", :layout => use_layout, :status => 404 }
format.atom { head 404 }
format.xml { head 404 }
format.js { head 404 }
format.json { head 404 }
end
return false return false
end end
def render_error(msg) # Renders an error response
def render_error(arg)
arg = {:message => arg} unless arg.is_a?(Hash)
@message = arg[:message]
@message = l(@message) if @message.is_a?(Symbol)
@status = arg[:status] || 500
respond_to do |format| respond_to do |format|
format.html { format.html {
flash.now[:error] = msg render :template => 'common/error', :layout => use_layout, :status => @status
render :text => '', :layout => use_layout, :status => 500
} }
format.atom { head 500 } format.atom { head @status }
format.xml { head 500 } format.xml { head @status }
format.js { head 500 } format.js { head @status }
format.json { head 500 } format.json { head @status }
end end
end end
......
<h2>404</h2>
<p><%= l(:notice_file_not_found) %></p>
<p><a href="javascript:history.back()">Back</a></p>
<% html_title '404' %>
<h2>403</h2> <h2><%=h @status %></h2>
<p><%=h @message %></p> <p id="errorExplanation"><%=h @message %></p>
<p><a href="javascript:history.back()">Back</a></p> <p><a href="javascript:history.back()">Back</a></p>
<% html_title '403' %> <% html_title @status %>
...@@ -340,9 +340,7 @@ class IssuesControllerTest < ActionController::TestCase ...@@ -340,9 +340,7 @@ class IssuesControllerTest < ActionController::TestCase
get :new, :project_id => 1 get :new, :project_id => 1
assert_response 500 assert_response 500
assert_not_nil flash[:error] assert_error_tag :content => /No default issue/
assert_tag :tag => 'div', :attributes => { :class => /error/ },
:content => /No default issue/
end end
def test_get_new_with_no_tracker_should_display_an_error def test_get_new_with_no_tracker_should_display_an_error
...@@ -351,9 +349,7 @@ class IssuesControllerTest < ActionController::TestCase ...@@ -351,9 +349,7 @@ class IssuesControllerTest < ActionController::TestCase
get :new, :project_id => 1 get :new, :project_id => 1
assert_response 500 assert_response 500
assert_not_nil flash[:error] assert_error_tag :content => /No tracker/
assert_tag :tag => 'div', :attributes => { :class => /error/ },
:content => /No tracker/
end end
def test_update_new_form def test_update_new_form
......
...@@ -113,11 +113,15 @@ class ActiveSupport::TestCase ...@@ -113,11 +113,15 @@ class ActiveSupport::TestCase
def self.repository_configured?(vendor) def self.repository_configured?(vendor)
File.directory?(repository_path(vendor)) File.directory?(repository_path(vendor))
end end
def assert_error_tag(options={})
assert_tag({:tag => 'p', :attributes => { :id => 'errorExplanation' }}.merge(options))
end
# Shoulda macros # Shoulda macros
def self.should_render_404 def self.should_render_404
should_respond_with :not_found should_respond_with :not_found
should_render_template 'common/404' should_render_template 'common/error'
end end
def self.should_have_before_filter(expected_method, options = {}) def self.should_have_before_filter(expected_method, options = {})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment