Browse Source

Refactor form namespacing (#873)

* Refactor form namespacing

* Extract common questions
pull/874/head
baarkerlounger 2 years ago committed by GitHub
parent
commit
1664493287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/form.rb
  2. 4
      app/models/form/common/pages/created_by.rb
  3. 4
      app/models/form/common/pages/organisation.rb
  4. 2
      app/models/form/common/questions/created_by_id.rb
  5. 2
      app/models/form/common/questions/owning_organisation_id.rb
  6. 4
      app/models/form/lettings/pages/location.rb
  7. 4
      app/models/form/lettings/pages/needs_type.rb
  8. 4
      app/models/form/lettings/pages/property_reference.rb
  9. 4
      app/models/form/lettings/pages/renewal.rb
  10. 6
      app/models/form/lettings/pages/rent_type.rb
  11. 4
      app/models/form/lettings/pages/scheme.rb
  12. 4
      app/models/form/lettings/pages/tenancy_start_date.rb
  13. 4
      app/models/form/lettings/pages/tenant_code.rb
  14. 2
      app/models/form/lettings/questions/irproduct_other.rb
  15. 2
      app/models/form/lettings/questions/location_id.rb
  16. 2
      app/models/form/lettings/questions/needs_type.rb
  17. 2
      app/models/form/lettings/questions/property_reference.rb
  18. 2
      app/models/form/lettings/questions/renewal.rb
  19. 2
      app/models/form/lettings/questions/rent_type.rb
  20. 2
      app/models/form/lettings/questions/scheme_id.rb
  21. 2
      app/models/form/lettings/questions/tenancy_start_date.rb
  22. 2
      app/models/form/lettings/questions/tenant_code.rb
  23. 4
      app/models/form/lettings/sections/setup.rb
  24. 37
      app/models/form/lettings/subsections/setup.rb
  25. 4
      app/models/form/sales/pages/purchaser_code.rb
  26. 4
      app/models/form/sales/pages/sale_date.rb
  27. 2
      app/models/form/sales/questions/purchaser_code.rb
  28. 2
      app/models/form/sales/questions/sale_date.rb
  29. 10
      app/models/form/sales/sections/setup.rb
  30. 10
      app/models/form/sales/setup/sections/setup.rb
  31. 15
      app/models/form/sales/setup/subsections/setup.rb
  32. 15
      app/models/form/sales/subsections/setup.rb
  33. 37
      app/models/form/setup/subsections/setup.rb
  34. 2
      spec/models/form/common/pages/created_by_spec.rb
  35. 2
      spec/models/form/common/pages/organisation_spec.rb
  36. 2
      spec/models/form/common/questions/created_by_id_spec.rb
  37. 2
      spec/models/form/common/questions/owning_organisation_id_spec.rb
  38. 2
      spec/models/form/lettings/pages/location_spec.rb
  39. 2
      spec/models/form/lettings/pages/needs_type_spec.rb
  40. 2
      spec/models/form/lettings/pages/property_reference_spec.rb
  41. 2
      spec/models/form/lettings/pages/renewal_spec.rb
  42. 2
      spec/models/form/lettings/pages/rent_type_spec.rb
  43. 2
      spec/models/form/lettings/pages/scheme_spec.rb
  44. 2
      spec/models/form/lettings/pages/tenancy_start_date_spec.rb
  45. 2
      spec/models/form/lettings/pages/tenant_code_spec.rb
  46. 2
      spec/models/form/lettings/questions/irproduct_other_spec.rb
  47. 2
      spec/models/form/lettings/questions/location_id_spec.rb
  48. 2
      spec/models/form/lettings/questions/needs_type_spec.rb
  49. 2
      spec/models/form/lettings/questions/property_reference_spec.rb
  50. 2
      spec/models/form/lettings/questions/renewal_spec.rb
  51. 2
      spec/models/form/lettings/questions/rent_type_spec.rb
  52. 2
      spec/models/form/lettings/questions/scheme_id_spec.rb
  53. 2
      spec/models/form/lettings/questions/tenancy_start_date_spec.rb
  54. 2
      spec/models/form/lettings/questions/tenant_code_spec.rb
  55. 2
      spec/models/form/lettings/sections/setup_spec.rb
  56. 4
      spec/models/form/lettings/subsections/setup_spec.rb
  57. 2
      spec/models/form/sales/pages/purchaser_code_spec.rb
  58. 2
      spec/models/form/sales/pages/sale_date_spec.rb
  59. 2
      spec/models/form/sales/questions/purchaser_code_spec.rb
  60. 2
      spec/models/form/sales/questions/sale_date_spec.rb
  61. 2
      spec/models/form/sales/sections/setup_spec.rb
  62. 4
      spec/models/form/sales/subsections/setup_spec.rb
  63. 4
      spec/models/form_spec.rb

6
app/models/form.rb

@ -3,12 +3,10 @@ class Form
:start_date, :end_date, :type, :name, :setup_definition, :start_date, :end_date, :type, :name, :setup_definition,
:setup_sections, :form_sections :setup_sections, :form_sections
include Form::Setup
def initialize(form_path, name, sections_in_form = [], type = "lettings") def initialize(form_path, name, sections_in_form = [], type = "lettings")
if type == "sales" if type == "sales"
@name = name @name = name
@setup_sections = [Form::Sales::Setup::Sections::Setup.new(nil, nil, self)] @setup_sections = [Form::Sales::Sections::Setup.new(nil, nil, self)]
@form_sections = sections_in_form.map { |sec| sec.new(nil, nil, self) } @form_sections = sections_in_form.map { |sec| sec.new(nil, nil, self) }
@type = "sales" @type = "sales"
@sections = setup_sections + form_sections @sections = setup_sections + form_sections
@ -27,7 +25,7 @@ class Form
raise "No form definition file exists for given year".freeze unless File.exist?(form_path) raise "No form definition file exists for given year".freeze unless File.exist?(form_path)
@name = name @name = name
@setup_sections = [Form::Setup::Sections::Setup.new(nil, nil, self)] @setup_sections = [Form::Lettings::Sections::Setup.new(nil, nil, self)]
@form_definition = JSON.parse(File.open(form_path).read) @form_definition = JSON.parse(File.open(form_path).read)
@form_sections = form_definition["sections"].map { |id, s| Form::Section.new(id, s, self) } @form_sections = form_definition["sections"].map { |id, s| Form::Section.new(id, s, self) }
@type = form_definition["form_type"] @type = form_definition["form_type"]

4
app/models/form/setup/pages/created_by.rb → app/models/form/common/pages/created_by.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::CreatedBy < ::Form::Page class Form::Common::Pages::CreatedBy < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "created_by" @id = "created_by"
@ -9,7 +9,7 @@ class Form::Setup::Pages::CreatedBy < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::CreatedById.new(nil, nil, self), Form::Common::Questions::CreatedById.new(nil, nil, self),
] ]
end end

