mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add product_and_variant_name display for Variant
This commit is contained in:
@@ -100,6 +100,14 @@ Spree::Variant.class_eval do
|
||||
display_as
|
||||
end
|
||||
|
||||
def product_and_variant_name
|
||||
name = product.name
|
||||
|
||||
name += " - #{name_to_display}" if name_to_display != product.name
|
||||
name += " (#{options_text})" if options_text
|
||||
|
||||
name
|
||||
end
|
||||
|
||||
def update_units
|
||||
delete_unit_option_values
|
||||
|
||||
@@ -153,6 +153,37 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
describe "generating the product and variant name" do
|
||||
let(:v) { Variant.new }
|
||||
let(:p) { double(:product, name: 'product') }
|
||||
|
||||
before do
|
||||
v.stub(:product) { p }
|
||||
v.stub(:name_to_display) { p.name }
|
||||
v.stub(:options_text) { nil }
|
||||
end
|
||||
|
||||
it "returns the product name only when there's no extra info" do
|
||||
v.product_and_variant_name.should == 'product'
|
||||
end
|
||||
|
||||
it "also shows the name to display when different to the product name" do
|
||||
v.stub(:name_to_display) { 'NTD' }
|
||||
v.product_and_variant_name.should == 'product - NTD'
|
||||
end
|
||||
|
||||
it "shows the options text when present" do
|
||||
v.stub(:options_text) { 'OT' }
|
||||
v.product_and_variant_name.should == 'product (OT)'
|
||||
end
|
||||
|
||||
it "displays all attributes" do
|
||||
v.stub(:name_to_display) { 'NTD' }
|
||||
v.stub(:options_text) { 'OT' }
|
||||
v.product_and_variant_name.should == 'product - NTD (OT)'
|
||||
end
|
||||
end
|
||||
|
||||
describe "calculating the price with enterprise fees" do
|
||||
it "returns the price plus the fees" do
|
||||
distributor = double(:distributor)
|
||||
|
||||
Reference in New Issue
Block a user