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.

`HttpCacheResponder` was deliberately excluded in version 1.8.0

Close: #862

Ref:
- heartcombo/responders#240
- a9fb8e1
  • Loading branch information
tagliala committed Aug 20, 2024
1 parent 6d716df commit bf8be73
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Test against Rails 7.2 [#921][].
* Change return codes to new Responders defaults [#918][].

## Version 1.14.0

Expand Down Expand Up @@ -229,4 +230,5 @@ _No changes_.
* First release. Support to I18n, singleton controllers, polymorphic controllers, belongs_to, nested_belongs_to and url helpers.

[#873]: https://github.com/activeadmin/inherited_resources/pull/873
[#918]: https://github.com/activeadmin/inherited_resources/pull/918
[#921]: https://github.com/activeadmin/inherited_resources/pull/921
3 changes: 3 additions & 0 deletions lib/inherited_resources/responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
module InheritedResources
class Responder < ActionController::Responder
include Responders::FlashResponder

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 bf8be73

Please sign in to comment.