Skip to content

Commit

Permalink
Change default error and redirect status codes
Browse files Browse the repository at this point in the history
Update responder class to the current defaults for responder gem

Close: #862

Ref: heartcombo/responders#240
  • Loading branch information
a-nickol authored and javierjulio committed Jun 15, 2024
1 parent 0b7e34d commit c7df3eb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/inherited_resources/responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
module InheritedResources
class Responder < ActionController::Responder
include Responders::FlashResponder
include Responders::HttpCacheResponder

# Configure default status codes for responding to errors and redirects.
self.error_status = :unprocessable_entity
self.redirect_status = :see_other
end
end
4 changes: 2 additions & 2 deletions test/aliases_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_dumb_responder_quietly_receives_everything_on_failure
@controller.stubs(:resource_url).returns('http://test.host/')
post :create

assert_response :success
assert_response :unprocessable_entity
assert_equal "New HTML", @response.body.strip
end

Expand All @@ -117,7 +117,7 @@ def test_html_is_the_default_when_only_xml_is_overwritten
@controller.stubs(:resource_url).returns('http://test.host/')
post :create

assert_response :success
assert_response :unprocessable_entity
assert_equal "New HTML", @response.body.strip
end

Expand Down
7 changes: 5 additions & 2 deletions test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_render_new_template_when_user_cannot_be_saved
User.stubs(:new).returns(mock_user(save: false, errors: {some: :error}))
post :create

assert_response :success
assert_response :unprocessable_entity
assert_equal "New HTML", @response.body.strip
end

Expand Down Expand Up @@ -322,7 +322,7 @@ def test_render_edit_template_when_user_cannot_be_saved
User.stubs(:find).returns(mock_user(update: false, errors: {some: :error}))
put :update, params: { id: '42' }

assert_response :success
assert_response :unprocessable_entity
assert_equal "Edit HTML", @response.body.strip
end

Expand Down Expand Up @@ -370,6 +370,7 @@ def test_show_flash_message_with_javascript_request_when_user_cannot_be_deleted
User.stubs(:find).returns(mock_user(destroy: false, errors: { fail: true }))
delete :destroy, params: { id: '42' }, format: :js

assert_response :unprocessable_entity
assert_equal 'User could not be destroyed.', flash[:alert]
end

Expand All @@ -378,6 +379,7 @@ def test_redirects_to_users_list
@controller.expects(:collection_url).returns('http://test.host/')
delete :destroy, params: { id: '42' }

assert_response :see_other
assert_redirected_to 'http://test.host/'
end

Expand All @@ -386,6 +388,7 @@ def test_redirects_to_the_resource_if_cannot_be_destroyed
@controller.expects(:collection_url).returns('http://test.host/')
delete :destroy, params: { id: '42' }

assert_response :see_other
assert_redirected_to 'http://test.host/'
end
end
4 changes: 2 additions & 2 deletions test/customized_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_render_new_template_when_user_cannot_be_saved
Car.stubs(:create_new).returns(mock_car(save_successfully: false, errors: {some: :error}))
post :create

assert_response :success
assert_response :unprocessable_entity
assert_equal "New HTML", @response.body.strip
end
end
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_render_edit_template_when_user_cannot_be_saved
Car.stubs(:get).returns(mock_car(update_successfully: false, errors: {some: :error}))
put :update, params: { id: '42' }

assert_response :success
assert_response :unprocessable_entity
assert_equal "Edit HTML", @response.body.strip
end
end
Expand Down

0 comments on commit c7df3eb

Please sign in to comment.