Display variant price differences as absolute, not relative values

This commit is contained in:
Rohan Mitchell
2012-06-26 09:54:00 +10:00
parent 34b694666c
commit 3ad575cb5f
2 changed files with 44 additions and 0 deletions

View 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

View 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