Browse Source

CLDC-4173: date refactoring in tests

pull/3186/head
Nat Dean-Lewis 3 weeks ago
parent
commit
ea0d1cdf53
  1. 7
      spec/models/form/sales/pages/building_height_class_spec.rb
  2. 7
      spec/models/form/sales/questions/building_height_class_spec.rb
  3. 37
      spec/models/form/sales/subsections/property_information_spec.rb

7
spec/models/form/sales/pages/building_height_class_spec.rb

@ -1,12 +1,15 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::BuildingHeightClass, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, collection_start_date_for_year(2026))) }
let(:sales_log) { FactoryBot.create(:sales_log, :completed) }
let(:start_date) { collection_start_date_for_year(2026) }
let(:form) { instance_double(Form, start_date:) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)

7
spec/models/form/sales/questions/building_height_class_spec.rb

@ -1,11 +1,16 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuildingHeightClass, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, collection_start_date_for_year(2026)))) }
let(:start_date) { collection_start_date_for_year(2026) }
let(:form) { instance_double(Form, start_date:) }
let(:subsection) { instance_double(Form::Subsection, form:) }
let(:page) { instance_double(Form::Page, subsection:) }
it "has correct page" do
expect(question.page).to eq(page)

37
spec/models/form/sales/subsections/property_information_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
include CollectionTimeHelper
subject(:property_information) { described_class.new(nil, nil, section) }
let(:section) { instance_double(Form::Sales::Sections::PropertyInformation) }
@ -11,14 +13,16 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
describe "pages" do
let(:section) { instance_double(Form::Sales::Sections::Household, form:) }
let(:form) { instance_double(Form, start_date:) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: false, start_year_2025_or_later?: false, start_year_2026_or_later?: false)
end
let(:start_year_2024_or_later?) { true }
let(:start_year_2025_or_later?) { true }
let(:start_year_2026_or_later?) { true }
let(:form) { instance_double(Form, start_date:, start_year_2024_or_later?: start_year_2024_or_later?, start_year_2025_or_later?: start_year_2025_or_later?, start_year_2026_or_later?: start_year_2026_or_later?) }
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
let(:start_date) { collection_start_date_for_year(2023) }
let(:start_year_2024_or_later?) { false }
let(:start_year_2025_or_later?) { false }
let(:start_year_2026_or_later?) { false }
it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq(
@ -44,11 +48,9 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
end
context "when 2024" do
let(:start_date) { Time.utc(2024, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: false, start_year_2026_or_later?: false)
end
let(:start_date) { collection_start_date_for_year(2024) }
let(:start_year_2025_or_later?) { false }
let(:start_year_2026_or_later?) { false }
it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq(
@ -73,11 +75,8 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
end
context "when 2025" do
let(:start_date) { Time.utc(2025, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: true, start_year_2026_or_later?: false)
end
let(:start_date) { collection_start_date_for_year(2025) }
let(:start_year_2026_or_later?) { false }
it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq(
@ -102,11 +101,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
end
context "when 2026" do
let(:start_date) { Time.utc(2026, 2, 8) }
before do
allow(form).to receive_messages(start_year_2024_or_later?: true, start_year_2025_or_later?: true, start_year_2026_or_later?: true)
end
let(:start_date) { collection_start_date_for_year(2026) }
it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq(

Loading…
Cancel
Save