Skip to content

Commit

Permalink
chore(model/purchase): add comment_view
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhwmn committed Sep 7, 2024
1 parent 5217bce commit 4f96571
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/models/purchase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f96571

Please sign in to comment.