diff --git a/app/models/purchase.rb b/app/models/purchase.rb index 4cfa2bb0fd..3b8a25e087 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -69,6 +69,10 @@ def purchased_from_view vendor.nil? ? purchased_from : vendor.business_name end + def comment_view + comment.nil? ? "" : comment + end + # @return [Integer] def amount_spent_in_dollars amount_spent.dollars.to_f diff --git a/spec/models/purchase_spec.rb b/spec/models/purchase_spec.rb index abd0ae7d69..9503ab4bad 100644 --- a/spec/models/purchase_spec.rb +++ b/spec/models/purchase_spec.rb @@ -156,6 +156,21 @@ expect(purchase.storage_view).to eq("Smithsonian Conservation Center") end end + + describe "comment_view" do + context "when comment is nil" do + let!(:purchase) { create(:purchase, :with_items, comment: nil) } + it "returns empty string" do + expect(purchase.comment_view).to eq("") + end + end + context "when comment is present" do + let!(:purchase) { create(:purchase, :with_items, comment: "This is a comment") } + it "returns comment" do + expect(purchase.comment_view).to eq("This is a comment") + end + end + end end describe "versioning" do