Browse Source

We don't need to reload if we're fetching from DB anyway

pull/199/head
baarkerlounger 3 years ago
parent
commit
92a806f034
  1. 27
      spec/models/case_log_spec.rb

27
spec/models/case_log_spec.rb

@ -1040,24 +1040,18 @@ RSpec.describe Form, type: :model do
end end
it "correctly derives and saves partial and full postcodes" do it "correctly derives and saves partial and full postcodes" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select postcode, postcod2 from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select postcode, postcod2 from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["postcode"]).to eq("M1") expect(record_from_db["postcode"]).to eq("M1")
expect(record_from_db["postcod2"]).to eq("1AE") expect(record_from_db["postcod2"]).to eq("1AE")
end end
it "correctly derives and saves partial and full previous postcodes" do it "correctly derives and saves partial and full previous postcodes" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select ppostc1, ppostc2 from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select ppostc1, ppostc2 from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["ppostc1"]).to eq("M2") expect(record_from_db["ppostc1"]).to eq("M2")
expect(record_from_db["ppostc2"]).to eq("2AE") expect(record_from_db["ppostc2"]).to eq("2AE")
end end
it "correctly derives and saves partial and full major repairs date" do it "correctly derives and saves partial and full major repairs date" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select mrcday, mrcmonth, mrcyear, mrcdate from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select mrcday, mrcmonth, mrcyear, mrcdate from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["mrcdate"].day).to eq(4) expect(record_from_db["mrcdate"].day).to eq(4)
expect(record_from_db["mrcdate"].month).to eq(5) expect(record_from_db["mrcdate"].month).to eq(5)
@ -1068,38 +1062,28 @@ RSpec.describe Form, type: :model do
end end
it "correctly derives and saves incref" do it "correctly derives and saves incref" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select incref from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select incref from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["incref"]).to eq(1) expect(record_from_db["incref"]).to eq(1)
end end
it "correctly derives and saves hhmemb" do it "correctly derives and saves hhmemb" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select hhmemb from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select hhmemb from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["hhmemb"]).to eq(7) expect(record_from_db["hhmemb"]).to eq(7)
end end
it "correctly derives and saves renttype" do it "correctly derives and saves renttype" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select renttype from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select renttype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.renttype).to eq("Intermediate Rent") expect(case_log.renttype).to eq("Intermediate Rent")
expect(record_from_db["renttype"]).to eq(3) expect(record_from_db["renttype"]).to eq(3)
end end
it "correctly derives and saves lettype" do it "correctly derives and saves lettype" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq("Intermediate Rent General needs PRP") expect(case_log.lettype).to eq("Intermediate Rent General needs PRP")
expect(record_from_db["lettype"]).to eq(9) expect(record_from_db["lettype"]).to eq(9)
end end
it "correctly derives and saves day, month, year from start date" do it "correctly derives and saves day, month, year from start date" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select day, month, year, startdate from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select day, month, year, startdate from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["startdate"].day).to eq(10) expect(record_from_db["startdate"].day).to eq(10)
expect(record_from_db["startdate"].month).to eq(10) expect(record_from_db["startdate"].month).to eq(10)
@ -1125,8 +1109,6 @@ RSpec.describe Form, type: :model do
end end
it "correctly infers la" do it "correctly infers la" do
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select la from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log.la).to eq("Manchester") expect(address_case_log.la).to eq("Manchester")
expect(record_from_db["la"]).to eq("E08000003") expect(record_from_db["la"]).to eq("E08000003")
@ -1139,7 +1121,6 @@ RSpec.describe Form, type: :model do
it "correctly resets all fields if property postcode not known" do it "correctly resets all fields if property postcode not known" do
address_case_log.update!({ postcode_known: "No" }) address_case_log.update!({ postcode_known: "No" })
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["property_postcode"]).to eq(nil) expect(record_from_db["property_postcode"]).to eq(nil)
@ -1150,7 +1131,6 @@ RSpec.describe Form, type: :model do
it "changes the LA if property postcode changes from not known to known and provided" do it "changes the LA if property postcode changes from not known to known and provided" do
address_case_log.update!({ postcode_known: "No" }) address_case_log.update!({ postcode_known: "No" })
address_case_log.update!({ la: "Westminster" }) address_case_log.update!({ la: "Westminster" })
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["property_postcode"]).to eq(nil) expect(record_from_db["property_postcode"]).to eq(nil)
@ -1158,7 +1138,6 @@ RSpec.describe Form, type: :model do
expect(record_from_db["la"]).to eq("E09000033") expect(record_from_db["la"]).to eq("E09000033")
address_case_log.update!({ postcode_known: "Yes", property_postcode: "M1 1AD" }) address_case_log.update!({ postcode_known: "Yes", property_postcode: "M1 1AD" })
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["property_postcode"]).to eq("M1 1AD") expect(record_from_db["property_postcode"]).to eq("M1 1AD")
@ -1218,22 +1197,16 @@ RSpec.describe Form, type: :model do
end end
it "correctly derives and saves totchild" do it "correctly derives and saves totchild" do
household_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select totchild from case_logs where id=#{household_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select totchild from case_logs where id=#{household_case_log.id}").to_a[0]
expect(record_from_db["totchild"]).to eq(3) expect(record_from_db["totchild"]).to eq(3)
end end
it "correctly derives and saves totelder" do it "correctly derives and saves totelder" do
household_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select totelder from case_logs where id=#{household_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select totelder from case_logs where id=#{household_case_log.id}").to_a[0]
expect(record_from_db["totelder"]).to eq(2) expect(record_from_db["totelder"]).to eq(2)
end end
it "correctly derives and saves totadult" do it "correctly derives and saves totadult" do
household_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select totadult from case_logs where id=#{household_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select totadult from case_logs where id=#{household_case_log.id}").to_a[0]
expect(record_from_db["totadult"]).to eq(3) expect(record_from_db["totadult"]).to eq(3)
end end

Loading…
Cancel
Save