Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return 422 - :unprocessable_entity when form submissions fails (#294)
* Adding HTTP Status Code for failed #update action Co-authored-by: Romanos Fessas <romanos@fessas.com>
- Loading branch information
1 parent
a46ffb8
commit d360aaa
Showing
7 changed files
with
63 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
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,18 @@ | ||
require 'test_helper' | ||
|
||
class StatusCodesControllerTest < WickedControllerTestCase | ||
test 'returns successful status code for show' do | ||
get :show, params: { id: 'good' } | ||
assert_response(:success) | ||
end | ||
|
||
test 'returns correct status code for successfuly update' do | ||
put :update, params: { id: 'good' } | ||
assert_response(:redirect) | ||
end | ||
|
||
test 'returns correct status code for failed update' do | ||
put :update, params: { id: 'bad' } | ||
assert_response(:unprocessable_entity) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class StatusCodesController < ApplicationController | ||
include Wicked::Wizard | ||
|
||
class GoodThing | ||
def save | ||
true | ||
end | ||
end | ||
|
||
class BadThing | ||
def save | ||
false | ||
end | ||
end | ||
|
||
steps :good, :bad | ||
|
||
def index; end | ||
|
||
def show | ||
render_wizard | ||
end | ||
|
||
def update | ||
case step | ||
when :good | ||
@thing = GoodThing.new | ||
when :bad | ||
@thing = BadThing.new | ||
end | ||
render_wizard(@thing, notice: "Thing was updated from step #{step}.") | ||
end | ||
|
||
private | ||
|
||
def finish_wizard_path | ||
updates_path | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bad step |
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 @@ | ||
good step |
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