Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4635: Comment is missing from purchase details #4642

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this deserves a full method of its own. You can replace with purchase.comment || ''.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes here 803a9dd


# @return [Integer]
def amount_spent_in_dollars
amount_spent.dollars.to_f
Expand Down
11 changes: 11 additions & 0 deletions app/views/purchases/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
<td><%= @purchase.storage_view %></td>
</tr>
</table>
<table class="table">
<thead>
<tr>
<th>Comment:</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= @purchase.comment_view %></td>
</tr>
</table>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix up the spacing here? Nested elements like tr and td should be indented more than the parent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed here 834f25f
I also fixed the indentation of the tr and td tags from the table above

</div>
</div>
</div>
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
15 changes: 14 additions & 1 deletion spec/requests/purchases_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,20 @@

describe "GET #show" do
let(:item) { create(:item) }
let!(:purchase) { create(:purchase, :with_items, item: item) }
let(:storage_location) { create(:storage_location, organization: organization, name: 'Some Storage') }
let(:vendor) { create(:vendor, organization: organization, business_name: 'Another Business') }
let!(:purchase) { create(:purchase, :with_items, item: item, storage_location: storage_location, comment: 'Fine day for diapers, it is.') }

it "shows the purchase info" do
escaped_html_comment = CGI.escapeHTML(purchase.comment_view)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know exactly what the comment is - please use that value in your expectation instead of referencing the purchaserecord.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes here 83ee754

date_of_purchase = "#{purchase.issued_at.to_fs(:distribution_date)} (entered: #{purchase.created_at.to_fs(:distribution_date)})"

get purchase_path(id: purchase.id)
expect(response.body).to include(date_of_purchase)
expect(response.body).to include(purchase.purchased_from_view)
expect(response.body).to include(purchase.storage_view)
expect(response.body).to include(escaped_html_comment)
end

it "shows an enabled edit button" do
get purchase_path(id: purchase.id)
Expand Down