Browse Source

derive exday, exmonth and exyear, tests and lint

pull/1112/head
Kat 3 years ago
parent
commit
30a438a918
  1. 5
      app/models/derived_variables/sales_log_variables.rb
  2. 2
      app/models/form/sales/pages/exchange_date.rb
  3. 2
      spec/models/form/sales/pages/exchange_date_spec.rb
  4. 15
      spec/models/sales_log_spec.rb

5
app/models/derived_variables/sales_log_variables.rb

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

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

@ -6,7 +6,7 @@ class Form::Sales::Pages::ExchangeDate < ::Form::Page
@description = ""
@subsection = subsection
@depends_on = [{
"resale" => 2
"resale" => 2,
}]
end

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

@ -29,7 +29,7 @@ RSpec.describe Form::Sales::Pages::ExchangeDate, type: :model do
it "has the correct depends_on" do
expect(page.depends_on).to eq([{
"resale" => 2
"resale" => 2,
}])
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)
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

Loading…
Cancel
Save