forked from rails-api/active_model_serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rescue_from handler to clear state
Fixes rails-api#917
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'test_helper' | ||
|
||
module ActionController | ||
module Serialization | ||
class RescueFromTest < ActionController::TestCase | ||
class MyController < ActionController::Base | ||
rescue_from Exception, with: :handle_error | ||
|
||
def render_using_raise_error_serializer | ||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) | ||
render json: [@profile], serializer: RaiseErrorSerializer | ||
end | ||
|
||
def handle_error(exception) | ||
render json: { errors: ['Internal Server Error'] }, status: :internal_server_error | ||
end | ||
end | ||
|
||
tests MyController | ||
|
||
def test_rescue_from | ||
get :render_using_raise_error_serializer | ||
|
||
expected = { | ||
errors: ['Internal Server Error'] | ||
}.to_json | ||
|
||
assert_equal expected, @response.body | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters