From fa337fcd6ea0c3bfcdc60ca910602bdd5e1fa901 Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 10 Jul 2014 17:04:35 +1000 Subject: [PATCH] Prevent display_as and display_name from being used when blank --- app/models/spree/variant_decorator.rb | 6 ++++-- spec/models/spree/variant_spec.rb | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 81977bc05a..12593215ba 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -51,11 +51,13 @@ Spree::Variant.class_eval do end def name_to_display - display_name || product.name + return product.name if display_name.blank? + display_name end def unit_to_display - display_as || options_text + return options_text if display_as.blank? + display_as end diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index bf13cf978c..0abf9ea431 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -133,6 +133,8 @@ module Spree it "returns product name if display_name is empty" do v = create(:variant, product: create(:product)) v.name_to_display.should == v.product.name + v1 = create(:variant, display_name: "", product: create(:product)) + v1.name_to_display.should == v1.product.name end end @@ -142,10 +144,13 @@ module Spree v.unit_to_display.should == "foo" end - it "returns options_text if display_as is empty" do + it "returns options_text if display_as is blank" do v = create(:variant) + v1 = create(:variant, display_as: "") v.stub(:options_text).and_return "ponies" + v1.stub(:options_text).and_return "ponies" v.unit_to_display.should == "ponies" + v1.unit_to_display.should == "ponies" end end