Skip to content

Commit

Permalink
Merge pull request solidusio#3940 from CandleScience/fix-no_method_er…
Browse files Browse the repository at this point in the history
…ror-original_message

Only use #original_message in Api::BaseController#parameter_missing_error if defined
  • Loading branch information
kennyadsl authored Feb 18, 2021
2 parents 0d2e3a8 + 46d4bf4 commit 61864f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/app/controllers/spree/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def gateway_error(exception)
end

def parameter_missing_error(exception)
message = exception.original_message || exception.message
# use original_message to remove DidYouMean suggestions, if defined
message = exception.try(:original_message) || exception.message
render json: {
exception: message,
error: message,
Expand Down
28 changes: 27 additions & 1 deletion api/spec/controllers/spree/api/base_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,37 @@ class FakesController < Spree::Api::BaseController
def index
render json: { "products" => [] }
end

def create
params.require(:order).permit(:number)
render json: { "order" => {} }
end
end

before do
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw { get 'index', to: 'spree/api/base#index' }
r.draw do
get 'index', to: 'spree/api/base#index'
post 'create', to: 'spree/api/base#create'
end
end
end

context "when validating presence of params" do
let!(:user) { create(:user, spree_api_key: "fake_key") }

context "if params are missing" do
it "returns an unprocessable_entity" do
post :create, params: { token: "fake_key" }
expect(response.status).to eq(422)
end
end

context "if params are not missing" do
it "does not return an unprocessable_entity" do
post :create, params: { token: "fake_key", order: { number: "R12345" } }
expect(response.status).to eq(200)
end
end
end

Expand Down

0 comments on commit 61864f8

Please sign in to comment.