Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

update specs for Variant and OptionValueVariant

Łukasz Adamczyk3b4c91540e4f
diff --git a/core/lib/spree/testing_support/factories/options_factory.rb b/core/lib/spree/testing_support/factories/options_factory.rb
index f93cdd945c..56392b07a1 100644
--- a/core/lib/spree/testing_support/factories/options_factory.rb
+++ b/core/lib/spree/testing_support/factories/options_factory.rb
@@ -5,6 +5,11 @@ FactoryBot.define do
option_type
end
+ factory :option_value_variant, class: Spree::OptionValueVariant do
+ option_value
+ variant
+ end
+
factory :option_type, class: Spree::OptionType do
sequence(:name) { |n| "foo-size-#{n}" }
presentation { 'Size' }
diff --git a/core/spec/models/spree/option_value_variant_spec.rb b/core/spec/models/spree/option_value_variant_spec.rb
new file mode 100644
index 0000000000..747df3e4a7
--- /dev/null
+++ b/core/spec/models/spree/option_value_variant_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe Spree::OptionValueVariant, type: :model do
+ let(:option_value_variant) { create(:option_value_variant) }
+
+ describe 'touching' do
+ let(:variant) { option_value_variant.variant }
+
+ it 'touches a variant' do
+ expect(variant).to receive(:touch)
+ option_value_variant.touch
+ end
+ end
+end
diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb
index 8aebb89ce9..6f8828e09e 100644
--- a/core/spec/models/spree/variant_spec.rb
+++ b/core/spec/models/spree/variant_spec.rb
@@ -684,6 +684,22 @@ describe Spree::Variant, type: :model do
expect(Rails.cache).to receive(:delete).with(variant.send(:in_stock_cache_key))
variant.touch
end
+
+ context 'when unlinking an option value' do
+ let(:option_value) { create(:option_value) }
+
+ before do
+ variant.option_values << option_value
+ variant.save!
+ end
+
+ it 'touches variant' do
+ expect(variant).to receive(:touch)
+
+ option_values = variant.option_values - [option_value]
+ variant.update(option_values: option_values)
+ end
+ end
end
describe '#should_track_inventory?' do