Add product_and_variant_name display for Variant

This commit is contained in:
Rohan Mitchell
2015-09-21 16:49:31 +10:00
parent 8f40702369
commit 7552776349
2 changed files with 39 additions and 0 deletions

View File

@@ -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

View File

@@ -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)