mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Merge pull request #6066 from arku/perf/variant-override-specs
Replace `create` with `build_stubbed` in variant override model specs
This commit is contained in:
@@ -54,7 +54,7 @@ describe VariantOverride do
|
||||
let(:count_on_hand) { nil }
|
||||
|
||||
it "is valid" do
|
||||
expect(variant_override.save).to be_truthy
|
||||
expect(variant_override).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@ describe VariantOverride do
|
||||
let(:count_on_hand) { nil }
|
||||
|
||||
it "is valid" do
|
||||
expect(variant_override.save).to be_truthy
|
||||
expect(variant_override).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,7 +85,7 @@ describe VariantOverride do
|
||||
let(:count_on_hand) { 1 }
|
||||
|
||||
it "is invalid" do
|
||||
expect(variant_override.save).to be_falsey
|
||||
expect(variant_override).not_to be_valid
|
||||
error_message = I18n.t("on_demand_but_count_on_hand_set",
|
||||
scope: [i18n_scope_for_error, "count_on_hand"])
|
||||
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
|
||||
@@ -100,7 +100,7 @@ describe VariantOverride do
|
||||
let(:count_on_hand) { nil }
|
||||
|
||||
it "is invalid" do
|
||||
expect(variant_override.save).to be_falsey
|
||||
expect(variant_override).not_to be_valid
|
||||
error_message = I18n.t("limited_stock_but_no_count_on_hand",
|
||||
scope: [i18n_scope_for_error, "count_on_hand"])
|
||||
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
|
||||
@@ -111,7 +111,7 @@ describe VariantOverride do
|
||||
let(:count_on_hand) { 1 }
|
||||
|
||||
it "is valid" do
|
||||
expect(variant_override.save).to be_truthy
|
||||
expect(variant_override).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -139,7 +139,7 @@ describe VariantOverride do
|
||||
end
|
||||
|
||||
describe "with price" do
|
||||
let(:variant_override) { create(:variant_override, variant: variant, hub: hub, price: 12.34) }
|
||||
let(:variant_override) { build_stubbed(:variant_override, variant: variant, hub: hub, price: 12.34) }
|
||||
|
||||
it "returns the numeric price" do
|
||||
expect(variant_override.price).to eq(12.34)
|
||||
@@ -147,7 +147,7 @@ describe VariantOverride do
|
||||
end
|
||||
|
||||
describe "with nil count on hand" do
|
||||
let(:variant_override) { create(:variant_override, variant: variant, hub: hub, count_on_hand: nil, on_demand: true) }
|
||||
let(:variant_override) { build_stubbed(:variant_override, variant: variant, hub: hub, count_on_hand: nil, on_demand: true) }
|
||||
|
||||
describe "stock_overridden?" do
|
||||
it "returns false" do
|
||||
@@ -196,12 +196,12 @@ describe VariantOverride do
|
||||
|
||||
describe "checking default stock value is present" do
|
||||
it "returns true when a default stock level has been set" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20)
|
||||
vo = build_stubbed(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20)
|
||||
expect(vo.default_stock?).to be true
|
||||
end
|
||||
|
||||
it "returns false when the override has no default stock level" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: nil)
|
||||
vo = build_stubbed(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: nil)
|
||||
expect(vo.default_stock?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user