Files
openfoodnetwork/engines/dfc_provider/spec/services/offer_builder_spec.rb
Maikel Linke 191c4a79db Load spec helpers before Rails is loaded
Using Spring was hiding an loading error. When you start Rspec, Rails
and its engines are not loaded yet. So our way to load the spec helper
via `Rails.root` did not work when you ran specs on their own without
loading Rails with Spring first.
2023-09-11 14:57:38 +10:00

31 lines
676 B
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
describe DfcBuilder do
let(:variant) { build(:variant) }
describe ".offer" do
it "assigns a stock level" do
# Assigning stock only works with persisted records:
variant.save!
variant.on_hand = 5
offer = DfcBuilder.offer(variant)
expect(offer.stockLimitation).to eq 5
end
it "has no stock limitation when on demand" do
# Assigning stock only works with persisted records:
variant.save!
variant.on_hand = 5
variant.on_demand = true
offer = DfcBuilder.offer(variant)
expect(offer.stockLimitation).to eq nil
end
end
end