Skip to content

Commit

Permalink
Deprecate passing return_items_attributes in API as hash of hashes
Browse files Browse the repository at this point in the history
This is a behaviour which was previously undocumented worked because of the
native Rails parameter parsing for nested attributes. This is not
something we want to support through the API going forward so we are
adding a deprecation warning for anyone using this behaviour currently.
  • Loading branch information
forkata committed Apr 16, 2021
1 parent c99c98b commit 00ffaf2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/app/controllers/spree/api/customer_returns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def build_customer_return

if return_items_params.is_a? ActionController::Parameters
return_items_params = return_items_params.values
Spree::Deprecation.warn(
"Passing `return_items_attributes` as a hash of hashes is \
deprecated and will be removed in future versions of Solidus."
)
end

@customer_return = CustomerReturn.new(customer_return_attributes)
Expand Down
10 changes: 10 additions & 0 deletions api/spec/requests/spree/api/customer_returns_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,22 @@ module Spree
end

it "can create a new customer return" do
expect(Spree::Deprecation).to receive(:warn)
expect { subject }.to change { Spree::CustomerReturn.count }.
from(0).to(1)

expect(response).to have_http_status(:success)
expect(json_response).to have_attributes(attributes)
end

it "logs a deprecation warning" do
expect(Spree::Deprecation).
to receive(:warn).
with(
/Passing `return_items_attributes` as a hash of hashes is deprecated/
)
subject
end
end

context "with reception_status_event provided for return item" do
Expand Down

0 comments on commit 00ffaf2

Please sign in to comment.