I’m having trouble with rescue_action_in_public, both in getting it
to work right in my rails app, and in writing tests to make sure.
What I ultimately want to do is test for what a normal user would see
when an error is trapped.
I override local_request? like so:
application.rb
def rescue_action_in_public(exception)
render :text => “oops”
end
def local_request?
false
end
Also, I altered the environments files so I won’t get the standard
developer error messages (although this seems like possible overkill)
development.rb
config.action_controller.consider_all_requests_local = false
test.rb
config.action_controller.consider_all_requests_local = false
In my functional tests, I chose a random controller to use, and
commented out the local rescue_action, so the test won’t stop when
rails hits an error (I assume this is what I want, because I want to
continue processing the error, not stop):
group_controller_test.rb
class GroupController; def rescue_action(e) raise e end; end
def test_error_no_such_group
post :home, :id => “this_is_not_a_valid_id”
assert_tag :content => “oops”
end
When I run this test, the test.log shows the expected
“ActiveRecord::RecordNotFound (Couldn’t find Group with
ID=this_is_not_a_valid_id)” but the test passes successfully. If I
uncomment the rescue_action(e) line at the top of the
group_controller_test.rb, the test fails, but the assert_tag check is
never performed so I can’t see what rescue_action_in_public is doing.
I could use some advice about how to configure things so I can
deliberately cause errors, and confirm they’re being handled right by
the application controller.
Sorry for the lengthy post, but I wanted to be thorough in explaining
the problem.
Any ideas or suggestions are greatly appreciated. Thanks in advance
to everyone.
-Jason
PS: As far as routes.rb, there’s nothing in there doing any explicit
routing to my application controller or the rescue_action_in_public
method, so I don’t think that’s a factor.
–
Jason F. - [email protected]
work: (310) 601-8454
cell: (415) 254-4890
AIM/Skype: jfrankov