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

Spree::OptionValue#name delegates to Spree::OptionType even when nil #3517

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
1 change: 0 additions & 1 deletion api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
end
resources :option_values

resources :option_values, only: :index
get '/orders/mine', to: 'orders#mine', as: 'my_orders'
get "/orders/current", to: "orders#current", as: "current_order"

Expand Down
16 changes: 10 additions & 6 deletions api/spec/requests/spree/api/option_values_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ module Spree
stub_authentication!
end

def check_option_values(option_values)
expect(option_values.count).to eq(1)
expect(option_values.first).to have_attributes([:id, :name, :presentation,
:option_type_name, :option_type_id])
end

context "without any option type scoping" do
before do
# Create another option value with a brand new option type
Expand Down Expand Up @@ -116,6 +110,16 @@ def check_option_values(option_values)
expect(option_value.name).to eq("Option Value")
end

it "can create an option value" do
post spree.api_option_values_path, params: { option_value: {
name: "Option Value",
presentation: 'option value'
} }
expect(response.status).to eq(201)

expect(json_response).to have_attributes(attributes)
end

it "permits the correct attributes" do
expect_any_instance_of(Spree::Api::OptionValuesController).to receive(:permitted_option_value_attributes)
put spree.api_option_value_path(option_value), params: { option_value: { name: "" } }
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/option_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OptionValue < Spree::Base
after_save :touch, if: :saved_changes?
after_touch :touch_all_variants

delegate :name, :presentation, to: :option_type, prefix: :option_type
delegate :name, :presentation, to: :option_type, prefix: :option_type, allow_nil: true

self.whitelisted_ransackable_attributes = %w[name presentation]

Expand Down