4
app/models/form/setup/pages/organisation.rb → app/models/form/common/pages/organisation.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::Organisation < ::Form::Page class Form::Common::Pages::Organisation < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "organisation" @id = "organisation"
@ -9,7 +9,7 @@ class Form::Setup::Pages::Organisation < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::OwningOrganisationId.new(nil, nil, self), Form::Common::Questions::OwningOrganisationId.new(nil, nil, self),
] ]
end end

2
app/models/form/setup/questions/created_by_id.rb → app/models/form/common/questions/created_by_id.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::CreatedById < ::Form::Question class Form::Common::Questions::CreatedById < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "created_by_id" @id = "created_by_id"

2
app/models/form/setup/questions/owning_organisation_id.rb → app/models/form/common/questions/owning_organisation_id.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::OwningOrganisationId < ::Form::Question class Form::Common::Questions::OwningOrganisationId < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "owning_organisation_id" @id = "owning_organisation_id"

4
app/models/form/setup/pages/location.rb → app/models/form/lettings/pages/location.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::Location < ::Form::Page class Form::Lettings::Pages::Location < ::Form::Page
def initialize(_id, hsh, subsection) def initialize(_id, hsh, subsection)
super("location", hsh, subsection) super("location", hsh, subsection)
@header = "" @header = ""
@ -11,7 +11,7 @@ class Form::Setup::Pages::Location < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::LocationId.new(nil, nil, self), Form::Lettings::Questions::LocationId.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/setup/pages/needs_type.rb → app/models/form/lettings/pages/needs_type.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::NeedsType < ::Form::Page class Form::Lettings::Pages::NeedsType < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "needs_type" @id = "needs_type"
@ -9,7 +9,7 @@ class Form::Setup::Pages::NeedsType < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::NeedsType.new(nil, nil, self), Form::Lettings::Questions::NeedsType.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/setup/pages/property_reference.rb → app/models/form/lettings/pages/property_reference.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::PropertyReference < ::Form::Page class Form::Lettings::Pages::PropertyReference < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "property_reference" @id = "property_reference"
@ -9,7 +9,7 @@ class Form::Setup::Pages::PropertyReference < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::PropertyReference.new(nil, nil, self), Form::Lettings::Questions::PropertyReference.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/setup/pages/renewal.rb → app/models/form/lettings/pages/renewal.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::Renewal < ::Form::Page class Form::Lettings::Pages::Renewal < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "renewal" @id = "renewal"
@ -9,7 +9,7 @@ class Form::Setup::Pages::Renewal < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::Renewal.new(nil, nil, self), Form::Lettings::Questions::Renewal.new(nil, nil, self),
] ]
end end
end end

