mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
fix existing tests
This commit is contained in:
@@ -46,7 +46,7 @@ class WeightsAndMeasures
|
||||
}.freeze
|
||||
|
||||
def scales_for_variant_unit
|
||||
@scales_for_variant_unit ||= @units[@variant.product.variant_unit].reject { |_scale, unit_info|
|
||||
@scales_for_variant_unit ||= @units[@variant.product.variant_unit]&.reject { |_scale, unit_info|
|
||||
available_units.exclude?(unit_info['name'])
|
||||
}
|
||||
end
|
||||
|
||||
@@ -695,6 +695,13 @@ module Spree
|
||||
let(:p2) { create(:product, name: 'Clear United States Honey', variant_unit_scale: 453.6) }
|
||||
let(:v2) { create(:variant, product: p2, unit_value: 453.6) }
|
||||
let(:li2) { create(:line_item, order: o, product: p2, variant: v2) }
|
||||
let(:available_units) {
|
||||
["mg", "g", "kg", "T", "oz", "lb", "mL", "cL", "dL", "L", "kL", "gal"].join(",")
|
||||
}
|
||||
|
||||
before do
|
||||
Spree::Config.set_preference(:available_units, available_units)
|
||||
end
|
||||
|
||||
it "returns options_text" do
|
||||
li = build_stubbed(:line_item)
|
||||
|
||||
@@ -6,9 +6,13 @@ describe UnitPrice do
|
||||
subject { UnitPrice.new(variant) }
|
||||
let(:variant) { Spree::Variant.new }
|
||||
let(:product) { instance_double(Spree::Product) }
|
||||
let(:available_units) {
|
||||
["mg", "g", "kg", "T", "oz", "lb", "mL", "cL", "dL", "L", "kL", "gal"].join(",")
|
||||
}
|
||||
|
||||
before do
|
||||
allow(variant).to receive(:product) { product }
|
||||
Spree::Config.set_preference(:available_units, available_units)
|
||||
end
|
||||
|
||||
describe "#unit" do
|
||||
|
||||
@@ -4,6 +4,13 @@ require 'spec_helper'
|
||||
|
||||
module VariantUnits
|
||||
describe OptionValueNamer do
|
||||
let(:available_units) {
|
||||
["mg", "g", "kg", "T", "oz", "lb", "mL", "cL", "dL", "L", "kL", "gal"].join(",")
|
||||
}
|
||||
|
||||
before do
|
||||
Spree::Config.set_preference(:available_units, available_units)
|
||||
end
|
||||
describe "generating option value name" do
|
||||
let(:v) { Spree::Variant.new }
|
||||
let(:p) { Spree::Product.new }
|
||||
|
||||
@@ -6,9 +6,13 @@ describe WeightsAndMeasures do
|
||||
subject { WeightsAndMeasures.new(variant) }
|
||||
let(:variant) { Spree::Variant.new }
|
||||
let(:product) { instance_double(Spree::Product) }
|
||||
let(:available_units) {
|
||||
["mg", "g", "kg", "T", "oz", "lb", "mL", "cL", "dL", "L", "kL", "gal"].join(",")
|
||||
}
|
||||
|
||||
before do
|
||||
allow(variant).to receive(:product) { product }
|
||||
Spree::Config.set_preference(:available_units, available_units)
|
||||
end
|
||||
|
||||
describe "#system" do
|
||||
@@ -69,16 +73,43 @@ describe WeightsAndMeasures do
|
||||
allow(variant).to receive(:unit_value) { 1500 }
|
||||
expect(subject.scale_for_unit_value).to eq([1000.0, "kg"])
|
||||
end
|
||||
|
||||
describe "should not display in kg if this unit is not selected" do
|
||||
let(:available_units) { ["mg", "g", "T"].join(",") }
|
||||
|
||||
it "should display in g" do
|
||||
allow(product).to receive(:variant_unit_scale) { 1.0 }
|
||||
allow(variant).to receive(:unit_value) { 1500 }
|
||||
expect(subject.scale_for_unit_value).to eq([1.0, "g"])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "volume" do
|
||||
it "for a unit value that should display in L" do
|
||||
it "for a unit value that should display in kL" do
|
||||
allow(product).to receive(:variant_unit) { "volume" }
|
||||
allow(product).to receive(:variant_unit_scale) { 1.0 }
|
||||
allow(variant).to receive(:unit_value) { 1500 }
|
||||
expect(subject.scale_for_unit_value).to eq([1000, "kL"])
|
||||
end
|
||||
|
||||
it "for a unit value that should display in dL" do
|
||||
allow(product).to receive(:variant_unit) { "volume" }
|
||||
allow(product).to receive(:variant_unit_scale) { 1.0 }
|
||||
allow(variant).to receive(:unit_value) { 0.5 }
|
||||
expect(subject.scale_for_unit_value).to eq([0.1, "dL"])
|
||||
end
|
||||
|
||||
context "should not display in dL/cL if those units are not selected" do
|
||||
let(:available_units){ ["mL", "L", "kL", "gal"].join(",") }
|
||||
it "for a unit value that should display in mL" do
|
||||
allow(product).to receive(:variant_unit) { "volume" }
|
||||
allow(product).to receive(:variant_unit_scale) { 1.0 }
|
||||
allow(variant).to receive(:unit_value) { 0.5 }
|
||||
expect(subject.scale_for_unit_value).to eq([0.001, "mL"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "items" do
|
||||
|
||||
@@ -53,6 +53,14 @@ describe "Product Import" do
|
||||
|
||||
let(:shipping_category_id_str) { Spree::ShippingCategory.all.first.id.to_s }
|
||||
|
||||
let(:available_units) {
|
||||
["mg", "g", "kg", "T", "oz", "lb", "mL", "cL", "dL", "L", "kL", "gal"].join(",")
|
||||
}
|
||||
|
||||
before do
|
||||
Spree::Config.set_preference(:available_units, available_units)
|
||||
end
|
||||
|
||||
describe "when importing products from uploaded file" do
|
||||
before do
|
||||
allow(Spree::Config).to receive(:available_units).and_return("g,lb,oz,kg,T,mL,L,kL")
|
||||
|
||||
Reference in New Issue
Block a user