Browse Source

update some depends on for readability and write test files for page classes

pull/1341/head
Arthur Campbell 3 years ago
parent
commit
e1052c5d76
  1. 4
      app/models/form/lettings/pages/starter_tenancy_type.rb
  2. 2
      app/models/form/lettings/pages/tenancy_length.rb
  3. 2
      app/models/form/lettings/pages/tenancy_type.rb
  4. 2
      app/models/form/lettings/questions/starter_tenancy_type.rb
  5. 8
      app/models/lettings_log.rb
  6. 31
      spec/models/form/lettings/pages/starter_tenancy_type_spec.rb
  7. 31
      spec/models/form/lettings/pages/tenancy_length_spec.rb
  8. 31
      spec/models/form/lettings/pages/tenancy_type_spec.rb

4
app/models/form/lettings/pages/starter_tenancy_type.rb

@ -2,12 +2,12 @@ class Form::Lettings::Pages::StarterTenancyType < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "starter_tenancy_type" @id = "starter_tenancy_type"
@depends_on = [{ "startertenancy" => 1 }] @depends_on = [{ "starter_tenancy?" => true }]
end end
def questions def questions
@questions ||= [ @questions ||= [
Form::Lettings::Questions::StarterTenancy.new(nil, nil, self), Form::Lettings::Questions::StarterTenancyType.new(nil, nil, self),
Form::Lettings::Questions::TenancyOther.new(nil, nil, self), Form::Lettings::Questions::TenancyOther.new(nil, nil, self),
] ]
end end

2
app/models/form/lettings/pages/tenancy_length.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::TenancyLength < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "tenancy_length" @id = "tenancy_length"
@depends_on = [{ "tenancy" => 4 }, { "tenancy" => 6 }, { "tenancy" => 3 }] @depends_on = [{ "tenancy_type_fixed_term_or_other?" => true }]
end end
def questions def questions

2
app/models/form/lettings/pages/tenancy_type.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::TenancyType < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "tenancy_type" @id = "tenancy_type"
@depends_on = [{ "startertenancy" => 2 }] @depends_on = [{ "starter_tenancy?" => false }]
end end
def questions def questions

2
app/models/form/lettings/questions/starter_tenancy.rb → app/models/form/lettings/questions/starter_tenancy_type.rb

@ -1,4 +1,4 @@
class Form::Lettings::Questions::StarterTenancy < ::Form::Question class Form::Lettings::Questions::StarterTenancyType < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "tenancy" @id = "tenancy"

8
app/models/lettings_log.rb

@ -201,6 +201,14 @@ class LettingsLog < Log
renewal == 1 renewal == 1
end end
def starter_tenancy?
startertenancy == 1
end
def tenancy_type_fixed_term_or_other?
[4, 6, 3].include? tenancy
end
def is_general_needs? def is_general_needs?
# 1: General Needs # 1: General Needs
needstype == 1 needstype == 1

31
spec/models/form/lettings/pages/starter_tenancy_type_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::StarterTenancyType, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[tenancy tenancyother])
end
it "has the correct id" do
expect(page.id).to eq("starter_tenancy_type")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct depends_on" do
expect(page.depends_on).to eq([{ "starter_tenancy?" => true }])
end
end

31
spec/models/form/lettings/pages/tenancy_length_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::TenancyLength, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq subsection
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq %w[tenancylength]
end
it "has the correct id" do
expect(page.id).to eq "tenancy_length"
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct depends_on" do
expect(page.depends_on).to eq [{ "tenancy_type_fixed_term_or_other?" => true }]
end
end

31
spec/models/form/lettings/pages/tenancy_type_spec.rb

@ -0,0 +1,31 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::TenancyType, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq %w[tenancy tenancyother]
end
it "has the correct id" do
expect(page.id).to eq "tenancy_type"
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct depends_on" do
expect(page.depends_on).to eq [{ "starter_tenancy?" => false }]
end
end
Loading…
Cancel
Save