mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add new context to spec so that some basic setup can be shared with new specs that will be added, it's mostly indentation here
This commit is contained in:
@@ -100,54 +100,57 @@ describe Spree::ProductSet do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when :master_attributes is passed' do
|
||||
context 'when attributes of the variants are passed' do
|
||||
let!(:product) { create(:simple_product) }
|
||||
let(:collection_hash) { { 0 => { id: product.id } } }
|
||||
let(:master_attributes) { { sku: '123' } }
|
||||
|
||||
before do
|
||||
collection_hash[0][:master_attributes] = master_attributes
|
||||
end
|
||||
context 'when :master_attributes is passed' do
|
||||
let(:master_attributes) { { sku: '123' } }
|
||||
|
||||
context 'and the variant does exist' do
|
||||
let!(:variant) { create(:variant, product: product) }
|
||||
|
||||
before { master_attributes[:id] = variant.id }
|
||||
|
||||
it 'updates the attributes of the master variant' do
|
||||
product_set.save
|
||||
expect(variant.reload.sku).to eq('123')
|
||||
before do
|
||||
collection_hash[0][:master_attributes] = master_attributes
|
||||
end
|
||||
end
|
||||
|
||||
context 'and the variant does not exist' do
|
||||
context 'and attributes provided are valid' do
|
||||
let(:master_attributes) do
|
||||
attributes_for(:variant).merge(sku: '123')
|
||||
end
|
||||
context 'and the variant does exist' do
|
||||
let!(:variant) { create(:variant, product: product) }
|
||||
|
||||
it 'creates it with the specified attributes' do
|
||||
number_of_variants = Spree::Variant.all.size
|
||||
before { master_attributes[:id] = variant.id }
|
||||
|
||||
it 'updates the attributes of the master variant' do
|
||||
product_set.save
|
||||
expect(Spree::Variant.last.sku).to eq('123')
|
||||
expect(Spree::Variant.all.size).to eq number_of_variants + 1
|
||||
expect(variant.reload.sku).to eq('123')
|
||||
end
|
||||
end
|
||||
|
||||
context 'and attributes provided are not valid' do
|
||||
let(:master_attributes) do
|
||||
# unit_value nil makes the variant invalid
|
||||
# on_hand with a value would make on_hand be updated and fail with exception
|
||||
attributes_for(:variant).merge(unit_value: nil, on_hand: 1, sku: '321')
|
||||
context 'and the variant does not exist' do
|
||||
context 'and attributes provided are valid' do
|
||||
let(:master_attributes) do
|
||||
attributes_for(:variant).merge(sku: '123')
|
||||
end
|
||||
|
||||
it 'creates it with the specified attributes' do
|
||||
number_of_variants = Spree::Variant.all.size
|
||||
product_set.save
|
||||
expect(Spree::Variant.last.sku).to eq('123')
|
||||
expect(Spree::Variant.all.size).to eq number_of_variants + 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not create variant and notifies bugsnag still raising the exception' do
|
||||
expect(Bugsnag).to receive(:notify)
|
||||
number_of_variants = Spree::Variant.all.size
|
||||
expect { product_set.save }
|
||||
.to raise_error(StandardError)
|
||||
expect(Spree::Variant.all.size).to eq number_of_variants
|
||||
expect(Spree::Variant.last.sku).not_to eq('321')
|
||||
context 'and attributes provided are not valid' do
|
||||
let(:master_attributes) do
|
||||
# unit_value nil makes the variant invalid
|
||||
# on_hand with a value would make on_hand be updated and fail with exception
|
||||
attributes_for(:variant).merge(unit_value: nil, on_hand: 1, sku: '321')
|
||||
end
|
||||
|
||||
it 'does not create variant and notifies bugsnag still raising the exception' do
|
||||
expect(Bugsnag).to receive(:notify)
|
||||
number_of_variants = Spree::Variant.all.size
|
||||
expect { product_set.save }
|
||||
.to raise_error(StandardError)
|
||||
expect(Spree::Variant.all.size).to eq number_of_variants
|
||||
expect(Spree::Variant.last.sku).not_to eq('321')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user