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

Conversation

victorhwmn
Copy link
Contributor

Resolves 4635

Description

I added a new table containing the comment above the list of items on view/purchases/show.html.erb, keeping it in the same div as the other purchase information. I also added a new method in the Purchase model called comment_view to avoid potential issues with a nil comment.

I then created tests for both changes. In spec/requests/purchases_requests_spec.rb, I added storage_location and vendor to set the values of the parameters used in the test. I also needed to add the constant escaped_html_comment because response.body returns escaped HTML, while purchase.comment does not.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Follow the same steps described in the issue:

Sign in as [email protected]. Click on "Purchases", then "All Purchases" in the left hand menu.. Find a purchase that has a comment, and click "View" on it.

The comment should appear there

Also I use the rails console to set the Purchase's comment as nil and them repeated the same steps to verify if the page would handle a null comment without breaking
Purchase.find(PURCHASE_ID).update(comment: nil)

Screenshots

Before

image

After

With comment:
image

Without comment:
image

@victorhwmn victorhwmn force-pushed the 4635-show-comment-on-purchase-details branch from 91e02dc to 1731bfe Compare September 7, 2024 02:48
@victorhwmn victorhwmn marked this pull request as ready for review September 7, 2024 03:28
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Looks great from the functional pov! Asking @dorner to take a look for any technical comments.

@cielf cielf requested a review from dorner September 7, 2024 14:52
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Looking good, with some nitpicks.

@@ -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

<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

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

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

One last suggestion!

let!(:purchase) { create(:purchase, :with_items, comment: 'Fine day for diapers, it is.', created_at: 1.month.ago, issued_at: 1.day.ago, item: item, storage_location: storage_location, vendor: vendor) }

it "shows the purchase info" do
date_of_purchase = "#{1.day.ago.to_fs(:distribution_date)} (entered: #{1.month.ago.to_fs(:distribution_date)})"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you might have to use the freeze_time helper here, and use let instead of let! so that the correct dates get set. Otherwise you might get flakiness here with times being off by part of a second.

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 1364f82

@victorhwmn victorhwmn force-pushed the 4635-show-comment-on-purchase-details branch from b7cdc30 to a978b4b Compare September 14, 2024 19:16
@victorhwmn victorhwmn force-pushed the 4635-show-comment-on-purchase-details branch from a978b4b to 1364f82 Compare September 14, 2024 19:17
@dorner
Copy link
Collaborator

dorner commented Sep 16, 2024

All good here!

@dorner dorner merged commit d59c559 into rubyforgood:main Sep 16, 2024
12 checks passed
Aaryanpal pushed a commit to Aaryanpal/human-essentials that referenced this pull request Sep 19, 2024
* chore(model/purchase): add comment_view

* feat(view/purchases/show): show comment on purchase details

* chore(model/purchase): remove comment_view

* fix(purchases/show): indent html

* chore(purchases_requests_rspec): use expected value on test

* fix(purchases_requests_rspec): use freeze_time on show purchase info test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comment is missing from purchase details
3 participants