mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-21 05:09:15 +00:00
Avoid unnecessary save
Actually, the variant factory is still adding an extra save. We should refactor Variant to avoid that.. but the afternoon slump has got me.
This commit is contained in:
@@ -282,8 +282,8 @@ module Spree
|
||||
|
||||
dup.tap do |variant|
|
||||
variant.price = price
|
||||
variant.save!
|
||||
variant.source_variants = [self]
|
||||
variant.stock_items << Spree::StockItem.new(variant:)
|
||||
variant.owner_id = owner_id
|
||||
variant.on_demand = on_demand
|
||||
variant.on_hand = on_hand
|
||||
|
||||
@@ -1018,13 +1018,9 @@ RSpec.describe Spree::Variant do
|
||||
child: enterprise,
|
||||
permissions_list: [:create_sourced_variants])
|
||||
}
|
||||
let(:variant) { create(:variant, price: 10.95, on_demand: false, on_hand: 5) }
|
||||
|
||||
it "clones the variant, retaining a link to the source" do
|
||||
variant.price = 10.95
|
||||
variant.save!
|
||||
variant.on_demand = false
|
||||
variant.on_hand = 5
|
||||
|
||||
sourced_variant = variant.create_sourced_variant(user)
|
||||
|
||||
expect(sourced_variant.source_variants).to eq [variant]
|
||||
|
||||
Reference in New Issue
Block a user