diff --git a/spec/controllers/modules/search_filter_spec.rb b/spec/controllers/modules/search_filter_spec.rb index b46878d82..52d9f0cd1 100644 --- a/spec/controllers/modules/search_filter_spec.rb +++ b/spec/controllers/modules/search_filter_spec.rb @@ -49,7 +49,7 @@ RSpec.describe Modules::SearchFilter do let(:search_term) { nil } it "returns all the users" do - expect(instance.filtered_users(user_list, search_term).count).to eq(7) + expect(instance.filtered_users(user_list, search_term).count).to eq(user_list.count) end end end diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index 464f67d49..7f1e77d2a 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -85,7 +85,7 @@ RSpec.describe "Lettings Log Features" do click_link("Set up this lettings log") select(support_user.organisation.name, from: "lettings-log-owning-organisation-id-field") click_button("Save and continue") - select(support_user.name, from: "lettings-log-created-by-id-field") + select("#{support_user.name} (#{support_user.email})", from: "lettings-log-created-by-id-field") click_button("Save and continue") log_id = page.current_path.scan(/\d/).join visit("lettings-logs/#{log_id}/setup/check-answers") @@ -95,7 +95,7 @@ RSpec.describe "Lettings Log Features" do end context "when visiting a subsection check answers page" do - let(:lettings_log) { FactoryBot.create(:lettings_log, :setup_completed) } + let(:lettings_log) { create(:lettings_log, :setup_completed) } it "has the correct breadcrumbs with the correct links" do visit lettings_log_setup_check_answers_path(lettings_log) @@ -108,7 +108,7 @@ RSpec.describe "Lettings Log Features" do end context "when reviewing a complete log" do - let(:lettings_log) { FactoryBot.create(:lettings_log, :completed) } + let(:lettings_log) { create(:lettings_log, :completed) } it "has the correct breadcrumbs with the correct links" do visit review_lettings_log_path(lettings_log) 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 0610e5b2a..ec3fc7a9b 100644 --- a/spec/models/form/lettings/questions/created_by_id_spec.rb +++ b/spec/models/form/lettings/questions/created_by_id_spec.rb @@ -41,6 +41,12 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do expect(question.derived?).to be true end + def expected_option_for_users(users) + users.each_with_object({ "" => "Select an option" }) do |user, obj| + obj[user.id] = "#{user.name} (#{user.email})" + end + end + context "when the current user is support" do let(:owning_org_user) { create(:user) } let(:managing_org_user) { create(:user) } @@ -51,17 +57,8 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do create(:lettings_log, created_by: support_user, owning_organisation: owning_org_user.organisation, managing_organisation: managing_org_user.organisation) end - let(:expected_answer_options) do - { - "" => "Select an option", - managing_org_user.id => "#{managing_org_user.name} (#{managing_org_user.email})", - owning_org_user.id => "#{owning_org_user.name} (#{owning_org_user.email})", - support_user.id => "#{support_user.name} (#{support_user.email})", - } - end - it "only displays users that belong to owning and managing organisations" do - expect(question.displayed_answer_options(lettings_log, support_user)).to eq(expected_answer_options) + expect(question.displayed_answer_options(lettings_log, support_user)).to eq(expected_option_for_users(managing_org_user.organisation.users + owning_org_user.organisation.users)) end end end @@ -77,15 +74,8 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do let(:user_in_same_org) { create(:user, organisation: data_coordinator.organisation) } - let(:expected_answer_options) do - { - "" => "Select an option", - data_coordinator.id => "#{data_coordinator.name} (#{data_coordinator.email})", - } - end - it "only displays users that belong user's org" do - expect(question.displayed_answer_options(lettings_log, data_coordinator)).to eq(expected_answer_options) + expect(question.displayed_answer_options(lettings_log, data_coordinator)).to eq(expected_option_for_users(data_coordinator.organisation.users)) end end end diff --git a/spec/models/form/sales/questions/created_by_id_spec.rb b/spec/models/form/sales/questions/created_by_id_spec.rb index fd0122cb8..29f5b38b8 100644 --- a/spec/models/form/sales/questions/created_by_id_spec.rb +++ b/spec/models/form/sales/questions/created_by_id_spec.rb @@ -37,6 +37,12 @@ RSpec.describe Form::Sales::Questions::CreatedById, type: :model do expect(question.derived?).to be true end + def expected_option_for_users(users) + users.each_with_object({ "" => "Select an option" }) do |user, obj| + obj[user.id] = "#{user.name} (#{user.email})" + end + end + context "when the current user is support" do let(:support_user) { build(:user, :support) } @@ -47,15 +53,9 @@ RSpec.describe Form::Sales::Questions::CreatedById, type: :model do describe "#displayed_answer_options" do let(:owning_org_user) { create(:user) } let(:sales_log) { create(:sales_log, owning_organisation: owning_org_user.organisation) } - let(:expected_answer_options) do - { - "" => "Select an option", - owning_org_user.id => "#{owning_org_user.name} (#{owning_org_user.email})", - } - end it "only displays users that belong to the owning organisation" do - expect(question.displayed_answer_options(sales_log, support_user)).to eq(expected_answer_options) + expect(question.displayed_answer_options(sales_log, support_user)).to eq(expected_option_for_users(owning_org_user.organisation.users)) end end end @@ -70,18 +70,13 @@ RSpec.describe Form::Sales::Questions::CreatedById, type: :model do describe "#displayed_answer_options" do let(:owning_org_user) { create(:user) } let(:sales_log) { create(:sales_log, owning_organisation: owning_org_user.organisation) } - let!(:user_in_same_org) { create(:user, organisation: data_coordinator.organisation) } - - let(:expected_answer_options) do - { - "" => "Select an option", - user_in_same_org.id => "#{user_in_same_org.name} (#{user_in_same_org.email})", - data_coordinator.id => "#{data_coordinator.name} (#{data_coordinator.email})", - } + + before do + create(:user, organisation: data_coordinator.organisation) end it "only displays users that belong user's org" do - expect(question.displayed_answer_options(sales_log, data_coordinator)).to eq(expected_answer_options) + expect(question.displayed_answer_options(sales_log, data_coordinator)).to eq(expected_option_for_users(data_coordinator.organisation.users)) end end end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 362a7e2a9..ad9034d35 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -2,39 +2,35 @@ require "rails_helper" RSpec.describe Organisation, type: :model do describe "#new" do - let(:user) { FactoryBot.create(:user) } + let(:user) { create(:user) } let!(:organisation) { user.organisation } - let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) } + let!(:scheme) { create(:scheme, owning_organisation: organisation) } it "has expected fields" do expect(organisation.attribute_names).to include("name", "phone", "provider_type") end - it "has users" do - expect(organisation.users.first).to eq(user) - end - it "has owned_schemes" do expect(organisation.owned_schemes.first).to eq(scheme) end it "validates provider_type presence" do - expect { FactoryBot.create(:organisation, provider_type: nil) } + expect { create(:organisation, provider_type: nil) } .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type #{I18n.t('validations.organisation.provider_type_missing')}") end context "with parent/child associations", :aggregate_failures do - let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } - let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } + let!(:child_organisation) { create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create( + create( :organisation_relationship, child_organisation:, parent_organisation: organisation, ) - FactoryBot.create( + create( :organisation_relationship, child_organisation: grandchild_organisation, parent_organisation: child_organisation, @@ -53,17 +49,17 @@ RSpec.describe Organisation, type: :model do end context "with owning association", :aggregate_failures do - let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } - let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } + let!(:child_organisation) { create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create( + create( :organisation_relationship, child_organisation:, parent_organisation: organisation, ) - FactoryBot.create( + create( :organisation_relationship, child_organisation: grandchild_organisation, parent_organisation: child_organisation, @@ -77,17 +73,17 @@ RSpec.describe Organisation, type: :model do end context "with managing association", :aggregate_failures do - let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } - let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } + let!(:child_organisation) { create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create( + create( :organisation_relationship, child_organisation:, parent_organisation: organisation, ) - FactoryBot.create( + create( :organisation_relationship, child_organisation: grandchild_organisation, parent_organisation: child_organisation, @@ -103,8 +99,8 @@ RSpec.describe Organisation, type: :model do context "with data protection confirmations" do before do - FactoryBot.create(:data_protection_confirmation, organisation:, confirmed: false, created_at: Time.utc(2018, 0o6, 0o5, 10, 36, 49)) - FactoryBot.create(:data_protection_confirmation, organisation:, created_at: Time.utc(2019, 0o6, 0o5, 10, 36, 49)) + create(:data_protection_confirmation, organisation:, confirmed: false, created_at: Time.utc(2018, 0o6, 0o5, 10, 36, 49)) + create(:data_protection_confirmation, organisation:, created_at: Time.utc(2019, 0o6, 0o5, 10, 36, 49)) end it "takes the most recently created" do @@ -118,11 +114,11 @@ RSpec.describe Organisation, type: :model do end before do - FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 2) - FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 3) + create(:organisation_rent_period, organisation:, rent_period: 2) + create(:organisation_rent_period, organisation:, rent_period: 3) # Unmapped and ignored by `rent_period_labels` - FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 10) + create(:organisation_rent_period, organisation:, rent_period: 10) allow(RentPeriod).to receive(:rent_period_mappings).and_return(rent_period_mappings) end @@ -142,9 +138,9 @@ RSpec.describe Organisation, type: :model do end context "with lettings logs" do - let(:other_organisation) { FactoryBot.create(:organisation) } + let(:other_organisation) { create(:organisation) } let!(:owned_lettings_log) do - FactoryBot.create( + create( :lettings_log, :completed, managing_organisation: other_organisation, @@ -152,7 +148,7 @@ RSpec.describe Organisation, type: :model do ) end let!(:managed_lettings_log) do - FactoryBot.create( + create( :lettings_log, created_by: user, ) @@ -173,7 +169,7 @@ RSpec.describe Organisation, type: :model do end describe "paper trail" do - let(:organisation) { FactoryBot.create(:organisation) } + let(:organisation) { create(:organisation) } it "creates a record of changes to a log" do expect { organisation.update!(name: "new test name") }.to change(organisation.versions, :count).by(1) @@ -187,11 +183,11 @@ RSpec.describe Organisation, type: :model do describe "delete cascade" do context "when the organisation is deleted" do - let!(:organisation) { FactoryBot.create(:organisation) } - let!(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) } - let!(:scheme_to_delete) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:log_to_delete) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation) } - let!(:sales_log_to_delete) { FactoryBot.create(:sales_log, owning_organisation: user.organisation) } + let!(:organisation) { create(:organisation) } + let!(:user) { create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) } + let!(:scheme_to_delete) { create(:scheme, owning_organisation: user.organisation) } + let!(:log_to_delete) { create(:lettings_log, owning_organisation: user.organisation) } + let!(:sales_log_to_delete) { create(:sales_log, owning_organisation: user.organisation) } context "when organisation is deleted" do it "child relationships ie logs, schemes and users are deleted too - application" do @@ -216,8 +212,8 @@ RSpec.describe Organisation, type: :model do describe "scopes" do before do - FactoryBot.create(:organisation, name: "Joe Bloggs") - FactoryBot.create(:organisation, name: "Tom Smith") + create(:organisation, name: "Joe Bloggs") + create(:organisation, name: "Tom Smith") end context "when searching by name" do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1cdbe7cd4..edc065a4f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,10 +2,10 @@ require "rails_helper" RSpec.describe User, type: :model do describe "#new" do - let(:user) { FactoryBot.create(:user, old_user_id: "3") } - let(:other_organisation) { FactoryBot.create(:organisation) } + let(:user) { create(:user, old_user_id: "3") } + let(:other_organisation) { create(:organisation) } let!(:owned_lettings_log) do - FactoryBot.create( + create( :lettings_log, :completed, managing_organisation: other_organisation, @@ -13,7 +13,7 @@ RSpec.describe User, type: :model do ) end let!(:managed_lettings_log) do - FactoryBot.create( + create( :lettings_log, created_by: user, owning_organisation: other_organisation, @@ -103,7 +103,7 @@ RSpec.describe User, type: :model do end context "when the user is a data coordinator" do - let(:user) { FactoryBot.create(:user, :data_coordinator) } + let(:user) { create(:user, :data_coordinator) } it "can assign all roles except support" do expect(user.assignable_roles).to eq({ @@ -124,7 +124,7 @@ RSpec.describe User, type: :model do context "and their organisation has managing agents" do before do - FactoryBot.create(:organisation_relationship, parent_organisation: user.organisation) + create(:organisation_relationship, parent_organisation: user.organisation) end it "can filter lettings logs by user, year, status and organisation" do @@ -134,8 +134,8 @@ RSpec.describe User, type: :model do end context "when the user is a Customer Support person" do - let(:user) { FactoryBot.create(:user, :support) } - let!(:other_orgs_log) { FactoryBot.create(:lettings_log) } + let(:user) { create(:user, :support) } + let!(:other_orgs_log) { create(:lettings_log) } it "has access to logs from all organisations" do expect(user.lettings_logs.to_a).to match_array([owned_lettings_log, managed_lettings_log, other_orgs_log]) @@ -159,7 +159,7 @@ RSpec.describe User, type: :model do end context "when the user is in development environment" do - let(:user) { FactoryBot.create(:user, :support) } + let(:user) { create(:user, :support) } before do allow(Rails.env).to receive(:development?).and_return(true) @@ -171,7 +171,7 @@ RSpec.describe User, type: :model do end context "when the user is in review environment" do - let(:user) { FactoryBot.create(:user, :support) } + let(:user) { create(:user, :support) } before do allow(Rails.env).to receive(:development?).and_return(false) @@ -185,7 +185,7 @@ RSpec.describe User, type: :model do end describe "paper trail" do - let(:user) { FactoryBot.create(:user) } + let(:user) { create(:user) } it "creates a record of changes to a log" do expect { user.update!(name: "new test name") }.to change(user.versions, :count).by(1) @@ -217,13 +217,13 @@ RSpec.describe User, type: :model do end describe "scopes" do - let(:organisation_1) { FactoryBot.create(:organisation, name: "A") } - let(:organisation_2) { FactoryBot.create(:organisation, name: "B") } - let!(:user_1) { FactoryBot.create(:user, name: "Joe Bloggs", email: "joe@example.com", organisation: organisation_1, role: "support") } - let!(:user_3) { FactoryBot.create(:user, name: "Tom Smith", email: "tom@example.com", organisation: organisation_1, role: "data_provider") } - let!(:user_2) { FactoryBot.create(:user, name: "Jenny Ford", email: "jenny@smith.com", organisation: organisation_1, role: "data_coordinator") } - let!(:user_4) { FactoryBot.create(:user, name: "Greg Thomas", email: "greg@org2.com", organisation: organisation_2, role: "data_coordinator") } - let!(:user_5) { FactoryBot.create(:user, name: "Adam Thomas", email: "adam@org2.com", organisation: organisation_2, role: "data_coordinator") } + let(:organisation_1) { create(:organisation, :without_dpc, name: "A") } + let(:organisation_2) { create(:organisation, :without_dpc, name: "B") } + let!(:user_1) { create(:user, name: "Joe Bloggs", email: "joe@example.com", organisation: organisation_1, role: "support") } + let!(:user_3) { create(:user, name: "Tom Smith", email: "tom@example.com", organisation: organisation_1, role: "data_provider") } + let!(:user_2) { create(:user, name: "Jenny Ford", email: "jenny@smith.com", organisation: organisation_1, role: "data_coordinator") } + let!(:user_4) { create(:user, name: "Greg Thomas", email: "greg@org2.com", organisation: organisation_2, role: "data_coordinator") } + let!(:user_5) { create(:user, name: "Adam Thomas", email: "adam@org2.com", organisation: organisation_2, role: "data_coordinator") } context "when searching by name" do it "returns case insensitive matching records" do @@ -271,7 +271,7 @@ RSpec.describe User, type: :model do let(:error_message) { "Validation failed: Password #{I18n.t('activerecord.errors.models.user.attributes.password.too_short', count: 8)}" } it "validates password length" do - expect { FactoryBot.create(:user, password:) } + expect { create(:user, password:) } .to raise_error(ActiveRecord::RecordInvalid, error_message) end end @@ -281,27 +281,27 @@ RSpec.describe User, type: :model do let(:error_message) { "Validation failed: email #{I18n.t('activerecord.errors.models.user.attributes.email.invalid')}" } it "validates email format" do - expect { FactoryBot.create(:user, email: invalid_email) } + expect { create(:user, email: invalid_email) } .to raise_error(ActiveRecord::RecordInvalid, error_message) end end context "when the email entered has already been used" do - let(:user) { FactoryBot.create(:user) } + let(:user) { create(:user) } let(:error_message) { "Validation failed: email #{I18n.t('activerecord.errors.models.user.attributes.email.taken')}" } it "validates email uniqueness" do - expect { FactoryBot.create(:user, email: user.email) } + expect { create(:user, email: user.email) } .to raise_error(ActiveRecord::RecordInvalid, error_message) end end end describe "delete" do - let(:user) { FactoryBot.create(:user) } + let(:user) { create(:user) } before do - FactoryBot.create( + create( :lettings_log, :completed, owning_organisation: user.organisation, @@ -309,7 +309,7 @@ RSpec.describe User, type: :model do created_by: user, ) - FactoryBot.create( + create( :sales_log, owning_organisation: user.organisation, created_by: user, @@ -319,13 +319,13 @@ RSpec.describe User, type: :model do context "when the user is deleted" do it "owned lettings logs are not deleted as a result" do expect { user.destroy! } - .to change(described_class, :count).from(1).to(0) + .to change(described_class, :count).by(-1) .and change(LettingsLog, :count).by(0) end it "owned sales logs are not deleted as a result" do expect { user.destroy! } - .to change(described_class, :count).from(1).to(0) + .to change(described_class, :count).by(-1) .and change(SalesLog, :count).by(0) end end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 3328fdaf6..a97086bb2 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -363,7 +363,7 @@ RSpec.describe UsersController, type: :request do end context "when user is signed in as a data coordinator" do - let(:user) { FactoryBot.create(:user, :data_coordinator, email: "coordinator@example.com") } + let(:user) { FactoryBot.create(:user, :data_coordinator, email: "coordinator@example.com", organisation: create(:organisation, :without_dpc)) } let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "filter name", email: "filter@example.com") } describe "#index" do @@ -969,7 +969,7 @@ RSpec.describe UsersController, type: :request do end context "when user is signed in as a support user" do - let(:user) { FactoryBot.create(:user, :support) } + let(:user) { FactoryBot.create(:user, :support, organisation: create(:organisation, :without_dpc)) } let(:other_user) { FactoryBot.create(:user, organisation: user.organisation) } before do @@ -979,7 +979,7 @@ RSpec.describe UsersController, type: :request do describe "#index" do let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "User 2", email: "other@example.com") } let!(:inactive_user) { FactoryBot.create(:user, organisation: user.organisation, active: false, name: "User 3", email: "inactive@example.com") } - let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "otherorg@otherexample.com") } + let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc)) } before do sign_in user @@ -1058,7 +1058,7 @@ RSpec.describe UsersController, type: :request do context "when our search term matches an email and a name" do let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "joe", email: "other@example.com") } - let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@otherexample.com") } + let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@otherexample.com", organisation: create(:organisation, :without_dpc)) } let(:search_param) { "joe" } it "returns any results including joe" do @@ -1090,15 +1090,19 @@ RSpec.describe UsersController, type: :request do get "/users", headers:, params: {} end + let(:byte_order_mark) { "\uFEFF" } + it "downloads a CSV file with headers" do csv = CSV.parse(response.body) - expect(csv.first.second).to eq("email") - expect(csv.second.first).to eq(user.id.to_s) + + expect(csv.first.to_csv).to eq( + "#{byte_order_mark}id,email,name,organisation_name,role,old_user_id,is_dpo,is_key_contact,active,sign_in_count,last_sign_in_at\n", + ) end it "downloads all users" do csv = CSV.parse(response.body) - expect(csv.count).to eq(27) + expect(csv.count).to eq(User.all.count + 1) # +1 for the headers end it "downloads organisation names rather than ids" do @@ -1517,7 +1521,7 @@ RSpec.describe UsersController, type: :request do end describe "#create" do - let(:organisation) { FactoryBot.create(:organisation) } + let(:organisation) { FactoryBot.create(:organisation, :without_dpc) } let(:email) { "new_user@example.com" } let(:params) do { diff --git a/spec/services/imports/data_protection_confirmation_import_service_spec.rb b/spec/services/imports/data_protection_confirmation_import_service_spec.rb index cb14829b4..400822462 100644 --- a/spec/services/imports/data_protection_confirmation_import_service_spec.rb +++ b/spec/services/imports/data_protection_confirmation_import_service_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do end context "when the organisation does exist" do - let!(:organisation) { FactoryBot.create(:organisation, old_org_id:) } + let!(:organisation) { create(:organisation, :without_dpc, old_org_id:) } context "when a data protection officer with matching name does not exists for the organisation" do it "creates a data protection officer without sign in credentials" do @@ -41,7 +41,7 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do it "successfully create a data protection confirmation record with the expected data" do import_service.create_data_protection_confirmations("data_protection_directory") - confirmation = Organisation.find_by(old_org_id:).data_protection_confirmations.last + confirmation = Organisation.find_by(old_org_id:).data_protection_confirmation expect(confirmation.data_protection_officer.name).to eq("John Doe") expect(confirmation.confirmed).to be_truthy expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49)) @@ -50,13 +50,13 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do context "when a data protection officer with matching name already exists for the organisation" do let!(:data_protection_officer) do - FactoryBot.create(:user, :data_protection_officer, name: "John Doe", organisation:) + create(:user, :data_protection_officer, name: "John Doe", organisation:) end it "successfully creates a data protection confirmation record with the expected data" do import_service.create_data_protection_confirmations("data_protection_directory") - confirmation = Organisation.find_by(old_org_id:).data_protection_confirmations.last + confirmation = Organisation.find_by(old_org_id:).data_protection_confirmation expect(confirmation.data_protection_officer.id).to eq(data_protection_officer.id) expect(confirmation.confirmed).to be_truthy expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49)) @@ -64,7 +64,7 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do context "when the data protection record has already been imported previously" do before do - FactoryBot.create( + create( :data_protection_confirmation, organisation:, data_protection_officer:,