mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Merge branch 'master' into docker_scripts
This commit is contained in:
@@ -5,7 +5,12 @@ require 'spec_helper'
|
||||
module OrderManagement
|
||||
module Stock
|
||||
describe Coordinator do
|
||||
let!(:order) { create(:order_with_line_items, distributor: create(:distributor_enterprise)) }
|
||||
let!(:order) do
|
||||
build_stubbed(
|
||||
:order_with_line_items,
|
||||
distributor: build_stubbed(:distributor_enterprise)
|
||||
)
|
||||
end
|
||||
|
||||
subject { Coordinator.new(order) }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'spec_helper'
|
||||
|
||||
describe Calculator::FlatPercentItemTotal do
|
||||
let(:calculator) { Calculator::FlatPercentItemTotal.new }
|
||||
let(:line_item) { build(:line_item, price: 10, quantity: 1) }
|
||||
let(:line_item) { build_stubbed(:line_item, price: 10, quantity: 1) }
|
||||
|
||||
before { allow(calculator).to receive_messages preferred_flat_percent: 10 }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Calculator::FlexiRate do
|
||||
let(:line_item) { build(:line_item, quantity: quantity) }
|
||||
let(:line_item) { build_stubbed(:line_item, quantity: quantity) }
|
||||
let(:calculator) do
|
||||
Calculator::FlexiRate.new(
|
||||
preferred_first_item: 2,
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
describe Calculator::PerItem do
|
||||
let(:calculator) { Calculator::PerItem.new(preferred_amount: 10) }
|
||||
let(:shipping_calculable) { double(:calculable) }
|
||||
let(:line_item) { build(:line_item, quantity: 5) }
|
||||
let(:line_item) { build_stubbed(:line_item, quantity: 5) }
|
||||
|
||||
it "correctly calculates on a single line item object" do
|
||||
allow(calculator).to receive_messages(calculable: shipping_calculable)
|
||||
|
||||
@@ -8,7 +8,7 @@ describe Calculator::PriceSack do
|
||||
calculator.preferred_discount_amount = 1
|
||||
calculator
|
||||
end
|
||||
let(:line_item) { build(:line_item, price: price, quantity: 2) }
|
||||
let(:line_item) { build_stubbed(:line_item, price: price, quantity: 2) }
|
||||
|
||||
context 'when the order amount is below preferred minimal' do
|
||||
let(:price) { 2 }
|
||||
|
||||
@@ -4,13 +4,13 @@ describe Calculator::Weight do
|
||||
it_behaves_like "a model using the LocalizedNumber module", [:preferred_per_kg]
|
||||
|
||||
it "computes shipping cost for an order by total weight" do
|
||||
variant1 = build(:variant, unit_value: 10_000)
|
||||
variant2 = build(:variant, unit_value: 20_000)
|
||||
variant3 = build(:variant, unit_value: nil)
|
||||
variant1 = build_stubbed(:variant, unit_value: 10_000)
|
||||
variant2 = build_stubbed(:variant, unit_value: 20_000)
|
||||
variant3 = build_stubbed(:variant, unit_value: nil)
|
||||
|
||||
line_item1 = build(:line_item, variant: variant1, quantity: 1)
|
||||
line_item2 = build(:line_item, variant: variant2, quantity: 3)
|
||||
line_item3 = build(:line_item, variant: variant3, quantity: 5)
|
||||
line_item1 = build_stubbed(:line_item, variant: variant1, quantity: 1)
|
||||
line_item2 = build_stubbed(:line_item, variant: variant2, quantity: 3)
|
||||
line_item3 = build_stubbed(:line_item, variant: variant3, quantity: 5)
|
||||
|
||||
order = double(:order, line_items: [line_item1, line_item2, line_item3])
|
||||
|
||||
@@ -19,8 +19,8 @@ describe Calculator::Weight do
|
||||
end
|
||||
|
||||
describe "line item with variant_unit weight and variant unit_value" do
|
||||
let(:variant) { create(:variant, unit_value: 10_000) }
|
||||
let(:line_item) { create(:line_item, variant: variant, quantity: 2) }
|
||||
let(:variant) { build_stubbed(:variant, unit_value: 10_000) }
|
||||
let(:line_item) { build_stubbed(:line_item, variant: variant, quantity: 2) }
|
||||
|
||||
before { subject.set_preference(:per_kg, 5) }
|
||||
|
||||
@@ -29,7 +29,9 @@ describe Calculator::Weight do
|
||||
end
|
||||
|
||||
describe "and with final_weight_volume defined" do
|
||||
before { line_item.update_attribute :final_weight_volume, '18000' }
|
||||
before do
|
||||
line_item.final_weight_volume = '18000'
|
||||
end
|
||||
|
||||
it "computes fee using final_weight_volume, not the variant weight" do
|
||||
expect(subject.compute(line_item)).to eq(90) # 18 * 5
|
||||
@@ -37,8 +39,8 @@ describe Calculator::Weight do
|
||||
|
||||
context "where variant unit is not weight" do
|
||||
it "uses both final_weight_volume and weight to calculate fee" do
|
||||
line_item.variant.update_attribute :weight, 7
|
||||
line_item.variant.product.update_attribute :variant_unit, 'items'
|
||||
line_item.variant.weight = 7
|
||||
line_item.variant.product.variant_unit = 'items'
|
||||
expect(subject.compute(line_item)).to eq(63) # 7 * (18000/10000) * 5
|
||||
end
|
||||
end
|
||||
@@ -46,11 +48,11 @@ describe Calculator::Weight do
|
||||
end
|
||||
|
||||
it "computes shipping cost for an object with an order" do
|
||||
variant1 = create(:variant, unit_value: 10_000)
|
||||
variant2 = create(:variant, unit_value: 20_000)
|
||||
variant1 = build_stubbed(:variant, unit_value: 10_000)
|
||||
variant2 = build_stubbed(:variant, unit_value: 20_000)
|
||||
|
||||
line_item1 = create(:line_item, variant: variant1, quantity: 1)
|
||||
line_item2 = create(:line_item, variant: variant2, quantity: 2)
|
||||
line_item1 = build_stubbed(:line_item, variant: variant1, quantity: 1)
|
||||
line_item2 = build_stubbed(:line_item, variant: variant2, quantity: 2)
|
||||
|
||||
order = double(:order, line_items: [line_item1, line_item2])
|
||||
object_with_order = double(:object_with_order, order: order)
|
||||
@@ -60,12 +62,12 @@ describe Calculator::Weight do
|
||||
end
|
||||
|
||||
context "when line item final_weight_volume is set" do
|
||||
let!(:product) { create(:product, product_attributes) }
|
||||
let!(:variant) { create(:variant, variant_attributes.merge(product: product)) }
|
||||
let!(:product) { build_stubbed(:product, product_attributes) }
|
||||
let!(:variant) { build_stubbed(:variant, variant_attributes.merge(product: product)) }
|
||||
|
||||
let(:calculator) { described_class.new(preferred_per_kg: 6) }
|
||||
let(:line_item) do
|
||||
create(:line_item, variant: variant, quantity: 2).tap do |object|
|
||||
build_stubbed(:line_item, variant: variant, quantity: 2).tap do |object|
|
||||
object.send(:calculate_final_weight_volume)
|
||||
end
|
||||
end
|
||||
@@ -176,14 +178,14 @@ describe Calculator::Weight do
|
||||
|
||||
context "when variant_unit is 'items'" do
|
||||
let(:product) {
|
||||
create(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: "bunch")
|
||||
build_stubbed(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: "bunch")
|
||||
}
|
||||
let(:line_item) { create(:line_item, variant: variant, quantity: 1) }
|
||||
let(:line_item) { build_stubbed(:line_item, variant: variant, quantity: 1) }
|
||||
|
||||
before { subject.set_preference(:per_kg, 5) }
|
||||
|
||||
context "when unit_value is zero variant.weight is present" do
|
||||
let(:variant) { create(:variant, product: product, unit_value: 0, weight: 10.0) }
|
||||
let(:variant) { build_stubbed(:variant, product: product, unit_value: 0, weight: 10.0) }
|
||||
|
||||
it "uses the variant weight" do
|
||||
expect(subject.compute(line_item)).to eq 50.0
|
||||
@@ -191,7 +193,7 @@ describe Calculator::Weight do
|
||||
end
|
||||
|
||||
context "when unit_value is zero variant.weight is nil" do
|
||||
let(:variant) { create(:variant, product: product, unit_value: 0, weight: nil) }
|
||||
let(:variant) { build_stubbed(:variant, product: product, unit_value: 0, weight: nil) }
|
||||
|
||||
it "uses zero weight" do
|
||||
expect(subject.compute(line_item)).to eq 0
|
||||
@@ -200,7 +202,7 @@ describe Calculator::Weight do
|
||||
|
||||
context "when unit_value is nil and variant.weight is present" do
|
||||
let(:variant) {
|
||||
create(:variant, product: product, unit_description: "bunches", unit_value: nil, weight: 10.0)
|
||||
build_stubbed(:variant, product: product, unit_description: "bunches", unit_value: nil, weight: 10.0)
|
||||
}
|
||||
|
||||
it "uses the variant weight" do
|
||||
@@ -212,7 +214,7 @@ describe Calculator::Weight do
|
||||
|
||||
context "when unit_value is nil and variant.weight is nil" do
|
||||
let(:variant) {
|
||||
create(:variant, product: product, unit_description: "bunches", unit_value: nil, weight: nil)
|
||||
build_stubbed(:variant, product: product, unit_description: "bunches", unit_value: nil, weight: nil)
|
||||
}
|
||||
|
||||
it "uses zero weight" do
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'spec_helper'
|
||||
|
||||
describe Spree::ShippingRate do
|
||||
let(:shipment) { create(:shipment) }
|
||||
let(:shipping_method) { create(:shipping_method) }
|
||||
let(:shipping_method) { build_stubbed(:shipping_method) }
|
||||
let(:shipping_rate) {
|
||||
Spree::ShippingRate.new(shipment: shipment,
|
||||
shipping_method: shipping_method,
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagRule, type: :model do
|
||||
let!(:tag_rule) { create(:tag_rule) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires a enterprise" do
|
||||
expect(tag_rule).to validate_presence_of :enterprise
|
||||
expect(subject).to validate_presence_of(:enterprise)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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