Browse Source

Move period creation to log

pull/2490/head
Kat 2 years ago
parent
commit
c481ba0a7b
  1. 7
      spec/factories/lettings_log.rb
  2. 12
      spec/factories/organisation.rb
  3. 2
      spec/helpers/organisations_helper_spec.rb
  4. 2
      spec/models/form/lettings/questions/period_spec.rb
  5. 4
      spec/models/lettings_log_derived_fields_spec.rb
  6. 2
      spec/models/organisation_spec.rb
  7. 2
      spec/models/validations/financial_validations_spec.rb
  8. 4
      spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb
  9. 8
      spec/services/merge/merge_organisations_service_spec.rb

7
spec/factories/lettings_log.rb

@ -6,6 +6,13 @@ FactoryBot.define do
managing_organisation { assigned_to.organisation } managing_organisation { assigned_to.organisation }
created_at { Time.zone.today } created_at { Time.zone.today }
updated_at { Time.zone.today } updated_at { Time.zone.today }
before(:create) do |log, _evaluator|
if log.period && !log.managing_organisation.organisation_rent_periods.exists?(rent_period: log.period)
log.managing_organisation.organisation_rent_periods << build(:organisation_rent_period, rent_period: log.period)
end
end
trait :setup_completed do trait :setup_completed do
startdate_today startdate_today
renewal { 0 } renewal { 0 }

12
spec/factories/organisation.rb

@ -14,18 +14,6 @@ FactoryBot.define do
with_dsa { true } with_dsa { true }
end end
transient do
skip_rent_period_creation { false }
end
after(:build) do |organisation, evaluator|
unless evaluator.skip_rent_period_creation
(1..11).each do |rent_period|
organisation.organisation_rent_periods << build(:organisation_rent_period, organisation:, rent_period:)
end
end
end
after(:create) do |org, evaluator| after(:create) do |org, evaluator|
if evaluator.with_dsa if evaluator.with_dsa
create( create(

2
spec/helpers/organisations_helper_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe OrganisationsHelper do RSpec.describe OrganisationsHelper do
include TagHelper include TagHelper
describe "display_organisation_attributes" do describe "display_organisation_attributes" do
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } let(:organisation) { create(:organisation) }
it "has the correct values" do it "has the correct values" do
expect(display_organisation_attributes(organisation)).to eq( expect(display_organisation_attributes(organisation)).to eq(

2
spec/models/form/lettings/questions/period_spec.rb

@ -28,7 +28,7 @@ RSpec.describe Form::Lettings::Questions::Period, type: :model do
end end
context "when managing organisation has rent periods" do context "when managing organisation has rent periods" do
let(:managing_organisation) { create(:organisation, skip_rent_period_creation: true) } let(:managing_organisation) { create(:organisation) }
let(:log) { create(:lettings_log, managing_organisation:) } let(:log) { create(:lettings_log, managing_organisation:) }
before do before do

4
spec/models/lettings_log_derived_fields_spec.rb

@ -2,7 +2,7 @@ require "rails_helper"
require "shared/shared_examples_for_derived_fields" require "shared/shared_examples_for_derived_fields"
RSpec.describe LettingsLog, type: :model do RSpec.describe LettingsLog, type: :model do
let(:organisation) { build(:organisation, name: "derived fields org", skip_rent_period_creation: true) } let(:organisation) { build(:organisation, name: "derived fields org") }
let(:user) { build(:user, organisation:) } let(:user) { build(:user, organisation:) }
let(:log) { build(:lettings_log, :startdate_today, assigned_to: user) } let(:log) { build(:lettings_log, :startdate_today, assigned_to: user) }
@ -956,7 +956,7 @@ RSpec.describe LettingsLog, type: :model do
end end
describe "variables dependent on whether a letting is a renewal" do describe "variables dependent on whether a letting is a renewal" do
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } let(:organisation) { create(:organisation) }
let(:user) { create(:user, organisation:) } let(:user) { create(:user, organisation:) }
let(:startdate) { Time.zone.today } let(:startdate) { Time.zone.today }
let(:persisted_renewal_lettings_log) { create(:lettings_log, :setup_completed, startdate:, renewal: 1, assigned_to: user) } let(:persisted_renewal_lettings_log) { create(:lettings_log, :setup_completed, startdate:, renewal: 1, assigned_to: user) }

2
spec/models/organisation_spec.rb

@ -109,7 +109,7 @@ RSpec.describe Organisation, type: :model do
end end
context "with associated rent periods" do context "with associated rent periods" do
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } let(:organisation) { create(:organisation) }
let(:period_1_label) { "Every minute" } let(:period_1_label) { "Every minute" }
let(:fake_rent_periods) do let(:fake_rent_periods) do
{ {

2
spec/models/validations/financial_validations_spec.rb

@ -139,7 +139,7 @@ RSpec.describe Validations::FinancialValidations do
end end
describe "rent period validations" do describe "rent period validations" do
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } let(:organisation) { create(:organisation) }
let(:user) { create(:user, organisation:) } let(:user) { create(:user, organisation:) }
let(:record) { create(:lettings_log, owning_organisation: organisation, managing_organisation: organisation, assigned_to: user) } let(:record) { create(:lettings_log, owning_organisation: organisation, managing_organisation: organisation, assigned_to: user) }
let(:used_period) { 2 } let(:used_period) { 2 }

4
spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb

@ -53,7 +53,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
describe "#edit" do describe "#edit" do
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } let(:organisation) { create(:organisation) }
let(:fake_rent_periods) do let(:fake_rent_periods) do
{ {
"1" => { "value" => "Every minute" }, "1" => { "value" => "Every minute" },
@ -83,7 +83,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
describe "#update" do describe "#update" do
let(:organisation) { create(:organisation, skip_rent_period_creation: true) } let(:organisation) { create(:organisation) }
let(:initially_checked_rent_period_id) { "1" } let(:initially_checked_rent_period_id) { "1" }
let(:initially_unchecked_rent_period_id) { "2" } let(:initially_unchecked_rent_period_id) { "2" }
let(:params) do let(:params) do

8
spec/services/merge/merge_organisations_service_spec.rb

@ -75,8 +75,8 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and merging organisation rent periods" do context "and merging organisation rent periods" do
let(:absorbing_organisation) { create(:organisation, holds_own_stock: false, name: "absorbing org", skip_rent_period_creation: true) } let(:absorbing_organisation) { create(:organisation, holds_own_stock: false, name: "absorbing org") }
let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org", skip_rent_period_creation: true) } let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org") }
before do before do
OrganisationRentPeriod.create!(organisation: absorbing_organisation, rent_period: 1) OrganisationRentPeriod.create!(organisation: absorbing_organisation, rent_period: 1)
@ -1160,8 +1160,8 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and merging organisation rent periods" do context "and merging organisation rent periods" do
let(:new_absorbing_organisation) { create(:organisation, :without_dpc, holds_own_stock: false, skip_rent_period_creation: true) } let(:new_absorbing_organisation) { create(:organisation, :without_dpc, holds_own_stock: false) }
let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org", skip_rent_period_creation: true) } let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org") }
before do before do
OrganisationRentPeriod.create!(organisation: new_absorbing_organisation, rent_period: 1) OrganisationRentPeriod.create!(organisation: new_absorbing_organisation, rent_period: 1)

Loading…
Cancel
Save