Skip to content

Commit

Permalink
Merge pull request #3517 from nebulab/SamuelMartini/allow_nil_option_…
Browse files Browse the repository at this point in the history
…value_method_delegation

Spree::OptionValue#name delegates to Spree::OptionType even when nil
  • Loading branch information
kennyadsl authored Feb 18, 2020
2 parents 0b88118 + 14a2261 commit 72e7157
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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

0 comments on commit 72e7157

Please sign in to comment.