diff --git a/CHANGELOG.md b/CHANGELOG.md index ec3072bb..2905b7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Test against Rails 7.2 [#921][]. +* Change return codes to new Responders defaults [#918][]. ## Version 1.14.0 @@ -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 diff --git a/lib/inherited_resources/responder.rb b/lib/inherited_resources/responder.rb index 19a559e0..44a65827 100644 --- a/lib/inherited_resources/responder.rb +++ b/lib/inherited_resources/responder.rb @@ -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 diff --git a/test/aliases_test.rb b/test/aliases_test.rb index 8dda29a2..4665fdce 100644 --- a/test/aliases_test.rb +++ b/test/aliases_test.rb @@ -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 @@ -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 diff --git a/test/base_test.rb b/test/base_test.rb index c4a59642..14d3f8f8 100644 --- a/test/base_test.rb +++ b/test/base_test.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/customized_base_test.rb b/test/customized_base_test.rb index 5a43f034..a608ada8 100644 --- a/test/customized_base_test.rb +++ b/test/customized_base_test.rb @@ -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 @@ -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