6
app/models/form/setup/pages/rent_type.rb → app/models/form/lettings/pages/rent_type.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::RentType < ::Form::Page class Form::Lettings::Pages::RentType < ::Form::Page
def initialize(_id, hsh, subsection) def initialize(_id, hsh, subsection)
super("rent_type", hsh, subsection) super("rent_type", hsh, subsection)
@header = "" @header = ""
@ -8,8 +8,8 @@ class Form::Setup::Pages::RentType < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::RentType.new(nil, nil, self), Form::Lettings::Questions::RentType.new(nil, nil, self),
Form::Setup::Questions::IrproductOther.new(nil, nil, self), Form::Lettings::Questions::IrproductOther.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/setup/pages/scheme.rb → app/models/form/lettings/pages/scheme.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::Scheme < ::Form::Page class Form::Lettings::Pages::Scheme < ::Form::Page
def initialize(_id, hsh, subsection) def initialize(_id, hsh, subsection)
super("scheme", hsh, subsection) super("scheme", hsh, subsection)
@header = "" @header = ""
@ -10,7 +10,7 @@ class Form::Setup::Pages::Scheme < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::SchemeId.new(nil, nil, self), Form::Lettings::Questions::SchemeId.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/setup/pages/tenancy_start_date.rb → app/models/form/lettings/pages/tenancy_start_date.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::TenancyStartDate < ::Form::Page class Form::Lettings::Pages::TenancyStartDate < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "tenancy_start_date" @id = "tenancy_start_date"
@ -8,7 +8,7 @@ class Form::Setup::Pages::TenancyStartDate < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::TenancyStartDate.new(nil, nil, self), Form::Lettings::Questions::TenancyStartDate.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/setup/pages/tenant_code.rb → app/models/form/lettings/pages/tenant_code.rb

@ -1,4 +1,4 @@
class Form::Setup::Pages::TenantCode < ::Form::Page class Form::Lettings::Pages::TenantCode < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "tenant_code" @id = "tenant_code"
@ -9,7 +9,7 @@ class Form::Setup::Pages::TenantCode < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Setup::Questions::TenantCode.new(nil, nil, self), Form::Lettings::Questions::TenantCode.new(nil, nil, self),
] ]
end end
end end

2
app/models/form/setup/questions/irproduct_other.rb → app/models/form/lettings/questions/irproduct_other.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::IrproductOther < ::Form::Question class Form::Lettings::Questions::IrproductOther < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "irproduct_other" @id = "irproduct_other"

