Skip to content

Commit

Permalink
Merge pull request #342 from jsurdilla/add-product-option-types-callb…
Browse files Browse the repository at this point in the history
…acks

Touch associated product when its option types change.
  • Loading branch information
magnusvk committed Sep 1, 2015
2 parents de81466 + 023b639 commit 8efdfb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/product_option_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Spree
class ProductOptionType < Spree::Base
belongs_to :product, class_name: 'Spree::Product', inverse_of: :product_option_types
belongs_to :product, class_name: 'Spree::Product', inverse_of: :product_option_types, touch: true
belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :product_option_types
acts_as_list scope: :product
end
Expand Down
21 changes: 19 additions & 2 deletions core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,26 @@ class Extension < Spree::Base

expect(product2.slug).to eq 'test-456'
end

end

context "associations" do
describe "product_option_types" do
it "touches the product instance when an option type is added" do
expect {
product.product_option_types.create(option_type: create(:option_type, name: 'new-option-type'))
product.reload
}.to change { product.updated_at }
end

it "touches product instance when an option type is removed" do
product.product_option_types.create(option_type: create(:option_type, name: 'new-option-type'))
expect {
product.product_option_types = []
product.reload
}.to change { product.updated_at }
end
end
end
end

context "properties" do
Expand Down Expand Up @@ -432,7 +449,7 @@ def build_option_type_with_values(name, values)
expect(product.reload.total_on_hand).to eql(5)
end
end

# Regression spec for https://github.com/spree/spree/issues/5588
context '#validate_master when duplicate SKUs entered' do
let!(:first_product) { create(:product, sku: 'a-sku') }
Expand Down

0 comments on commit 8efdfb8

Please sign in to comment.