mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Display variant price differences as absolute, not relative values
This commit is contained in:
9
app/helpers/spree/products_helper_decorator.rb
Normal file
9
app/helpers/spree/products_helper_decorator.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module Spree
|
||||
ProductsHelper.class_eval do
|
||||
# Return the price of the variant, or nil if it is identical to the master price
|
||||
def variant_price_diff(variant)
|
||||
return nil if variant.price == variant.product.price
|
||||
"(#{number_to_currency variant.price})"
|
||||
end
|
||||
end
|
||||
end
|
||||
35
spec/helpers/products_helper_spec.rb
Normal file
35
spec/helpers/products_helper_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe ProductsHelper do
|
||||
subject do
|
||||
obj = Object.new
|
||||
obj.extend(ProductsHelper)
|
||||
obj.extend(ActionView::Helpers::NumberHelper)
|
||||
end
|
||||
|
||||
|
||||
it "displays variant price differences as absolute, not relative values" do
|
||||
variant = make_variant_stub(10.00, 10.00)
|
||||
subject.variant_price_diff(variant).should be_nil
|
||||
|
||||
variant = make_variant_stub(10.00, 15.55)
|
||||
subject.variant_price_diff(variant).should == "($15.55)"
|
||||
|
||||
variant = make_variant_stub(10.00, 5.55)
|
||||
subject.variant_price_diff(variant).should == "($5.55)"
|
||||
end
|
||||
|
||||
private
|
||||
def make_variant_stub(product_price, variant_price)
|
||||
product = stub(:product)
|
||||
product.stub(:price).and_return(product_price)
|
||||
|
||||
variant = stub(:variant)
|
||||
variant.stub(:product).and_return(product)
|
||||
variant.stub(:price).and_return(variant_price)
|
||||
|
||||
variant
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user