Browse Source

Cldc 1535 exchange contracts (#1112)

* Add exdate to sales logs table

* Add exchange date page and question

* Add exchange contracts page to the shared ownership subsection

* derive exday, exmonth and exyear, tests and lint

* rebase tests
pull/1115/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
a2b61b9ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/derived_variables/sales_log_variables.rb
  2. 18
      app/models/form/sales/pages/exchange_date.rb
  3. 10
      app/models/form/sales/questions/exchange_date.rb
  4. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  5. 11
      db/migrate/20221221122233_add_exchange_contracts_to_sales.rb
  6. 7
      db/schema.rb
  7. 35
      spec/models/form/sales/pages/exchange_date_spec.rb
  8. 33
      spec/models/form/sales/questions/exchange_date_spec.rb
  9. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  10. 4
      spec/models/form_handler_spec.rb
  11. 15
      spec/models/sales_log_spec.rb

5
app/models/derived_variables/sales_log_variables.rb

@ -1,5 +1,10 @@
module DerivedVariables::SalesLogVariables module DerivedVariables::SalesLogVariables
def set_derived_fields! def set_derived_fields!
self.ethnic = 17 if ethnic_refused? self.ethnic = 17 if ethnic_refused?
if exdate.present?
self.exday = exdate.day
self.exmonth = exdate.month
self.exyear = exdate.year
end
end end
end end

18
app/models/form/sales/pages/exchange_date.rb

@ -0,0 +1,18 @@
class Form::Sales::Pages::ExchangeDate < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "exchange_contracts"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"resale" => 2,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::ExchangeDate.new(nil, nil, self),
]
end
end

10
app/models/form/sales/questions/exchange_date.rb

@ -0,0 +1,10 @@
class Form::Sales::Questions::ExchangeDate < ::Form::Question
def initialize(id, hsh, page)
super
@id = "exdate"
@check_answer_label = "Exchange of contracts date"
@header = "What is the exchange of contracts date?"
@type = "date"
@page = page
end
end

1
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -13,6 +13,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutStaircase.new(nil, nil, self), Form::Sales::Pages::AboutStaircase.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
Form::Sales::Pages::ExchangeDate.new(nil, nil, self),
] ]
end end

11
db/migrate/20221221122233_add_exchange_contracts_to_sales.rb

@ -0,0 +1,11 @@
class AddExchangeContractsToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :exdate, :datetime
t.column :exday, :integer
t.column :exmonth, :integer
t.column :exyear, :integer
t.column :resale, :integer
end
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_12_21_105502) do ActiveRecord::Schema[7.0].define(version: 2022_12_21_122233) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -420,6 +420,11 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_21_105502) do
t.integer "stairbought" t.integer "stairbought"
t.integer "stairowned" t.integer "stairowned"
t.decimal "mrent", precision: 10, scale: 2 t.decimal "mrent", precision: 10, scale: 2
t.datetime "exdate", precision: nil
t.integer "exday"
t.integer "exmonth"
t.integer "exyear"
t.integer "resale"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

35
spec/models/form/sales/pages/exchange_date_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::ExchangeDate, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
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[exdate])
end
it "has the correct id" do
expect(page.id).to eq("exchange_contracts")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has the correct depends_on" do
expect(page.depends_on).to eq([{
"resale" => 2,
}])
end
end

33
spec/models/form/sales/questions/exchange_date_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::ExchangeDate, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("exdate")
end
it "has the correct header" do
expect(question.header).to eq("What is the exchange of contracts date?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Exchange of contracts date")
end
it "has the correct type" do
expect(question.type).to eq("date")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
end

1
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -18,6 +18,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
about_staircasing about_staircasing
previous_bedrooms previous_bedrooms
monthly_rent monthly_rent
exchange_contracts
], ],
) )
end end

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(72) expect(form.pages.count).to eq(73)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(72) expect(form.pages.count).to eq(73)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

15
spec/models/sales_log_spec.rb

@ -90,4 +90,19 @@ RSpec.describe SalesLog, type: :model do
expect(described_class.filter_by_organisation([organisation_3]).count).to eq(0) expect(described_class.filter_by_organisation([organisation_3]).count).to eq(0)
end end
end end
describe "derived variables" do
let!(:sales_log) do
described_class.create({
exdate: Time.gm(2022, 5, 4),
})
end
it "correctly derives and saves exday, exmonth and exyear" do
record_from_db = ActiveRecord::Base.connection.execute("select exday, exmonth, exyear from sales_logs where id=#{sales_log.id}").to_a[0]
expect(record_from_db["exday"]).to eq(4)
expect(record_from_db["exmonth"]).to eq(5)
expect(record_from_db["exyear"]).to eq(2022)
end
end
end end

Loading…
Cancel
Save