10000 Change default error and redirect status codes · activeadmin/inherited_resources@c7df3eb · GitHub
[go: up one dir, main page]

Skip to content

Commit c7df3eb

Browse files
a-nickoljavierjulio
authored andcommitted
Change default error and redirect status codes
Update responder class to the current defaults for responder gem Close: #862 Ref: heartcombo/responders#240
1 parent 0b7e34d commit c7df3eb

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lib/inherited_resources/responder.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
module InheritedResources
44
class Responder < ActionController::Responder
55
include Responders::FlashResponder
6+
include Responders::HttpCacheResponder
7+
8+
# Configure default status codes for responding to errors and redirects.
9+
self.error_status = :unprocessable_entity
10+
self.redirect_status = :see_other
611
end
712
end

test/aliases_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_dumb_responder_quietly_receives_everything_on_failure
107107
@controller.stubs(:resource_url).returns('http://test.host/')
108108
post :create
109109

110-
assert_response :success
110+
assert_response :unprocessable_entity
111111
assert_equal "New HTML", @response.body.strip
112112
end
113113

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

120-
assert_response :success
120+
assert_response :unprocessable_entity
121121
assert_equal "New HTML", @response.body.strip
122122
end
123123

test/base_test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_render_new_template_when_user_cannot_be_saved
246246
User.stubs(:new).returns(mock_user(save: false, errors: {some: :error}))
247247
post :create
248248

249-
assert_response :success
249+
assert_response :unprocessable_entity
250250
assert_equal "New HTML", @response.body.strip
251251
end
252252

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

325-
assert_response :success
325+
assert_response :unprocessable_entity
326326
assert_equal "Edit HTML", @response.body.strip
327327
end
328328

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

373+
assert_response :unprocessable_entity
373374
assert_equal 'User could not be destroyed.', flash[:alert]
374375
end
375376

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

382+
assert_response :see_other
381383
assert_redirected_to 'http://test.host/'
382384
end
383385

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

391+
assert_response :see_other
389392
assert_redirected_to 'http://test.host/'
390393
end
391394
end

test/customized_base_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_render_new_template_when_user_cannot_be_saved
141141
Car.stubs(:create_new).returns(mock_car(save_successfully: false, errors: {some: :error}))
142142
post :create
143143

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

172-
assert_response :success
172+
assert_response :unprocessable_entity
173173
assert_equal "Edit HTML", @response.body.strip
174174
end
175175
end

0 commit comments

Comments
 (0)
0