mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
Spree::Price parsing was returning 0.0 when given a an empty string as price, resulting in a variant being valid even if no price was given. It only happened if `Spree::LocalizedNumber` wasn't used. Spree::LocalizedNumber` return nil if given a blank number.
59 lines
1.2 KiB
Ruby
59 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
module Spree
|
|
RSpec.describe Price do
|
|
let(:variant) { create(:variant) }
|
|
let(:price) { variant.default_price }
|
|
|
|
context "when variant is soft-deleted" do
|
|
before do
|
|
variant.destroy
|
|
end
|
|
|
|
it "can access the variant" do
|
|
expect(price.reload.variant).to eq variant
|
|
end
|
|
end
|
|
|
|
context "with large values" do
|
|
let(:expensive_variant) { build(:variant, price: 10_000_000) }
|
|
|
|
it "saves without error" do
|
|
expect{ expensive_variant.save }.not_to raise_error
|
|
expect(expensive_variant.persisted?).to be true
|
|
end
|
|
end
|
|
|
|
context "with string" do
|
|
it "parses the price" do
|
|
variant.price = " 10.25 eur"
|
|
variant.save
|
|
|
|
expect(variant.reload.price).to eq 10.25
|
|
end
|
|
end
|
|
|
|
describe "#price=" do
|
|
subject { Spree::Price.new }
|
|
|
|
context "with a number" do
|
|
it "returns the same number" do
|
|
subject.price = 12.5
|
|
|
|
expect(subject.price).to eq(12.5)
|
|
end
|
|
end
|
|
|
|
context "with empty string" do
|
|
it "sets the price to nil" do
|
|
subject.price = ""
|
|
|
|
expect(subject.price).to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|