2
app/models/form/setup/questions/location_id.rb → app/models/form/lettings/questions/location_id.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::LocationId < ::Form::Question class Form::Lettings::Questions::LocationId < ::Form::Question
def initialize(_id, hsh, page) def initialize(_id, hsh, page)
super("location_id", hsh, page) super("location_id", hsh, page)
@check_answer_label = "Location" @check_answer_label = "Location"

2
app/models/form/setup/questions/needs_type.rb → app/models/form/lettings/questions/needs_type.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::NeedsType < ::Form::Question class Form::Lettings::Questions::NeedsType < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "needstype" @id = "needstype"

2
app/models/form/setup/questions/property_reference.rb → app/models/form/lettings/questions/property_reference.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::PropertyReference < ::Form::Question class Form::Lettings::Questions::PropertyReference < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "propcode" @id = "propcode"

2
app/models/form/setup/questions/renewal.rb → app/models/form/lettings/questions/renewal.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::Renewal < ::Form::Question class Form::Lettings::Questions::Renewal < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "renewal" @id = "renewal"

2
app/models/form/setup/questions/rent_type.rb → app/models/form/lettings/questions/rent_type.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::RentType < ::Form::Question class Form::Lettings::Questions::RentType < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "rent_type" @id = "rent_type"

2
app/models/form/setup/questions/scheme_id.rb → app/models/form/lettings/questions/scheme_id.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::SchemeId < ::Form::Question class Form::Lettings::Questions::SchemeId < ::Form::Question
def initialize(_id, hsh, page) def initialize(_id, hsh, page)
super("scheme_id", hsh, page) super("scheme_id", hsh, page)
@check_answer_label = "Scheme name" @check_answer_label = "Scheme name"

2
app/models/form/setup/questions/tenancy_start_date.rb → app/models/form/lettings/questions/tenancy_start_date.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::TenancyStartDate < ::Form::Question class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "startdate" @id = "startdate"

2
app/models/form/setup/questions/tenant_code.rb → app/models/form/lettings/questions/tenant_code.rb

@ -1,4 +1,4 @@
class Form::Setup::Questions::TenantCode < ::Form::Question class Form::Lettings::Questions::TenantCode < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "tenancycode" @id = "tenancycode"

4
app/models/form/setup/sections/setup.rb → app/models/form/lettings/sections/setup.rb

@ -1,10 +1,10 @@
class Form::Sections::Setup < ::Form::Section class Form::Lettings::Sections::Setup < ::Form::Section
def initialize(id, hsh, form) def initialize(id, hsh, form)
super super
@id = "setup" @id = "setup"
@label = "Before you start" @label = "Before you start"
@description = "" @description = ""
@form = form @form = form
@subsections = [Form::Setup::Subsections::Setup.new(nil, nil, self)] @subsections = [Form::Lettings::Subsections::Setup.new(nil, nil, self)]
end end
end end

37
app/models/form/lettings/subsections/setup.rb

@ -0,0 +1,37 @@
class Form::Lettings::Subsections::Setup < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "setup"
@label = "Set up this lettings log"
@section = section
end
def pages
@pages ||= [
Form::Common::Pages::Organisation.new(nil, nil, self),
Form::Common::Pages::CreatedBy.new(nil, nil, self),
Form::Lettings::Pages::NeedsType.new(nil, nil, self),
Form::Lettings::Pages::Scheme.new(nil, nil, self),
Form::Lettings::Pages::Location.new(nil, nil, self),
Form::Lettings::Pages::Renewal.new(nil, nil, self),
Form::Lettings::Pages::TenancyStartDate.new(nil, nil, self),
Form::Lettings::Pages::RentType.new(nil, nil, self),
Form::Lettings::Pages::TenantCode.new(nil, nil, self),
Form::Lettings::Pages::PropertyReference.new(nil, nil, self),
]
end
def applicable_questions(lettings_log)
questions.select { |q| support_only_questions.include?(q.id) } + super
end
def enabled?(_lettings_log)
true
end
private
def support_only_questions
%w[owning_organisation_id created_by_id].freeze
end
end

4
app/models/form/sales/setup/pages/purchaser_code.rb → app/models/form/sales/pages/purchaser_code.rb

