mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
26 lines
794 B
Ruby
26 lines
794 B
Ruby
shared_examples "a model using the LocalizedNumber module" do |attributes|
|
|
before do
|
|
Spree::Config[:enable_localized_number?] = true
|
|
end
|
|
|
|
after do
|
|
Spree::Config[:enable_localized_number?] = false
|
|
end
|
|
|
|
attributes.each do |attribute|
|
|
setter = "#{attribute}="
|
|
|
|
it "uses the LocalizedNumber.parse method when setting #{attribute}" do
|
|
allow(Spree::LocalizedNumber).to receive(:parse).and_return(nil)
|
|
expect(Spree::LocalizedNumber).to receive(:parse).with('1.599,99')
|
|
subject.send(setter, '1.599,99')
|
|
end
|
|
|
|
it "creates an error if the input to #{attribute} is invalid" do
|
|
subject.send(setter, '1.59,99')
|
|
subject.valid?
|
|
expect(subject.errors[attribute]).to include(I18n.t('spree.localized_number.invalid_format'))
|
|
end
|
|
end
|
|
end
|