Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Handle errors and flash messages editing a taxon #3574

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/taxons_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ module Spree
end

it "cannot create a new taxon with invalid attributes" do
post spree.api_taxonomy_taxons_path(taxonomy), params: { taxon: { foo: :bar } }
post spree.api_taxonomy_taxons_path(taxonomy), params: { taxon: { name: '' } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the reason why for this change, can you explain to me? thanks 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was passing due the wrong check, it was actually passing because foo is not a permitted param, and using name it actually runs the validations

expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")

Expand Down
8 changes: 7 additions & 1 deletion backend/app/controllers/spree/admin/taxons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ def update
end

respond_with(@taxon) do |format|
format.html { redirect_to edit_admin_taxonomy_url(@taxonomy) }
format.html do
if @taxon.valid?
redirect_to edit_admin_taxonomy_url(@taxonomy)
else
render :edit
end
end
end
end

Expand Down