From 1cffd359689b81d9bc70724788981caa6449da2a Mon Sep 17 00:00:00 2001 From: Rob H Date: Sun, 29 Nov 2015 17:52:01 +1100 Subject: [PATCH] Fixing up specs pertaining to full_name generation for line_items --- spec/models/spree/line_item_spec.rb | 44 ++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index fd2729b2db..c9063ea0f6 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -196,12 +196,48 @@ module Spree describe "generating the full name" do let(:li) { LineItem.new } - before do - li.stub(:unit_to_display) { 'unit_to_display' } + context "when display_name is blank" do + before do + li.stub(:unit_to_display) { 'unit_to_display' } + li.stub(:display_name) { '' } + end + + it "returns unit_to_display" do + li.full_name.should == 'unit_to_display' + end end - it "returns unit_to_display" do - li.full_name.should == 'unit_to_display' + context "when unit_to_display contains display_name" do + before do + li.stub(:unit_to_display) { '1kg Jar' } + li.stub(:display_name) { '1kg' } + end + + it "returns unit_to_display" do + li.full_name.should == '1kg Jar' + end + end + + context "when display_name contains unit_to_display" do + before do + li.stub(:unit_to_display) { '10kg' } + li.stub(:display_name) { '10kg Box' } + end + + it "returns display_name" do + li.full_name.should == '10kg Box' + end + end + + context "otherwise" do + before do + li.stub(:unit_to_display) { 'Spelt Sourghdough' } + li.stub(:display_name) { '1 Loaf' } + end + + it "returns unit_to_display" do + li.full_name.should == 'Spelt Sourdough (1 Loaf)' + end end end