mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
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.
31 lines
676 B
Ruby
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
|