From 4f96571a112f6d3bb23058127ba38c7437f0f321 Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Fri, 6 Sep 2024 18:10:33 -0300 Subject: [PATCH 1/6] chore(model/purchase): add comment_view --- app/models/purchase.rb | 4 ++++ spec/models/purchase_spec.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+) 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 From 1731bfe1eefa06799f216ba0dd8438eaa1a1b0df Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Fri, 6 Sep 2024 18:12:33 -0300 Subject: [PATCH 2/6] feat(view/purchases/show): show comment on purchase details --- app/views/purchases/show.html.erb | 11 +++++++++++ spec/requests/purchases_requests_spec.rb | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/views/purchases/show.html.erb b/app/views/purchases/show.html.erb index d75fb18684..5ebaba86f3 100644 --- a/app/views/purchases/show.html.erb +++ b/app/views/purchases/show.html.erb @@ -43,6 +43,17 @@ <%= @purchase.storage_view %> + + + + + + + + + + +
Comment:
<%= @purchase.comment_view %>
diff --git a/spec/requests/purchases_requests_spec.rb b/spec/requests/purchases_requests_spec.rb index abf7f1342a..fc982295b0 100644 --- a/spec/requests/purchases_requests_spec.rb +++ b/spec/requests/purchases_requests_spec.rb @@ -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) + 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) From 803a9ddaa3e4637170f652b6bd7ee826cd7505f5 Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Thu, 12 Sep 2024 19:21:57 -0300 Subject: [PATCH 3/6] chore(model/purchase): remove comment_view --- app/models/purchase.rb | 4 ---- app/views/purchases/show.html.erb | 2 +- spec/models/purchase_spec.rb | 15 --------------- spec/requests/purchases_requests_spec.rb | 2 +- 4 files changed, 2 insertions(+), 21 deletions(-) diff --git a/app/models/purchase.rb b/app/models/purchase.rb index 3b8a25e087..4cfa2bb0fd 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -69,10 +69,6 @@ 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/app/views/purchases/show.html.erb b/app/views/purchases/show.html.erb index 5ebaba86f3..f00ca63070 100644 --- a/app/views/purchases/show.html.erb +++ b/app/views/purchases/show.html.erb @@ -51,7 +51,7 @@ - <%= @purchase.comment_view %> + <%= @purchase.comment || '' %> diff --git a/spec/models/purchase_spec.rb b/spec/models/purchase_spec.rb index 9503ab4bad..abd0ae7d69 100644 --- a/spec/models/purchase_spec.rb +++ b/spec/models/purchase_spec.rb @@ -156,21 +156,6 @@ 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 diff --git a/spec/requests/purchases_requests_spec.rb b/spec/requests/purchases_requests_spec.rb index fc982295b0..0d045e18d0 100644 --- a/spec/requests/purchases_requests_spec.rb +++ b/spec/requests/purchases_requests_spec.rb @@ -269,7 +269,7 @@ 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) + escaped_html_comment = CGI.escapeHTML(purchase.comment) date_of_purchase = "#{purchase.issued_at.to_fs(:distribution_date)} (entered: #{purchase.created_at.to_fs(:distribution_date)})" get purchase_path(id: purchase.id) From 834f25ff5aa7a5146ef5e7890e5726fd52c930d1 Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Thu, 12 Sep 2024 19:24:46 -0300 Subject: [PATCH 4/6] fix(purchases/show): indent html --- app/views/purchases/show.html.erb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/purchases/show.html.erb b/app/views/purchases/show.html.erb index f00ca63070..9969b9153c 100644 --- a/app/views/purchases/show.html.erb +++ b/app/views/purchases/show.html.erb @@ -30,24 +30,24 @@
- - - - - + + + + + - - - + + +
Date of Purchase:Vendor:Storage Location:
Date of Purchase:Vendor:Storage Location:
<%= @purchase.issued_at.to_fs(:distribution_date) %> (entered: <%= @purchase.created_at.to_fs(:distribution_date) %>)<%= @purchase.purchased_from_view %><%= @purchase.storage_view %><%= @purchase.issued_at.to_fs(:distribution_date) %> (entered: <%= @purchase.created_at.to_fs(:distribution_date) %>)<%= @purchase.purchased_from_view %><%= @purchase.storage_view %>
- - - + + + From 83ee754272535324c78998a8c4b6165c5ac2e986 Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Thu, 12 Sep 2024 19:37:45 -0300 Subject: [PATCH 5/6] chore(purchases_requests_rspec): use expected value on test --- spec/requests/purchases_requests_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/requests/purchases_requests_spec.rb b/spec/requests/purchases_requests_spec.rb index 0d045e18d0..41cc8847c2 100644 --- a/spec/requests/purchases_requests_spec.rb +++ b/spec/requests/purchases_requests_spec.rb @@ -266,17 +266,16 @@ let(:item) { create(: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.') } + 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 - escaped_html_comment = CGI.escapeHTML(purchase.comment) - date_of_purchase = "#{purchase.issued_at.to_fs(:distribution_date)} (entered: #{purchase.created_at.to_fs(:distribution_date)})" + date_of_purchase = "#{1.day.ago.to_fs(:distribution_date)} (entered: #{1.month.ago.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) + expect(response.body).to include('Another Business') + expect(response.body).to include('Some Storage') + expect(response.body).to include('Fine day for diapers, it is.') end it "shows an enabled edit button" do From 1364f821be5dada65f8384c3aba9c13d580f680d Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Sat, 14 Sep 2024 16:17:07 -0300 Subject: [PATCH 6/6] fix(purchases_requests_rspec): use freeze_time on show purchase info test --- spec/requests/purchases_requests_spec.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spec/requests/purchases_requests_spec.rb b/spec/requests/purchases_requests_spec.rb index 41cc8847c2..d60b23f484 100644 --- a/spec/requests/purchases_requests_spec.rb +++ b/spec/requests/purchases_requests_spec.rb @@ -266,16 +266,18 @@ let(:item) { create(: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, 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) } + 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)})" + freeze_time do + date_of_purchase = "#{1.day.ago.to_fs(:distribution_date)} (entered: #{1.month.ago.to_fs(:distribution_date)})" - get purchase_path(id: purchase.id) - expect(response.body).to include(date_of_purchase) - expect(response.body).to include('Another Business') - expect(response.body).to include('Some Storage') - expect(response.body).to include('Fine day for diapers, it is.') + get purchase_path(id: purchase.id) + expect(response.body).to include(date_of_purchase) + expect(response.body).to include('Another Business') + expect(response.body).to include('Some Storage') + expect(response.body).to include('Fine day for diapers, it is.') + end end it "shows an enabled edit button" do
Comment:
Comment: