From f1a0931b9feda5b675e8773ff657a74c79fe32ef Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 1 Apr 2022 13:38:00 +0100 Subject: [PATCH] Time bombing your own specs is a bad time --- spec/factories/case_log.rb | 20 +++++++++---------- spec/fixtures/exports/case_logs.xml | 12 +++++------ spec/models/form/subsection_spec.rb | 10 +++++----- .../exports/case_log_export_service_spec.rb | 5 +++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 60cdc72bd..e869d8e7f 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -129,16 +129,16 @@ FactoryBot.define do ppostc1 { "w3" } ppostc2 { "w3" } property_relet { 0 } - mrcdate { Time.zone.now } - mrcday { 5 } - mrcmonth { 5 } - mrcyear { 2020 } + mrcdate { Time.utc(2020, 0o5, 0o5, 10, 36, 49) } + mrcday { mrcdate.day } + mrcmonth { mrcdate.month } + mrcyear { mrcdate.year } incref { 0 } sale_completion_date { nil } - startdate { Time.zone.now } - day { Time.zone.now.day } - month { Time.zone.now.month } - year { 2021 } + startdate { Time.utc(2022, 0o2, 0o2, 10, 36, 49) } + day { startdate.day } + month { startdate.month } + year { startdate.year } armedforces { 0 } builtype { 1 } unitletas { 2 } @@ -148,7 +148,7 @@ FactoryBot.define do la_known { 1 } declaration { 1 } end - created_at { Time.zone.now } - updated_at { Time.zone.now } + created_at { Time.utc(2022, 0o2, 8, 16, 52, 15) } + updated_at { Time.utc(2022, 0o2, 8, 16, 52, 15) } end end diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index d648045ab..6ad128d05 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -104,14 +104,14 @@ SE2 6RT 0 - 2022-02-08 16:52:15 UTC - 8 - 2 - 2022 + 2020-05-05 10:36:49 UTC + 5 + 5 + 2020 1 0 - 2022-02-08 16:52:15 UTC + 2022-02-02 10:36:49 UTC 0 2 @@ -125,7 +125,7 @@ 1 1 false - 8 + 2 2 2022 0 diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index d41755faf..6492c1b21 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -85,21 +85,21 @@ RSpec.describe Form::Subsection, type: :model do end context "with a completed case log" do - let(:completed_case_log) { FactoryBot.build(:case_log, :completed) } + let(:case_log) { FactoryBot.build(:case_log, :completed) } it "has a status" do - expect(subsection.status(completed_case_log)).to eq(:completed) + expect(subsection.status(case_log)).to eq(:completed) end it "has a status when optional fields are not filled" do case_log.update!({ propcode: nil }) case_log.reload - expect(subsection.status(completed_case_log)).to eq(:completed) + expect(subsection.status(case_log)).to eq(:completed) end it "has status helpers" do - expect(subsection.is_incomplete?(completed_case_log)).to be(false) - expect(subsection.is_started?(completed_case_log)).to be(true) + expect(subsection.is_incomplete?(case_log)).to be(false) + expect(subsection.is_started?(case_log)).to be(true) end end end diff --git a/spec/services/exports/case_log_export_service_spec.rb b/spec/services/exports/case_log_export_service_spec.rb index 776e4408e..dfea4c1a9 100644 --- a/spec/services/exports/case_log_export_service_spec.rb +++ b/spec/services/exports/case_log_export_service_spec.rb @@ -5,7 +5,6 @@ RSpec.describe Exports::CaseLogExportService do let(:export_filepath) { "spec/fixtures/exports/case_logs.xml" } let(:export_file) { File.open(export_filepath, "r:UTF-8") } let(:expected_filename) { "core_2022_02_08/dat_core_2022_02_08_0001.xml" } - let!(:case_log) { FactoryBot.create(:case_log, :completed) } def replace_entity_ids(export_template) export_template.sub!(/\{id\}/, case_log["id"].to_s) @@ -16,8 +15,10 @@ RSpec.describe Exports::CaseLogExportService do context "when exporting case logs" do subject(:export_service) { described_class.new(storage_service) } + let(:case_log) { FactoryBot.create(:case_log, :completed) } + before do - Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00")) + Timecop.freeze(case_log.updated_at) end it "generate an XML export file with the expected filename" do