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:
David Cook
2026-03-10 15:40:11 +11:00
parent 7e8b3694be
commit c165ade4ba
2 changed files with 2 additions and 6 deletions

View File

@@ -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

View File

@@ -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]