@ -1,4 +1,4 @@
class Form::Sales::Setup::Pages::PurchaserCode < ::Form::Page class Form::Sales::Pages::PurchaserCode < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "purchaser_code" @id = "purchaser_code"
@ -9,7 +9,7 @@ class Form::Sales::Setup::Pages::PurchaserCode < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Setup::Questions::PurchaserCode.new(nil, nil, self), Form::Sales::Questions::PurchaserCode.new(nil, nil, self),
] ]
end end
end end

4
app/models/form/sales/setup/pages/sale_date.rb → app/models/form/sales/pages/sale_date.rb

@ -1,4 +1,4 @@
class Form::Sales::Setup::Pages::SaleDate < ::Form::Page class Form::Sales::Pages::SaleDate < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "sale_date" @id = "sale_date"
@ -9,7 +9,7 @@ class Form::Sales::Setup::Pages::SaleDate < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Setup::Questions::SaleDate.new(nil, nil, self), Form::Sales::Questions::SaleDate.new(nil, nil, self),
] ]
end end
end end

2
app/models/form/sales/setup/questions/purchaser_code.rb → app/models/form/sales/questions/purchaser_code.rb

@ -1,4 +1,4 @@
class Form::Sales::Setup::Questions::PurchaserCode < ::Form::Question class Form::Sales::Questions::PurchaserCode < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "purchid" @id = "purchid"

2
app/models/form/sales/setup/questions/sale_date.rb → app/models/form/sales/questions/sale_date.rb

@ -1,4 +1,4 @@
class Form::Sales::Setup::Questions::SaleDate < ::Form::Question class Form::Sales::Questions::SaleDate < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "saledate" @id = "saledate"

10
app/models/form/sales/sections/setup.rb

@ -0,0 +1,10 @@
class Form::Sales::Sections::Setup < ::Form::Section
def initialize(id, hsh, form)
super
@id = "setup"
@label = "Before you start"
@description = ""
@form = form
@subsections = [Form::Sales::Subsections::Setup.new(nil, nil, self)] || []
end
end

10
app/models/form/sales/setup/sections/setup.rb

@ -1,10 +0,0 @@
class Form::Sales::Setup::Sections::Setup < ::Form::Section
def initialize(id, hsh, form)
super
@id = "setup"
@label = "Before you start"
@description = ""
@form = form
@subsections = [Form::Sales::Setup::Subsections::Setup.new(nil, nil, self)] || []
end
end

15
app/models/form/sales/setup/subsections/setup.rb

@ -1,15 +0,0 @@
class Form::Sales::Setup::Subsections::Setup < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "setup"
@label = "Set up this sales log"
@section = section
end
def pages
@pages ||= [
Form::Sales::Setup::Pages::PurchaserCode.new(nil, nil, self),
Form::Sales::Setup::Pages::SaleDate.new(nil, nil, self),
]
end
end

15
app/models/form/sales/subsections/setup.rb

@ -0,0 +1,15 @@
class Form::Sales::Subsections::Setup < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "setup"
@label = "Set up this sales log"
@section = section
end
def pages
@pages ||= [
Form::Sales::Pages::PurchaserCode.new(nil, nil, self),
Form::Sales::Pages::SaleDate.new(nil, nil, self),
]
end
end

37
app/models/form/setup/subsections/setup.rb

@ -1,37 +0,0 @@
class Form::Subsections::Setup < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "setup"
@label = "Set up this lettings log"
@section = section
end
def pages
@pages ||= [
Form::Setup::Pages::Organisation.new(nil, nil, self),
Form::Setup::Pages::CreatedBy.new(nil, nil, self),
Form::Setup::Pages::NeedsType.new(nil, nil, self),
Form::Setup::Pages::Scheme.new(nil, nil, self),
Form::Setup::Pages::Location.new(nil, nil, self),
Form::Setup::Pages::Renewal.new(nil, nil, self),
Form::Setup::Pages::TenancyStartDate.new(nil, nil, self),
Form::Setup::Pages::RentType.new(nil, nil, self),
Form::Setup::Pages::TenantCode.new(nil, nil, self),
Form::Setup::Pages::PropertyReference.new(nil, nil, self),
]
end
def applicable_questions(lettings_log)
questions.select { |q| support_only_questions.include?(q.id) } + super
end
def enabled?(_lettings_log)
true
end
private
def support_only_questions
%w[owning_organisation_id created_by_id].freeze
end
end

