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

Fix option_values nested attributes behavior on the API #4409

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
4 changes: 0 additions & 4 deletions api/openapi/solidus-api.oas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7185,10 +7185,6 @@ components:
type: array
items:
type: integer
option_values_attributes:
type: array
items:
$ref: '#/components/schemas/option-value-input'
options:
type: object
description: '`Name` will be the name/presentation of the option type and `Value` will be the name/presentation of the option value. They will be created if not exist.'
Expand Down
16 changes: 16 additions & 0 deletions api/spec/requests/spree/api/option_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ def check_option_values(option_values)
expect(response.status).to eq(201)
end

it "can create an option type with nested option values" do
post spree.api_option_types_path, params: {
option_type: {
name: "Option Type",
presentation: "Option Type",
option_values_attributes: [
name: "foo", presentation: "Foo"
]
}
}

option_value = Spree::OptionType.find(json_response["id"]).option_values.first
expect(option_value).not_to be(nil)
expect(option_value.name).to eq("foo")
end

it "cannot create an option type with invalid attributes" do
post spree.api_option_types_path, params: { option_type: {} }
expect(response.status).to eq(422)
Expand Down
6 changes: 3 additions & 3 deletions core/lib/spree/permitted_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ module PermittedAttributes

@@line_item_attributes = [:id, :variant_id, :quantity]

@@option_type_attributes = [:name, :presentation, :option_values_attributes]

@@option_value_attributes = [:name, :presentation]

@@option_type_attributes = [:name, :presentation, option_values_attributes: option_value_attributes]

@@payment_attributes = [:amount, :payment_method_id, :payment_method]

@@product_properties_attributes = [:property_name, :value, :position]
Expand Down Expand Up @@ -131,7 +131,7 @@ module PermittedAttributes
@@variant_attributes = [
:name, :presentation, :cost_price, :lock_version,
:position, :track_inventory,
:product_id, :product, :option_values_attributes, :price,
:product_id, :product, :price,
:weight, :height, :width, :depth, :sku, :cost_currency, option_value_ids: [], options: [:name, :value]
]

Expand Down