diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 3ed87159a7..5ac89c1430 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -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 diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 77e50af4a8..69dda85ff5 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -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)