2
spec/models/form/setup/pages/created_by_spec.rb → spec/models/form/common/pages/created_by_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::CreatedBy, type: :model do RSpec.describe Form::Common::Pages::CreatedBy, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/organisation_spec.rb → spec/models/form/common/pages/organisation_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::Organisation, type: :model do RSpec.describe Form::Common::Pages::Organisation, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/questions/created_by_id_spec.rb → spec/models/form/common/questions/created_by_id_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::CreatedById, type: :model do RSpec.describe Form::Common::Questions::CreatedById, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/owning_organisation_id_spec.rb → spec/models/form/common/questions/owning_organisation_id_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::OwningOrganisationId, type: :model do RSpec.describe Form::Common::Questions::OwningOrganisationId, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/pages/location_spec.rb → spec/models/form/lettings/pages/location_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::Location, type: :model do RSpec.describe Form::Lettings::Pages::Location, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/needs_type_spec.rb → spec/models/form/lettings/pages/needs_type_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::NeedsType, type: :model do RSpec.describe Form::Lettings::Pages::NeedsType, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/property_reference_spec.rb → spec/models/form/lettings/pages/property_reference_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::PropertyReference, type: :model do RSpec.describe Form::Lettings::Pages::PropertyReference, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/renewal_spec.rb → spec/models/form/lettings/pages/renewal_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::Renewal, type: :model do RSpec.describe Form::Lettings::Pages::Renewal, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/rent_type_spec.rb → spec/models/form/lettings/pages/rent_type_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::RentType, type: :model do RSpec.describe Form::Lettings::Pages::RentType, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/scheme_spec.rb → spec/models/form/lettings/pages/scheme_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::Scheme, type: :model do RSpec.describe Form::Lettings::Pages::Scheme, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/tenancy_start_date_spec.rb → spec/models/form/lettings/pages/tenancy_start_date_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::TenancyStartDate, type: :model do RSpec.describe Form::Lettings::Pages::TenancyStartDate, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/pages/tenant_code_spec.rb → spec/models/form/lettings/pages/tenant_code_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Pages::TenantCode, type: :model do RSpec.describe Form::Lettings::Pages::TenantCode, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/setup/questions/irproduct_other_spec.rb → spec/models/form/lettings/questions/irproduct_other_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::IrproductOther, type: :model do RSpec.describe Form::Lettings::Questions::IrproductOther, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/location_id_spec.rb → spec/models/form/lettings/questions/location_id_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::LocationId, type: :model do RSpec.describe Form::Lettings::Questions::LocationId, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/needs_type_spec.rb → spec/models/form/lettings/questions/needs_type_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::NeedsType, type: :model do RSpec.describe Form::Lettings::Questions::NeedsType, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/property_reference_spec.rb → spec/models/form/lettings/questions/property_reference_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::PropertyReference, type: :model do RSpec.describe Form::Lettings::Questions::PropertyReference, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/renewal_spec.rb → spec/models/form/lettings/questions/renewal_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::Renewal, type: :model do RSpec.describe Form::Lettings::Questions::Renewal, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/rent_type_spec.rb → spec/models/form/lettings/questions/rent_type_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::RentType, type: :model do RSpec.describe Form::Lettings::Questions::RentType, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/scheme_id_spec.rb → spec/models/form/lettings/questions/scheme_id_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::SchemeId, type: :model do RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/tenancy_start_date_spec.rb → spec/models/form/lettings/questions/tenancy_start_date_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::TenancyStartDate, type: :model do RSpec.describe Form::Lettings::Questions::TenancyStartDate, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/questions/tenant_code_spec.rb → spec/models/form/lettings/questions/tenant_code_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Questions::TenantCode, type: :model do RSpec.describe Form::Lettings::Questions::TenantCode, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/sales/setup/sections/setup_spec.rb → spec/models/form/lettings/sections/setup_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Setup::Sections::Setup, type: :model do RSpec.describe Form::Lettings::Sections::Setup, type: :model do
subject(:setup) { described_class.new(section_id, section_definition, form) } subject(:setup) { described_class.new(section_id, section_definition, form) }
let(:section_id) { nil } let(:section_id) { nil }

