From b7cdc30f8c67d1479925ad97612801db9970048d Mon Sep 17 00:00:00 2001 From: victorhwmn Date: Sat, 14 Sep 2024 16:02:53 -0300 Subject: [PATCH] fix(purchases_requests_rspec): use freeze_time on show purchase info test --- spec/requests/purchases_requests_spec.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/spec/requests/purchases_requests_spec.rb b/spec/requests/purchases_requests_spec.rb index 41cc8847c2..ef436de1f9 100644 --- a/spec/requests/purchases_requests_spec.rb +++ b/spec/requests/purchases_requests_spec.rb @@ -264,18 +264,21 @@ describe "GET #show" do 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!(: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.', 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 + purchase.update(created_at: 1.month.ago, issued_at: 1.day.ago) + 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