Browse Source

CLDC-651 refused derived variable (#396)

* refused derived variable

* add helper methods

* update schema

* fix failing spec
pull/418/head
Dushan 3 years ago committed by GitHub
parent
commit
a23ddc6070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      app/models/case_log.rb
  2. 7
      db/migrate/20220317103029_add_refused_field.rb
  3. 1
      db/schema.rb
  4. 1
      spec/fixtures/exports/case_logs.xml
  5. 19
      spec/models/case_log_spec.rb

23
app/models/case_log.rb

@ -358,6 +358,7 @@ private
self.totchild = get_totchild
self.totelder = get_totelder
self.totadult = get_totadult
self.refused = get_refused
if %i[brent scharge pscharge supcharg].any? { |f| public_send(f).present? }
self.brent ||= 0
self.scharge ||= 0
@ -451,6 +452,12 @@ private
end
end
def get_refused
return 1 if age_refused? || sex_refused? || relat_refused? || ecstat_refused?
0
end
def get_inferred_la(postcode)
postcode_lookup = nil
begin
@ -529,4 +536,20 @@ private
def mandatory_fields
form.questions.map(&:id).difference(OPTIONAL_FIELDS, dynamically_not_required)
end
def age_refused?
[age1_known, age2_known, age3_known, age4_known, age5_known, age6_known, age7_known, age8_known].any?(1)
end
def sex_refused?
[sex1, sex2, sex3, sex4, sex5, sex6, sex7, sex8].any?("R")
end
def relat_refused?
[relat2, relat3, relat4, relat5, relat6, relat7, relat8].any?(3)
end
def ecstat_refused?
[ecstat1, ecstat2, ecstat3, ecstat4, ecstat5, ecstat6, ecstat7, ecstat8].any?(10)
end
end

7
db/migrate/20220317103029_add_refused_field.rb

@ -0,0 +1,7 @@
class AddRefusedField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :refused, :integer
end
end
end

1
db/schema.rb

@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.decimal "wsupchrg", precision: 10, scale: 2
t.decimal "wtcharge", precision: 10, scale: 2
t.decimal "wtshortfall", precision: 10, scale: 2
t.integer "refused"
t.integer "housingneeds"
t.integer "vday"
t.integer "vmonth"

1
spec/fixtures/exports/case_logs.xml vendored

@ -166,6 +166,7 @@
<wsupchrg>17.5</wsupchrg>
<wtcharge>162.5</wtcharge>
<wtshortfall>6.0</wtshortfall>
<refused>0</refused>
<housingneeds>1</housingneeds>
<vday>3</vday>
<vmonth>11</vmonth>

19
spec/models/case_log_spec.rb

@ -1378,6 +1378,25 @@ RSpec.describe CaseLog do
end
end
context "when answering the household characteristics questions" do
let!(:case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
age1_known: 1,
sex1: "R",
relat2: 3,
ecstat1: 10,
})
end
it "correctly derives and saves refused" do
record_from_db = ActiveRecord::Base.connection.execute("select refused from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["refused"]).to eq(1)
expect(case_log["refused"]).to eq(1)
end
end
context "when the data provider is filling in household needs" do
let!(:case_log) do
described_class.create({

Loading…
Cancel
Save