4
spec/models/form/setup/subsections/setup_spec.rb → spec/models/form/lettings/subsections/setup_spec.rb

@ -1,11 +1,11 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Subsections::Setup, type: :model do RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
subject(:setup) { described_class.new(subsection_id, subsection_definition, section) } subject(:setup) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil } let(:subsection_id) { nil }
let(:subsection_definition) { nil } let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Setup::Sections::Setup) } let(:section) { instance_double(Form::Lettings::Sections::Setup) }
it "has correct section" do it "has correct section" do
expect(setup.section).to eq(section) expect(setup.section).to eq(section)

2
spec/models/form/sales/setup/pages/purchaser_code_spec.rb → spec/models/form/sales/pages/purchaser_code_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Setup::Pages::PurchaserCode, type: :model do RSpec.describe Form::Sales::Pages::PurchaserCode, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/sales/setup/pages/sale_date_spec.rb → spec/models/form/sales/pages/sale_date_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Setup::Pages::SaleDate, type: :model do RSpec.describe Form::Sales::Pages::SaleDate, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }

2
spec/models/form/sales/setup/questions/purchaser_code_spec.rb → spec/models/form/sales/questions/purchaser_code_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Setup::Questions::PurchaserCode, type: :model do RSpec.describe Form::Sales::Questions::PurchaserCode, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/sales/setup/questions/sale_date_spec.rb → spec/models/form/sales/questions/sale_date_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Setup::Questions::SaleDate, type: :model do RSpec.describe Form::Sales::Questions::SaleDate, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }

2
spec/models/form/setup/sections/setup_spec.rb → spec/models/form/sales/sections/setup_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Setup::Sections::Setup, type: :model do RSpec.describe Form::Sales::Sections::Setup, type: :model do
subject(:setup) { described_class.new(section_id, section_definition, form) } subject(:setup) { described_class.new(section_id, section_definition, form) }
let(:section_id) { nil } let(:section_id) { nil }

4
spec/models/form/sales/setup/subsections/setup_spec.rb → spec/models/form/sales/subsections/setup_spec.rb

@ -1,11 +1,11 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Setup::Subsections::Setup, type: :model do RSpec.describe Form::Sales::Subsections::Setup, type: :model do
subject(:setup) { described_class.new(subsection_id, subsection_definition, section) } subject(:setup) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil } let(:subsection_id) { nil }
let(:subsection_definition) { nil } let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Setup::Sections::Setup) } let(:section) { instance_double(Form::Sales::Sections::Setup) }
it "has correct section" do it "has correct section" do
expect(setup.section).to eq(section) expect(setup.section).to eq(section)

4
spec/models/form_spec.rb

@ -213,9 +213,9 @@ RSpec.describe Form, type: :model do
expect(form.type).to eq("sales") expect(form.type).to eq("sales")
expect(form.name).to eq("2022_23_sales") expect(form.name).to eq("2022_23_sales")
expect(form.setup_sections.count).to eq(1) expect(form.setup_sections.count).to eq(1)
expect(form.setup_sections[0].class).to eq(Form::Sales::Setup::Sections::Setup) expect(form.setup_sections[0].class).to eq(Form::Sales::Sections::Setup)
expect(form.sections.count).to eq(1) expect(form.sections.count).to eq(1)
expect(form.sections[0].class).to eq(Form::Sales::Setup::Sections::Setup) expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup)
expect(form.subsections.count).to eq(1) expect(form.subsections.count).to eq(1)
expect(form.subsections.first.id).to eq("setup") expect(form.subsections.first.id).to eq("setup")
expect(form.pages.count).to eq(2) expect(form.pages.count).to eq(2)

Loading…
Cancel
Save