diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 4ea6a905f..7834e0dad 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -13,8 +13,7 @@ RSpec.describe "Form Check Answers Page" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, needstype: 2, scheme:, location:, @@ -26,8 +25,7 @@ RSpec.describe "Form Check Answers Page" do previous_la_known: 1, prevloc: "E09000033", is_previous_la_inferred: false, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:completed_lettings_log) do @@ -36,6 +34,7 @@ RSpec.describe "Form Check Answers Page" do :completed, owning_organisation: user.organisation, managing_organisation: user.organisation, + created_by: user, startdate: Time.zone.local(2021, 5, 1), ) end @@ -190,8 +189,7 @@ RSpec.describe "Form Check Answers Page" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, tenancycode: "123", age1: 35, sex1: "M", @@ -203,8 +201,7 @@ RSpec.describe "Form Check Answers Page" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, tenancycode: "123", age1: 35, sex1: "M", @@ -218,8 +215,7 @@ RSpec.describe "Form Check Answers Page" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, tenancycode: "123", age1: 35, sex1: "M", @@ -236,8 +232,6 @@ RSpec.describe "Form Check Answers Page" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, created_by: user, needstype: 1, tenancycode: nil, diff --git a/spec/features/form/checkboxes_spec.rb b/spec/features/form/checkboxes_spec.rb index d3e3671eb..8f3f4ad65 100644 --- a/spec/features/form/checkboxes_spec.rb +++ b/spec/features/form/checkboxes_spec.rb @@ -9,8 +9,7 @@ RSpec.describe "Checkboxes" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:id) { lettings_log.id } diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index 07a660321..4fc9387da 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -8,16 +8,14 @@ RSpec.describe "Form Conditional Questions" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:sales_log) do FactoryBot.create( :sales_log, :completed, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:id) { lettings_log.id } diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index b60c2dd03..eb4f6acc2 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -8,8 +8,7 @@ RSpec.describe "Form Page Routing" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:id) { lettings_log.id } @@ -120,6 +119,7 @@ RSpec.describe "Form Page Routing" do :lettings_log, owning_organisation: user.organisation, managing_organisation: user.organisation, + created_by: user, needstype: 2, ) end diff --git a/spec/features/form/progressive_total_field_spec.rb b/spec/features/form/progressive_total_field_spec.rb index 77edfbedd..e5959d16d 100644 --- a/spec/features/form/progressive_total_field_spec.rb +++ b/spec/features/form/progressive_total_field_spec.rb @@ -8,8 +8,7 @@ RSpec.describe "Accessible Automcomplete" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index a0889e9a4..7a7996457 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -8,8 +8,7 @@ RSpec.describe "Form Saving Data" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:id) { lettings_log.id } @@ -17,8 +16,7 @@ RSpec.describe "Form Saving Data" do FactoryBot.create( :lettings_log, :in_progress, housingneeds_a: 1, - owning_organisation: user.organisation, - managing_organisation: user.organisation + created_by: user ) end let(:question_answers) do diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 9df179937..24b2816ce 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -8,24 +8,21 @@ RSpec.describe "validations" do FactoryBot.create( :lettings_log, :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, renewal: 0, ) end let(:empty_lettings_log) do FactoryBot.create( :lettings_log, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:completed_without_declaration) do FactoryBot.create( :lettings_log, :completed, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, status: 1, declaration: nil, startdate: Time.zone.local(2021, 5, 1), @@ -124,8 +121,7 @@ RSpec.describe "validations" do :lettings_log, :in_progress, ecstat1: 1, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end let(:income_over_soft_limit) { 750 } diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index 09d6130e4..9d2478d9f 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -136,8 +136,8 @@ RSpec.describe "User Features" do context "when viewing lettings logs for specific organisation" do let(:first_log) { organisation.lettings_logs.first } - let!(:log_to_search) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation, managing_organisation_id: organisation.id) } - let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) } + let!(:log_to_search) { FactoryBot.create(:lettings_log, created_by: user) } + let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user) } let(:number_of_lettings_logs) { LettingsLog.count } before do diff --git a/spec/helpers/interruption_screen_helper_spec.rb b/spec/helpers/interruption_screen_helper_spec.rb index 4984a0450..8153b9d7b 100644 --- a/spec/helpers/interruption_screen_helper_spec.rb +++ b/spec/helpers/interruption_screen_helper_spec.rb @@ -12,8 +12,7 @@ RSpec.describe InterruptionScreenHelper do ecstat1: 1, earnings: 750, incfreq: 1, - owning_organisation: user.organisation, - managing_organisation: user.organisation, + created_by: user, ) end diff --git a/spec/jobs/email_csv_job_spec.rb b/spec/jobs/email_csv_job_spec.rb index f4939b855..5ff0b3355 100644 --- a/spec/jobs/email_csv_job_spec.rb +++ b/spec/jobs/email_csv_job_spec.rb @@ -19,8 +19,7 @@ describe EmailCsvJob do let!(:lettings_log) do FactoryBot.create( :lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ecstat1: 1, ) end @@ -31,8 +30,6 @@ describe EmailCsvJob do before do FactoryBot.create(:lettings_log, :completed, - owning_organisation: organisation, - managing_organisation: organisation, created_by: user, startdate: Time.zone.local(2021, 5, 1)) diff --git a/spec/models/form/lettings/questions/created_by_id_spec.rb b/spec/models/form/lettings/questions/created_by_id_spec.rb index 84ee4156a..b1ee1de49 100644 --- a/spec/models/form/lettings/questions/created_by_id_spec.rb +++ b/spec/models/form/lettings/questions/created_by_id_spec.rb @@ -71,6 +71,7 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do let(:lettings_log) do create( :lettings_log, + created_by: user_2, owning_organisation: user_2.organisation, managing_organisation: user_3.organisation, ) diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 1dd61f4b2..c5787f9e0 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -151,7 +151,6 @@ RSpec.describe Organisation, type: :model do FactoryBot.create( :lettings_log, :completed, - owning_organisation: organisation, managing_organisation: other_organisation, created_by: user, ) @@ -159,8 +158,7 @@ RSpec.describe Organisation, type: :model do let!(:managed_lettings_log) do FactoryBot.create( :lettings_log, - owning_organisation: other_organisation, - managing_organisation: organisation, + created_by: user, ) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bd6555348..fd132a8ef 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -8,7 +8,6 @@ RSpec.describe User, type: :model do FactoryBot.create( :lettings_log, :completed, - owning_organisation: user.organisation, managing_organisation: other_organisation, created_by: user, ) @@ -16,8 +15,8 @@ RSpec.describe User, type: :model do let!(:managed_lettings_log) do FactoryBot.create( :lettings_log, + created_by: user, owning_organisation: other_organisation, - managing_organisation: user.organisation, ) end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index b54f3cbf7..a1ed9846e 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -4,12 +4,12 @@ RSpec.describe FormController, type: :request do let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { create(:user) } let(:organisation) { user.organisation } - let(:other_organisation) { create(:organisation) } + let(:other_user) { create(:user) } + let(:other_organisation) { other_user.organisation } let!(:unauthorized_lettings_log) do create( :lettings_log, - owning_organisation: other_organisation, - managing_organisation: other_organisation, + created_by: other_user, ) end let(:setup_complete_lettings_log) do @@ -18,16 +18,14 @@ RSpec.describe FormController, type: :request do :about_completed, status: 1, startdate: Time.zone.local(2021, 10, 10), - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ) end let(:completed_lettings_log) do create( :lettings_log, :completed, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, startdate: Time.zone.local(2021, 5, 1), ) end @@ -43,8 +41,7 @@ RSpec.describe FormController, type: :request do let!(:lettings_log) do create( :lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ) end @@ -72,8 +69,7 @@ RSpec.describe FormController, type: :request do let!(:lettings_log) do create( :lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ) end @@ -156,8 +152,7 @@ RSpec.describe FormController, type: :request do create( :lettings_log, startdate: Time.zone.local(2022, 12, 1), - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ) end let(:headers) { { "Accept" => "text/html" } } @@ -224,8 +219,7 @@ RSpec.describe FormController, type: :request do let(:lettings_log) do create( :lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ) end let(:page_id) { "person_1_age" } @@ -566,12 +560,11 @@ RSpec.describe FormController, type: :request do context "with lettings logs that are not owned or managed by your organisation" do let(:answer) { 25 } - let(:other_organisation) { create(:organisation) } + let(:other_user) { create(:user) } let(:unauthorized_lettings_log) do create( :lettings_log, - owning_organisation: other_organisation, - managing_organisation: other_organisation, + created_by: other_user, ) end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 0cee5d7b3..862f82fa1 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -150,20 +150,19 @@ RSpec.describe LettingsLogsController, type: :request do let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { FactoryBot.create(:user) } let(:organisation) { user.organisation } - let(:other_organisation) { FactoryBot.create(:organisation) } + let(:other_user) { FactoryBot.create(:user) } + let(:other_organisation) { other_user.organisation } let!(:lettings_log) do FactoryBot.create( :lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, tenancycode: "LC783", ) end let!(:unauthorized_lettings_log) do FactoryBot.create( :lettings_log, - owning_organisation: other_organisation, - managing_organisation: other_organisation, + created_by: other_user, tenancycode: "UA984", ) end @@ -266,9 +265,8 @@ RSpec.describe LettingsLogsController, type: :request do context "with year filter" do let!(:lettings_log_2021) do FactoryBot.create(:lettings_log, :in_progress, - owning_organisation: organisation, - startdate: Time.zone.local(2022, 3, 1), - managing_organisation: organisation) + created_by: user, + startdate: Time.zone.local(2022, 3, 1)) end let!(:lettings_log_2022) do lettings_log = FactoryBot.build(:lettings_log, :completed, @@ -567,7 +565,7 @@ RSpec.describe LettingsLogsController, type: :request do context "when there are more than 20 logs" do before do - FactoryBot.create_list(:lettings_log, 25, owning_organisation: organisation, managing_organisation: organisation) + FactoryBot.create_list(:lettings_log, 25, created_by: user) end context "when on the first page" do @@ -699,8 +697,7 @@ RSpec.describe LettingsLogsController, type: :request do FactoryBot.create( :lettings_log, :conditional_section_complete, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, ) end @@ -756,8 +753,7 @@ RSpec.describe LettingsLogsController, type: :request do context "when accessing the check answers page" do let(:postcode_lettings_log) do FactoryBot.create(:lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, postcode_known: "No") end let(:id) { postcode_lettings_log.id } @@ -771,8 +767,7 @@ RSpec.describe LettingsLogsController, type: :request do it "shows the inferred la" do lettings_log = FactoryBot.create(:lettings_log, - owning_organisation: organisation, - managing_organisation: organisation, + created_by: user, postcode_known: 1, postcode_full: "PO5 3TE") id = lettings_log.id @@ -1096,8 +1091,7 @@ RSpec.describe LettingsLogsController, type: :request do let!(:lettings_log) do FactoryBot.create( :lettings_log, - owning_organisation:, - managing_organisation: owning_organisation, + created_by: user, ecstat1: 1, ) end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 797b7600e..ab5dcb6af 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -590,8 +590,8 @@ RSpec.describe OrganisationsController, type: :request do let(:number_of_org2_lettings_logs) { 4 } before do - FactoryBot.create_list(:lettings_log, number_of_org1_lettings_logs, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) - FactoryBot.create_list(:lettings_log, number_of_org2_lettings_logs, owning_organisation_id: unauthorised_organisation.id, managing_organisation_id: unauthorised_organisation.id) + FactoryBot.create_list(:lettings_log, number_of_org1_lettings_logs, created_by: user) + FactoryBot.create_list(:lettings_log, number_of_org2_lettings_logs, created_by: nil, owning_organisation_id: unauthorised_organisation.id, managing_organisation_id: unauthorised_organisation.id) get "/organisations/#{organisation.id}/lettings-logs", headers:, params: {} end