mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Add VariantOverride.stock_overriden?
This commit is contained in:
@@ -16,6 +16,10 @@ class VariantOverride < ActiveRecord::Base
|
||||
self.for(hub, variant).andand.count_on_hand
|
||||
end
|
||||
|
||||
def self.stock_overridden?(hub, variant)
|
||||
count_on_hand_for(hub, variant).present?
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -40,4 +40,23 @@ describe VariantOverride do
|
||||
VariantOverride.count_on_hand_for(hub, variant).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "checking if stock levels have been overriden" do
|
||||
let(:variant) { create(:variant) }
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
|
||||
it "returns true when stock level has been overridden" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12)
|
||||
VariantOverride.stock_overridden?(hub, variant).should be_true
|
||||
end
|
||||
|
||||
it "returns false when the override has no stock level" do
|
||||
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: nil)
|
||||
VariantOverride.stock_overridden?(hub, variant).should be_false
|
||||
end
|
||||
|
||||
it "returns false when there is no override for the hub/variant" do
|
||||
VariantOverride.stock_overridden?(hub, variant).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user