From fb9e1c50e6be6c15066ab2bb4b44149ceae80616 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 26 Sep 2022 17:08:46 +0100 Subject: [PATCH] Folder structure (#901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update the folder structure * Add specs * testy 💁‍♀️ * Update names in tests 🫠 --- .../pages/property_number_of_bedrooms.rb | 4 +-- .../property/sections/property_information.rb | 10 ------- .../questions/property_number_of_bedrooms.rb | 2 +- .../sales/sections/property_information.rb | 10 +++++++ .../subsections/property_information.rb | 4 +-- app/models/form_handler.rb | 2 +- .../pages/property_number_of_bedrooms_spec.rb | 2 +- .../property_number_of_bedrooms_spec.rb | 2 +- .../form/sales/sections/household_spec.rb | 29 +++++++++++++++++++ .../sections/property_information_spec.rb | 29 +++++++++++++++++++ .../household_characteristics_spec.rb | 27 +++++++++++++++++ .../subsections/property_information_spec.rb | 27 +++++++++++++++++ spec/models/form_spec.rb | 4 +-- 13 files changed, 132 insertions(+), 20 deletions(-) rename app/models/form/sales/{property => }/pages/property_number_of_bedrooms.rb (57%) delete mode 100644 app/models/form/sales/property/sections/property_information.rb rename app/models/form/sales/{property => }/questions/property_number_of_bedrooms.rb (76%) create mode 100644 app/models/form/sales/sections/property_information.rb rename app/models/form/sales/{property => }/subsections/property_information.rb (58%) rename spec/models/form/sales/{property => }/pages/property_number_of_bedrooms_spec.rb (88%) rename spec/models/form/sales/{property => }/questions/property_number_of_bedrooms_spec.rb (90%) create mode 100644 spec/models/form/sales/sections/household_spec.rb create mode 100644 spec/models/form/sales/sections/property_information_spec.rb create mode 100644 spec/models/form/sales/subsections/household_characteristics_spec.rb create mode 100644 spec/models/form/sales/subsections/property_information_spec.rb diff --git a/app/models/form/sales/property/pages/property_number_of_bedrooms.rb b/app/models/form/sales/pages/property_number_of_bedrooms.rb similarity index 57% rename from app/models/form/sales/property/pages/property_number_of_bedrooms.rb rename to app/models/form/sales/pages/property_number_of_bedrooms.rb index c9199c84e..5efb6b0f4 100644 --- a/app/models/form/sales/property/pages/property_number_of_bedrooms.rb +++ b/app/models/form/sales/pages/property_number_of_bedrooms.rb @@ -1,4 +1,4 @@ -class Form::Sales::Property::Pages::PropertyNumberOfBedrooms < ::Form::Page +class Form::Sales::Pages::PropertyNumberOfBedrooms < ::Form::Page def initialize(id, hsh, subsection) super @id = "property_number_of_bedrooms" @@ -9,7 +9,7 @@ class Form::Sales::Property::Pages::PropertyNumberOfBedrooms < ::Form::Page def questions @questions ||= [ - Form::Sales::Property::Questions::PropertyNumberOfBedrooms.new(nil, nil, self), + Form::Sales::Questions::PropertyNumberOfBedrooms.new(nil, nil, self), ] end end diff --git a/app/models/form/sales/property/sections/property_information.rb b/app/models/form/sales/property/sections/property_information.rb deleted file mode 100644 index eab4faac6..000000000 --- a/app/models/form/sales/property/sections/property_information.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Form::Sales::Property::Sections::PropertyInformation < ::Form::Section - def initialize(id, hsh, form) - super - @id = "property_information" - @label = "Property information" - @description = "" - @form = form - @subsections = [Form::Sales::Property::Subsections::PropertyInformation.new(nil, nil, self)] || [] - end -end diff --git a/app/models/form/sales/property/questions/property_number_of_bedrooms.rb b/app/models/form/sales/questions/property_number_of_bedrooms.rb similarity index 76% rename from app/models/form/sales/property/questions/property_number_of_bedrooms.rb rename to app/models/form/sales/questions/property_number_of_bedrooms.rb index 046005cf1..34b319240 100644 --- a/app/models/form/sales/property/questions/property_number_of_bedrooms.rb +++ b/app/models/form/sales/questions/property_number_of_bedrooms.rb @@ -1,4 +1,4 @@ -class Form::Sales::Property::Questions::PropertyNumberOfBedrooms < ::Form::Question +class Form::Sales::Questions::PropertyNumberOfBedrooms < ::Form::Question def initialize(id, hsh, page) super @id = "beds" diff --git a/app/models/form/sales/sections/property_information.rb b/app/models/form/sales/sections/property_information.rb new file mode 100644 index 000000000..39f6609ae --- /dev/null +++ b/app/models/form/sales/sections/property_information.rb @@ -0,0 +1,10 @@ +class Form::Sales::Sections::PropertyInformation < ::Form::Section + def initialize(id, hsh, form) + super + @id = "property_information" + @label = "Property information" + @description = "" + @form = form + @subsections = [Form::Sales::Subsections::PropertyInformation.new(nil, nil, self)] || [] + end +end diff --git a/app/models/form/sales/property/subsections/property_information.rb b/app/models/form/sales/subsections/property_information.rb similarity index 58% rename from app/models/form/sales/property/subsections/property_information.rb rename to app/models/form/sales/subsections/property_information.rb index cbaa37d42..22983049b 100644 --- a/app/models/form/sales/property/subsections/property_information.rb +++ b/app/models/form/sales/subsections/property_information.rb @@ -1,4 +1,4 @@ -class Form::Sales::Property::Subsections::PropertyInformation < ::Form::Subsection +class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection def initialize(id, hsh, section) super @id = "property_information" @@ -9,7 +9,7 @@ class Form::Sales::Property::Subsections::PropertyInformation < ::Form::Subsecti def pages @pages ||= [ - Form::Sales::Property::Pages::PropertyNumberOfBedrooms.new(nil, nil, self), + Form::Sales::Pages::PropertyNumberOfBedrooms.new(nil, nil, self), ] end end diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 8cbcba5cf..c9d45e876 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -20,7 +20,7 @@ class FormHandler def sales_forms sales_sections = [ - Form::Sales::Property::Sections::PropertyInformation, + Form::Sales::Sections::PropertyInformation, Form::Sales::Sections::Household, ] current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales") diff --git a/spec/models/form/sales/property/pages/property_number_of_bedrooms_spec.rb b/spec/models/form/sales/pages/property_number_of_bedrooms_spec.rb similarity index 88% rename from spec/models/form/sales/property/pages/property_number_of_bedrooms_spec.rb rename to spec/models/form/sales/pages/property_number_of_bedrooms_spec.rb index 88a6941f6..078694916 100644 --- a/spec/models/form/sales/property/pages/property_number_of_bedrooms_spec.rb +++ b/spec/models/form/sales/pages/property_number_of_bedrooms_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Property::Pages::PropertyNumberOfBedrooms, type: :model do +RSpec.describe Form::Sales::Pages::PropertyNumberOfBedrooms, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection) } let(:page_id) { nil } diff --git a/spec/models/form/sales/property/questions/property_number_of_bedrooms_spec.rb b/spec/models/form/sales/questions/property_number_of_bedrooms_spec.rb similarity index 90% rename from spec/models/form/sales/property/questions/property_number_of_bedrooms_spec.rb rename to spec/models/form/sales/questions/property_number_of_bedrooms_spec.rb index 7e7ba3078..fc8dc3989 100644 --- a/spec/models/form/sales/property/questions/property_number_of_bedrooms_spec.rb +++ b/spec/models/form/sales/questions/property_number_of_bedrooms_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Property::Questions::PropertyNumberOfBedrooms, type: :model do +RSpec.describe Form::Sales::Questions::PropertyNumberOfBedrooms, type: :model do subject(:question) { described_class.new(question_id, question_definition, page) } let(:question_id) { nil } diff --git a/spec/models/form/sales/sections/household_spec.rb b/spec/models/form/sales/sections/household_spec.rb new file mode 100644 index 000000000..53d81f2fb --- /dev/null +++ b/spec/models/form/sales/sections/household_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Sections::Household, type: :model do + subject(:household) { described_class.new(section_id, section_definition, form) } + + let(:section_id) { nil } + let(:section_definition) { nil } + let(:form) { instance_double(Form) } + + it "has correct form" do + expect(household.form).to eq(form) + end + + it "has correct subsections" do + expect(household.subsections.map(&:id)).to eq(%w[household_characteristics]) + end + + it "has the correct id" do + expect(household.id).to eq("household") + end + + it "has the correct label" do + expect(household.label).to eq("About the household") + end + + it "has the correct description" do + expect(household.description).to eq("") + end +end diff --git a/spec/models/form/sales/sections/property_information_spec.rb b/spec/models/form/sales/sections/property_information_spec.rb new file mode 100644 index 000000000..fbd551233 --- /dev/null +++ b/spec/models/form/sales/sections/property_information_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Sections::PropertyInformation, type: :model do + subject(:property_information) { described_class.new(section_id, section_definition, form) } + + let(:section_id) { nil } + let(:section_definition) { nil } + let(:form) { instance_double(Form) } + + it "has correct form" do + expect(property_information.form).to eq(form) + end + + it "has correct subsections" do + expect(property_information.subsections.map(&:id)).to eq(%w[property_information]) + end + + it "has the correct id" do + expect(property_information.id).to eq("property_information") + end + + it "has the correct label" do + expect(property_information.label).to eq("Property information") + end + + it "has the correct description" do + expect(property_information.description).to eq("") + end +end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb new file mode 100644 index 000000000..b8c3d3e71 --- /dev/null +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model do + subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) } + + let(:subsection_id) { nil } + let(:subsection_definition) { nil } + let(:section) { instance_double(Form::Sales::Sections::Household) } + + it "has correct section" do + expect(household_characteristics.section).to eq(section) + end + + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[buyer_1_age], + ) + end + + it "has the correct id" do + expect(household_characteristics.id).to eq("household_characteristics") + end + + it "has the correct label" do + expect(household_characteristics.label).to eq("Household characteristics") + end +end diff --git a/spec/models/form/sales/subsections/property_information_spec.rb b/spec/models/form/sales/subsections/property_information_spec.rb new file mode 100644 index 000000000..95c09f016 --- /dev/null +++ b/spec/models/form/sales/subsections/property_information_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do + subject(:property_information) { described_class.new(subsection_id, subsection_definition, section) } + + let(:subsection_id) { nil } + let(:subsection_definition) { nil } + let(:section) { instance_double(Form::Sales::Sections::PropertyInformation) } + + it "has correct section" do + expect(property_information.section).to eq(section) + end + + it "has correct pages" do + expect(property_information.pages.map(&:id)).to eq( + %w[property_number_of_bedrooms], + ) + end + + it "has the correct id" do + expect(property_information.id).to eq("property_information") + end + + it "has the correct label" do + expect(property_information.label).to eq("Property information") + end +end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 82d83de49..fef3be5d7 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -227,12 +227,12 @@ RSpec.describe Form, type: :model do end it "can correctly define sections in the sales form" do - sections = [Form::Sales::Property::Sections::PropertyInformation] + sections = [Form::Sales::Sections::PropertyInformation] form = described_class.new(nil, 2022, sections, "sales") expect(form.type).to eq("sales") expect(form.name).to eq("2022_2023_sales") expect(form.sections.count).to eq(2) - expect(form.sections[1].class).to eq(Form::Sales::Property::Sections::PropertyInformation) + expect(form.sections[1].class).to eq(Form::Sales::Sections::PropertyInformation) end end end