|
|
@ -3,11 +3,12 @@ require "rails_helper" |
|
|
|
RSpec.describe CaseLog do |
|
|
|
RSpec.describe CaseLog do |
|
|
|
let(:owning_organisation) { FactoryBot.create(:organisation) } |
|
|
|
let(:owning_organisation) { FactoryBot.create(:organisation) } |
|
|
|
let(:different_managing_organisation) { FactoryBot.create(:organisation) } |
|
|
|
let(:different_managing_organisation) { FactoryBot.create(:organisation) } |
|
|
|
|
|
|
|
let(:created_by_user) { FactoryBot.create(:user) } |
|
|
|
|
|
|
|
|
|
|
|
describe "#form" do |
|
|
|
describe "#form" do |
|
|
|
let(:case_log) { FactoryBot.build(:case_log) } |
|
|
|
let(:case_log) { FactoryBot.build(:case_log, created_by: created_by_user) } |
|
|
|
let(:case_log_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2022, 1, 1)) } |
|
|
|
let(:case_log_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2022, 1, 1), created_by: created_by_user) } |
|
|
|
let(:case_log_year_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2023, 5, 1)) } |
|
|
|
let(:case_log_year_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2023, 5, 1), created_by: created_by_user) } |
|
|
|
|
|
|
|
|
|
|
|
it "has returns the correct form based on the start date" do |
|
|
|
it "has returns the correct form based on the start date" do |
|
|
|
expect(case_log.form_name).to be_nil |
|
|
|
expect(case_log.form_name).to be_nil |
|
|
@ -19,7 +20,7 @@ RSpec.describe CaseLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when a date outside the collection window is passed" do |
|
|
|
context "when a date outside the collection window is passed" do |
|
|
|
let(:case_log) { FactoryBot.build(:case_log, startdate: Time.zone.local(2015, 1, 1)) } |
|
|
|
let(:case_log) { FactoryBot.build(:case_log, startdate: Time.zone.local(2015, 1, 1), created_by: created_by_user) } |
|
|
|
|
|
|
|
|
|
|
|
it "returns the first form" do |
|
|
|
it "returns the first form" do |
|
|
|
expect(case_log.form).to be_a(Form) |
|
|
|
expect(case_log.form).to be_a(Form) |
|
|
@ -34,6 +35,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create( |
|
|
|
described_class.create( |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -45,7 +47,7 @@ RSpec.describe CaseLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "#update" do |
|
|
|
describe "#update" do |
|
|
|
let(:case_log) { FactoryBot.create(:case_log) } |
|
|
|
let(:case_log) { FactoryBot.create(:case_log, created_by: created_by_user) } |
|
|
|
let(:validator) { case_log._validators[nil].first } |
|
|
|
let(:validator) { case_log._validators[nil].first } |
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
after do |
|
|
@ -199,6 +201,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
postcode_full: "M1 1AE", |
|
|
|
postcode_full: "M1 1AE", |
|
|
|
ppostcode_full: "M2 2AE", |
|
|
|
ppostcode_full: "M2 2AE", |
|
|
|
startdate: Time.gm(2021, 10, 10), |
|
|
|
startdate: Time.gm(2021, 10, 10), |
|
|
@ -1134,6 +1137,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
postcode_known: 1, |
|
|
|
postcode_known: 1, |
|
|
|
postcode_full: "M1 1AE", |
|
|
|
postcode_full: "M1 1AE", |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1221,6 +1225,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
previous_postcode_known: 1, |
|
|
|
previous_postcode_known: 1, |
|
|
|
ppostcode_full: "M1 1AE", |
|
|
|
ppostcode_full: "M1 1AE", |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1305,6 +1310,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
brent: 5.77, |
|
|
|
brent: 5.77, |
|
|
|
scharge: 10.01, |
|
|
|
scharge: 10.01, |
|
|
|
pscharge: 3, |
|
|
|
pscharge: 3, |
|
|
@ -1323,6 +1329,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create!({ |
|
|
|
described_class.create!({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
hhmemb: 3, |
|
|
|
hhmemb: 3, |
|
|
|
relat2: "X", |
|
|
|
relat2: "X", |
|
|
|
relat3: "C", |
|
|
|
relat3: "C", |
|
|
@ -1376,6 +1383,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
renewal: 1, |
|
|
|
renewal: 1, |
|
|
|
startdate: Time.zone.local(2021, 4, 10), |
|
|
|
startdate: Time.zone.local(2021, 4, 10), |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1421,6 +1429,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
age1_known: 1, |
|
|
|
age1_known: 1, |
|
|
|
sex1: "R", |
|
|
|
sex1: "R", |
|
|
|
relat2: "R", |
|
|
|
relat2: "R", |
|
|
@ -1440,6 +1449,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
}) |
|
|
|
}) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -1467,6 +1477,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
needstype: 2, |
|
|
|
needstype: 2, |
|
|
|
}) |
|
|
|
}) |
|
|
|
end |
|
|
|
end |
|
|
@ -1621,6 +1632,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
first_time_property_let_as_social_housing: 1, |
|
|
|
first_time_property_let_as_social_housing: 1, |
|
|
|
}) |
|
|
|
}) |
|
|
|
end |
|
|
|
end |
|
|
@ -1629,6 +1641,7 @@ RSpec.describe CaseLog do |
|
|
|
described_class.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
owning_organisation:, |
|
|
|
owning_organisation:, |
|
|
|
|
|
|
|
created_by: created_by_user, |
|
|
|
first_time_property_let_as_social_housing: 0, |
|
|
|
first_time_property_let_as_social_housing: 0, |
|
|
|
}) |
|
|
|
}) |
|
|
|
end |
|
|
|
end |
|
|
@ -1799,8 +1812,8 @@ RSpec.describe CaseLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "scopes" do |
|
|
|
describe "scopes" do |
|
|
|
let!(:case_log_1) { FactoryBot.create(:case_log, :in_progress, startdate: Time.utc(2021, 5, 3)) } |
|
|
|
let!(:case_log_1) { FactoryBot.create(:case_log, :in_progress, startdate: Time.utc(2021, 5, 3), created_by: created_by_user) } |
|
|
|
let!(:case_log_2) { FactoryBot.create(:case_log, :completed, startdate: Time.utc(2021, 5, 3)) } |
|
|
|
let!(:case_log_2) { FactoryBot.create(:case_log, :completed, startdate: Time.utc(2021, 5, 3), created_by: created_by_user) } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
FactoryBot.create(:case_log, startdate: Time.utc(2022, 6, 3)) |
|
|
|
FactoryBot.create(:case_log, startdate: Time.utc(2022, 6, 3)) |
|
|
@ -1839,23 +1852,21 @@ RSpec.describe CaseLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when filtering by user" do |
|
|
|
context "when filtering by user" do |
|
|
|
let!(:user) { FactoryBot.create(:user) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
PaperTrail::Version.find_by(item_id: case_log_1.id, event: "create").update!(whodunnit: user.to_global_id.uri.to_s) |
|
|
|
PaperTrail::Version.find_by(item_id: case_log_1.id, event: "create").update!(whodunnit: created_by_user.to_global_id.uri.to_s) |
|
|
|
PaperTrail::Version.find_by(item_id: case_log_2.id, event: "create").update!(whodunnit: user.to_global_id.uri.to_s) |
|
|
|
PaperTrail::Version.find_by(item_id: case_log_2.id, event: "create").update!(whodunnit: created_by_user.to_global_id.uri.to_s) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "allows filtering on current user" do |
|
|
|
it "allows filtering on current user" do |
|
|
|
expect(described_class.filter_by_user(%w[yours], user).count).to eq(2) |
|
|
|
expect(described_class.filter_by_user(%w[yours], created_by_user).count).to eq(2) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "returns all logs when all logs selected" do |
|
|
|
it "returns all logs when all logs selected" do |
|
|
|
expect(described_class.filter_by_user(%w[all], user).count).to eq(3) |
|
|
|
expect(described_class.filter_by_user(%w[all], created_by_user).count).to eq(3) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "returns all logs when all and your users selected" do |
|
|
|
it "returns all logs when all and your users selected" do |
|
|
|
expect(described_class.filter_by_user(%w[all yours], user).count).to eq(3) |
|
|
|
expect(described_class.filter_by_user(%w[all yours], created_by_user).count).to eq(3) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|