diff --git a/config/environments/development.rb b/config/environments/development.rb
index 7e1890b026..f756435249 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -81,6 +81,8 @@
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
+ Faker::Config.locale = "en-GB"
+
# see https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017
config.active_record.yaml_column_permitted_classes = [Time, BigDecimal]
diff --git a/config/environments/review.rb b/config/environments/review.rb
index f7438fdb6d..471879b279 100644
--- a/config/environments/review.rb
+++ b/config/environments/review.rb
@@ -125,6 +125,8 @@
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
+ Faker::Config.locale = "en-GB"
+
# see https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017
config.active_record.yaml_column_permitted_classes = [Time, BigDecimal]
end
diff --git a/db/seeds.rb b/db/seeds.rb
index 9654b2b787..fcbb61b31a 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -6,431 +6,147 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
-# rubocop:disable Rails/Output
-def create_data_protection_confirmation(user)
- DataProtectionConfirmation.find_or_create_by!(
- organisation: user.organisation,
- confirmed: true,
- data_protection_officer: user,
- signed_at: Time.zone.local(2019, 1, 1),
- data_protection_officer_email: user.email,
- data_protection_officer_name: user.name,
- organisation_name: user.organisation.name,
- organisation_address: user.organisation.address_row,
- )
+def find_or_create_user(organisation, email, name, role)
+ case role
+ when :data_provider
+ FactoryBot.create(:user, :if_unique, :data_provider, organisation:, email:, name:, password: ENV["REVIEW_APP_USER_PASSWORD"])
+ when :data_coordinator
+ FactoryBot.create(:user, :if_unique, :data_coordinator, organisation:, email:, name:, password: ENV["REVIEW_APP_USER_PASSWORD"])
+ when :support
+ FactoryBot.create(:user, :if_unique, :support, organisation:, email:, name:, password: ENV["REVIEW_APP_USER_PASSWORD"])
+ end
end
unless Rails.env.test?
- stock_owner1 = Organisation.find_or_create_by!(
- name: "Stock Owner 1",
- address_line1: "2 Marsham Street",
- address_line2: "London",
- postcode: "SW1P 4DF",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "LA",
- )
- stock_owner2 = Organisation.find_or_create_by!(
- name: "Stock Owner 2",
- address_line1: "2 Marsham Street",
- address_line2: "London",
- postcode: "SW1P 4DF",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "LA",
- )
- managing_agent1 = Organisation.find_or_create_by!(
- name: "Managing Agent 1 (PRP)",
- address_line1: "2 Marsham Street",
- address_line2: "London",
- postcode: "SW1P 4DF",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "PRP",
- )
- managing_agent2 = Organisation.find_or_create_by!(
- name: "Managing Agent 2",
- address_line1: "2 Marsham Street",
- address_line2: "London",
- postcode: "SW1P 4DF",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "LA",
- )
+ if LocalAuthority.count.zero?
+ la_path = "config/local_authorities_data/initial_local_authorities.csv"
+ service = Imports::LocalAuthoritiesService.new(path: la_path)
+ service.call
+ end
- org = Organisation.find_or_create_by!(
- name: "MHCLG",
- address_line1: "2 Marsham Street",
- address_line2: "London",
- postcode: "SW1P 4DF",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "LA",
- ) do
- info = "Seeded MHCLG Organisation"
- if Rails.env.development?
- pp info
- else
- Rails.logger.info info
+ if LaRentRange.count.zero?
+ Dir.glob("config/rent_range_data/*.csv").each do |path|
+ start_year = File.basename(path, ".csv")
+ service = Imports::RentRangesService.new(start_year:, path:)
+ service.call
end
end
- standalone_owns_stock = Organisation.find_or_create_by!(
- name: "Standalone Owns Stock 1 Ltd",
- address_line1: "2 Marsham Street",
- address_line2: "London",
- postcode: "SW1P 4DF",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "LA",
- )
+ if LaSaleRange.count.zero?
+ Dir.glob("config/sale_range_data/*.csv").each do |path|
+ start_year = File.basename(path, ".csv")
+ service = Imports::SaleRangesService.new(start_year:, path:)
+ service.call
+ end
+ end
+
+ all_rent_periods = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
- standalone_no_stock = Organisation.find_or_create_by!(
- name: "Standalone No Stock 1 Ltd",
+ mhclg = FactoryBot.create(
+ :organisation,
+ :if_unique,
+ name: "MHCLG",
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
- holds_own_stock: false,
+ holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "LA",
- )
-
- User.find_or_create_by!(
- name: "Provider Owns Stock",
- email: "provider.owner1@example.com",
- organisation: standalone_owns_stock,
- role: "data_provider",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- User.find_or_create_by!(
- name: "Coordinator Owns Stock",
- email: "coordinator.owner1@example.com",
- organisation: standalone_owns_stock,
- role: "data_coordinator",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- User.find_or_create_by!(
- name: "Provider No Stock",
- email: "provider.nostock@example.com",
- organisation: standalone_no_stock,
- role: "data_provider",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- User.find_or_create_by!(
- name: "Coordinator No Stock",
- email: "coordinator.nostock@example.com",
- organisation: standalone_no_stock,
- role: "data_coordinator",
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- end
-
- User.find_or_create_by!(
- name: "Stock owner 1",
- email: "stock_owner1_dpo@example.com",
- organisation: stock_owner1,
- role: "data_coordinator",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- User.find_or_create_by!(
- name: "Stock owner 2",
- email: "stock_owner2_dpo@example.com",
- organisation: stock_owner2,
- role: "data_coordinator",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- User.find_or_create_by!(
- name: "Managing agent 1",
- email: "managing_agent1_dpo@example.com",
- organisation: managing_agent1,
- role: "data_coordinator",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- User.find_or_create_by!(
- name: "Managing agent 2",
- email: "managing_agent2_dpo@example.com",
- organisation: managing_agent2,
- role: "data_coordinator",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- OrganisationRelationship.find_or_create_by!(
- parent_organisation: stock_owner1,
- child_organisation: org,
- )
- OrganisationRelationship.find_or_create_by!(
- parent_organisation: stock_owner2,
- child_organisation: org,
- )
- OrganisationRelationship.find_or_create_by!(
- parent_organisation: org,
- child_organisation: managing_agent1,
- )
- OrganisationRelationship.find_or_create_by!(
- parent_organisation: org,
- child_organisation: managing_agent2,
+ rent_periods: all_rent_periods,
)
if Rails.env.development? || Rails.env.review?
- User.find_or_create_by!(
- name: "Provider",
- email: "provider@example.com",
- organisation: org,
- role: "data_provider",
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- end
-
- User.find_or_create_by!(
- name: "Coordinator",
- email: "coordinator@example.com",
- organisation: org,
- role: "data_coordinator",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- user.is_dpo = true
- create_data_protection_confirmation(user)
- end
-
- support_user = User.find_or_create_by!(
- name: "Support",
- email: "support@example.com",
- organisation: org,
- role: "support",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
-
- pp "Seeded dummy users"
- end
-
- if (Rails.env.development? || Rails.env.review?) && SalesLog.count.zero?
- SalesLog.find_or_create_by!(
- assigned_to: support_user,
- owning_organisation: org,
- managing_organisation: org,
- saledate: Time.zone.today,
- purchid: "1",
- ownershipsch: 1,
- type: 2,
- jointpur: 1,
- jointmore: 1,
+ stock_owner1 = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Stock Owner 1", rent_periods: all_rent_periods)
+ stock_owner2 = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Stock Owner 2", rent_periods: all_rent_periods.sample(5))
+ managing_agent1 = FactoryBot.create(:organisation, :if_unique, :prp, :holds_own_stock, name: "Managing Agent 1 (PRP)", rent_periods: all_rent_periods)
+ managing_agent2 = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Managing Agent 2", rent_periods: all_rent_periods.sample(5))
+ standalone_owns_stock = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Standalone Owns Stock 1 Ltd", rent_periods: all_rent_periods)
+ standalone_no_stock = FactoryBot.create(:organisation, :if_unique, :la, :does_not_own_stock, name: "Standalone No Stock 1 Ltd", rent_periods: all_rent_periods)
+
+ OrganisationRelationship.find_or_create_by!(
+ parent_organisation: stock_owner1,
+ child_organisation: mhclg,
)
-
- SalesLog.find_or_create_by!(
- assigned_to: support_user,
- owning_organisation: org,
- managing_organisation: org,
- saledate: Time.zone.today,
- purchid: "1",
- ownershipsch: 2,
- type: 9,
- jointpur: 1,
- jointmore: 1,
+ OrganisationRelationship.find_or_create_by!(
+ parent_organisation: stock_owner2,
+ child_organisation: mhclg,
)
-
- SalesLog.find_or_create_by!(
- assigned_to: support_user,
- owning_organisation: org,
- managing_organisation: org,
- saledate: Time.zone.today,
- purchid: "1",
- ownershipsch: 3,
- type: 10,
- companybuy: 1,
+ OrganisationRelationship.find_or_create_by!(
+ parent_organisation: mhclg,
+ child_organisation: managing_agent1,
)
-
- pp "Seeded a sales log of each type"
- end
-
- if Rails.env.development? || Rails.env.review?
- dummy_org = Organisation.find_or_create_by!(
- name: "FooBar LTD",
- address_line1: "Higher Kingston",
- address_line2: "Yeovil",
- postcode: "BA21 4AT",
- holds_own_stock: true,
- other_stock_owners: "None",
- managing_agents_label: "None",
- provider_type: "LA",
+ OrganisationRelationship.find_or_create_by!(
+ parent_organisation: mhclg,
+ child_organisation: managing_agent2,
)
- pp "Seeded dummy FooBar LTD organisation"
+ provider = find_or_create_user(mhclg, "provider@example.com", "Provider", :data_provider)
+ coordinator = find_or_create_user(mhclg, "coordinator@example.com", "Coordinator", :data_coordinator)
+ support = find_or_create_user(mhclg, "support@example.com", "Support", :support)
- User.find_or_create_by!(
- name: "Dummy user",
- email: "dummy_org@example.com",
- organisation: dummy_org,
- role: "data_provider",
- is_dpo: true,
- ) do |user|
- user.password = ENV["REVIEW_APP_USER_PASSWORD"]
- user.confirmed_at = Time.zone.now
- create_data_protection_confirmation(user)
- end
- end
+ stock_owner1_user = find_or_create_user(stock_owner1, "stock_owner1_dpo@example.com", "Stock owner 1", :data_coordinator)
+ stock_owner2_user = find_or_create_user(stock_owner2, "stock_owner2_dpo@example.com", "Stock owner 2", :data_coordinator)
- if (Rails.env.development? || Rails.env.review?) && Scheme.count.zero?
- scheme1 = Scheme.create!(
- service_name: "Beulahside Care",
- sensitive: 0,
- registered_under_care_act: 1,
- support_type: 2,
- scheme_type: 4,
- intended_stay: "M",
- primary_client_group: "O",
- has_other_client_group: 1,
- secondary_client_group: "H",
- owning_organisation: org,
- arrangement_type: "D",
- confirmed: true,
- created_at: Time.zone.now,
- )
+ managing_agent1_user = find_or_create_user(managing_agent1, "managing_agent1_dpo@example.com", "Managing agent 1", :data_coordinator)
+ managing_agent2_user = find_or_create_user(managing_agent2, "managing_agent2_dpo@example.com", "Managing agent 2", :data_coordinator)
- scheme2 = Scheme.create!(
- service_name: "Abdullahview Point",
- sensitive: 0,
- registered_under_care_act: 1,
- support_type: 2,
- scheme_type: 5,
- intended_stay: "S",
- primary_client_group: "D",
- secondary_client_group: "E",
- has_other_client_group: 1,
- owning_organisation: org,
- arrangement_type: "D",
- confirmed: true,
- created_at: Time.zone.now,
- )
+ provider_owner1 = find_or_create_user(standalone_owns_stock, "provider.owner1@example.com", "Provider Owns Stock", :data_provider)
+ coordinator_owner1 = find_or_create_user(standalone_owns_stock, "coordinator.owner1@example.com", "Coordinator Owns Stock", :data_coordinator)
- Scheme.create!(
- service_name: "Caspermouth Center",
- sensitive: 1,
- registered_under_care_act: 1,
- support_type: 4,
- scheme_type: 7,
- intended_stay: "X",
- primary_client_group: "G",
- has_other_client_group: 1,
- secondary_client_group: "R",
- owning_organisation: dummy_org,
- arrangement_type: "D",
- confirmed: true,
- created_at: Time.zone.now,
- )
+ find_or_create_user(standalone_no_stock, "provider.nostock@example.com", "Provider No Stock", :data_provider)
+ find_or_create_user(standalone_no_stock, "coordinator.nostock@example.com", "Coordinator No Stock", :data_coordinator)
- Location.create!(
- scheme: scheme1,
- location_code: "E09000033",
- location_admin_district: "Westminster",
- postcode: "CU193AA",
- name: "Rectory Road",
- type_of_unit: 4,
- units: 1,
- mobility_type: "N",
- )
+ if Scheme.count.zero?
+ scheme1 = FactoryBot.create(:scheme, service_name: "Beulahside Care", owning_organisation: mhclg)
+ scheme2 = FactoryBot.create(:scheme, service_name: "Abdullahview Point", owning_organisation: mhclg)
+ scheme3 = FactoryBot.create(:scheme, :created_now, owning_organisation: mhclg)
+ scheme4 = FactoryBot.create(:scheme, owning_organisation: stock_owner1)
- Location.create!(
- scheme: scheme1,
- location_code: "E09000033",
- location_admin_district: "Westminster",
- postcode: "DM250DC",
- name: "Smithy Lane",
- type_of_unit: 1,
- units: 1,
- mobility_type: "W",
- )
+ [scheme1, scheme2, scheme3, scheme4].each do |scheme|
+ FactoryBot.create(:location, scheme:)
+ end
+ [scheme2, scheme3].each do |scheme|
+ FactoryBot.create_list(:location, 3, scheme:)
+ end
+ end
- Location.create!(
- scheme: scheme2,
- location_code: "E09000033",
- location_admin_district: "Westminster",
- postcode: "YX130WP",
- name: "Smithy Lane",
- type_of_unit: 2,
- units: 1,
- mobility_type: "W",
- )
- pp "Seeded dummy schemes"
- end
+ users_with_logs = [provider, coordinator, support, stock_owner1_user, stock_owner2_user, managing_agent1_user, managing_agent2_user, provider_owner1, coordinator_owner1]
- if LocalAuthority.count.zero?
- la_path = "config/local_authorities_data/initial_local_authorities.csv"
- service = Imports::LocalAuthoritiesService.new(path: la_path)
- service.call
- end
+ if SalesLog.count.zero?
+ users_with_logs.each do |user|
+ FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: user)
+ FactoryBot.create(:sales_log, :discounted_ownership_setup_complete, assigned_to: user)
+ FactoryBot.create(:sales_log, :outright_sale_setup_complete, assigned_to: user)
+ FactoryBot.create(:sales_log, :completed, assigned_to: user)
+ FactoryBot.create_list(:sales_log, 2, :completed, :ignore_validation_errors, saledate: Time.zone.today - 1.year, assigned_to: user)
+ end
- if (Rails.env.development? || Rails.env.review?) && LocalAuthorityLink.count.zero?
- links_data_paths = ["config/local_authorities_data/local_authority_links_2023.csv", "config/local_authorities_data/local_authority_links_2022.csv"]
- links_data_paths.each do |path|
- service = Imports::LocalAuthorityLinksService.new(path:)
- service.call
+ FactoryBot.create(:sales_log, :completed, assigned_to: managing_agent1_user, owning_organisation: mhclg)
+ FactoryBot.create(:sales_log, :completed, assigned_to: provider, owning_organisation: stock_owner1)
end
- pp "Seeded local authority links"
- end
-
- if LaRentRange.count.zero?
- Dir.glob("config/rent_range_data/*.csv").each do |path|
- start_year = File.basename(path, ".csv")
- service = Imports::RentRangesService.new(start_year:, path:)
- service.call
+ if LettingsLog.count.zero?
+ users_with_logs.each do |user|
+ FactoryBot.create(:lettings_log, :setup_completed, assigned_to: user)
+ FactoryBot.create(:lettings_log, :completed, assigned_to: user)
+ if user.organisation.owned_schemes.any?
+ scheme = user.organisation.owned_schemes.first
+ FactoryBot.create(:lettings_log, :setup_completed, :sh, scheme:, location: scheme.locations.first, assigned_to: user)
+ end
+ FactoryBot.create_list(:lettings_log, 2, :completed, :ignore_validation_errors, startdate: Time.zone.today - 1.year, assigned_to: user)
+ end
+
+ FactoryBot.create(:lettings_log, :completed, assigned_to: managing_agent1_user, owning_organisation: mhclg)
+ FactoryBot.create(:lettings_log, :completed, assigned_to: provider, owning_organisation: stock_owner1)
end
- end
- if LaSaleRange.count.zero?
- Dir.glob("config/sale_range_data/*.csv").each do |path|
- start_year = File.basename(path, ".csv")
- service = Imports::SaleRangesService.new(start_year:, path:)
- service.call
+ if LocalAuthorityLink.count.zero?
+ links_data_paths = ["config/local_authorities_data/local_authority_links_2023.csv", "config/local_authorities_data/local_authority_links_2022.csv"]
+ links_data_paths.each do |path|
+ service = Imports::LocalAuthorityLinksService.new(path:)
+ service.call
+ end
end
end
end
@@ -440,4 +156,3 @@ def create_data_protection_confirmation(user)
service = Imports::LocalAuthoritiesService.new(path:)
service.call
end
-# rubocop:enable Rails/Output
diff --git a/spec/components/lettings_log_summary_component_spec.rb b/spec/components/lettings_log_summary_component_spec.rb
index 52b6b19552..78ce5d8044 100644
--- a/spec/components/lettings_log_summary_component_spec.rb
+++ b/spec/components/lettings_log_summary_component_spec.rb
@@ -3,9 +3,11 @@
RSpec.describe LettingsLogSummaryComponent, type: :component do
let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user) }
+ let(:organisation) { create(:organisation, name: "MHCLG") }
+ let(:log_user) { create(:user, name: "Danny Rojas", organisation:) }
let(:propcode) { "P3647" }
let(:tenancycode) { "T62863" }
- let(:lettings_log) { FactoryBot.create(:lettings_log, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) }
+ let(:lettings_log) { FactoryBot.create(:lettings_log, assigned_to: log_user, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) }
context "when rendering lettings log for a support user" do
it "shows the log summary with organisational relationships" do
diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb
index 8ebe448750..22682c70c6 100644
--- a/spec/factories/lettings_log.rb
+++ b/spec/factories/lettings_log.rb
@@ -56,8 +56,8 @@
status { 2 }
tenancycode { Faker::Name.initials(number: 10) }
age1_known { 0 }
- age1 { 35 }
- sex1 { "F" }
+ age1 { Faker::Number.within(range: 25..55) }
+ sex1 { %w[F M X R].sample }
ethnic_group { 0 }
ethnic { 2 }
national { 13 }
@@ -67,8 +67,8 @@
relat2 { "P" }
age2_known { 0 }
details_known_2 { 0 }
- age2 { 32 }
- sex2 { "M" }
+ age2 { Faker::Number.within(range: 25..55) }
+ sex2 { %w[F M X R].sample }
ecstat2 { 6 }
homeless { 1 }
underoccupation_benefitcap { 0 }
@@ -163,7 +163,7 @@
uprn_known { 0 }
joint { 3 }
address_line1 { "Address line 1" }
- town_or_city { "London" }
+ town_or_city { Faker::Address.city }
ppcodenk { 1 }
tshortfall_known { 1 }
after(:build) do |log, _evaluator|
diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb
index 6623ff3557..376b9c126f 100644
--- a/spec/factories/organisation.rb
+++ b/spec/factories/organisation.rb
@@ -41,7 +41,13 @@
trait :prp do
provider_type { "PRP" }
end
+ trait :la do
+ provider_type { "LA" }
+ end
+ trait :holds_own_stock do
+ holds_own_stock { true }
+ end
trait :does_not_own_stock do
holds_own_stock { false }
end
@@ -53,6 +59,10 @@
data_protection_confirmation { nil }
end
+
+ trait :if_unique do
+ initialize_with { Organisation.find_or_create_by(name:) }
+ end
end
factory :organisation_rent_period do
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index b809b9daf9..1a97862acc 100644
--- a/spec/factories/sales_log.rb
+++ b/spec/factories/sales_log.rb
@@ -32,6 +32,17 @@
jointpur { 2 }
noint { 2 }
privacynotice { 1 }
+ purchid { rand(999_999_999).to_s }
+ end
+ trait :discounted_ownership_setup_complete do
+ saledate_today
+ ownershipsch { 2 }
+ type { 9 }
+ jointpur { 1 }
+ jointmore { 1 }
+ noint { 2 }
+ privacynotice { 1 }
+ purchid { rand(999_999_999).to_s }
end
trait :outright_sale_setup_complete do
saledate_today
@@ -67,14 +78,14 @@
noint { 2 }
privacynotice { 1 }
age1_known { 0 }
- age1 { 30 }
- sex1 { "X" }
+ age1 { Faker::Number.within(range: 27..55) }
+ sex1 { %w[F M X R].sample }
national { 18 }
buy1livein { 1 }
relat2 { "P" }
proptype { 1 }
age2_known { 0 }
- age2 { 35 }
+ age2 { Faker::Number.within(range: 25..55) }
builtype { 1 }
ethnic { 3 }
ethnic_group { 17 }
@@ -104,16 +115,16 @@
inc2mort { 1 }
uprn_known { 0 }
address_line1 { "Address line 1" }
- town_or_city { "Town or city" }
+ town_or_city { Faker::Address.city }
la_known { 1 }
la { "E09000003" }
savingsnk { 1 }
prevown { 1 }
prevshared { 2 }
- sex3 { "X" }
- sex4 { "X" }
- sex5 { "X" }
- sex6 { "X" }
+ sex3 { %w[F M X R].sample }
+ sex4 { %w[F M X R].sample }
+ sex5 { %w[F M X R].sample }
+ sex6 { %w[F M X R].sample }
mortgage { 20_000 }
ecstat3 { 9 }
ecstat4 { 3 }
@@ -122,6 +133,7 @@
disabled { 1 }
deposit { 80_000 }
value { 110_000 }
+ value_value_check { 0 }
grant { 10_000 }
proplen { 10 }
pregyrha { 1 }
@@ -174,5 +186,12 @@
trait :imported do
old_id { Random.hex }
end
+ trait :ignore_validation_errors do
+ to_create do |instance|
+ instance.valid?
+ instance.errors.clear
+ instance.save!(validate: false)
+ end
+ end
end
end
diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb
index 77d74b70a5..34f98a8a66 100644
--- a/spec/factories/scheme.rb
+++ b/spec/factories/scheme.rb
@@ -41,5 +41,8 @@
support_type { 2 }
intended_stay { "M" }
end
+ trait :created_now do
+ created_at { Time.zone.now }
+ end
end
end
diff --git a/spec/factories/user.rb b/spec/factories/user.rb
index 956d883320..8708e319b2 100644
--- a/spec/factories/user.rb
+++ b/spec/factories/user.rb
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :user do
sequence(:email) { "test#{SecureRandom.hex}@example.com" }
- name { "Danny Rojas" }
+ name { Faker::Name.name }
password { "pAssword1" }
organisation { association :organisation, with_dsa: is_dpo ? false : true }
role { "data_provider" }
@@ -40,5 +40,9 @@
)
end
end
+
+ trait :if_unique do
+ initialize_with { User.find_or_create_by(email:) }
+ end
end
end
diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb
index d3dc7e21f5..74594c9b96 100644
--- a/spec/models/form_spec.rb
+++ b/spec/models/form_spec.rb
@@ -329,7 +329,7 @@ def answer_local_authority(lettings_log)
end
context "when a value is changed such that a radio and free input questions are no longer routed to" do
- let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now) }
+ let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now, hhmemb: 2, details_known_2: 0, sex2: "M", relat2: "P", age2_known: 0, age2: 32, ecstat2: 6) }
it "all attributes relating to that checkbox question are cleared" do
expect(log.hhmemb).to be 2
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 89f4f9deef..51cfc00bdc 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -380,7 +380,7 @@
end
describe "paper trail" do
- let(:user) { create(:user) }
+ let(:user) { create(:user, name: "Danny Rojas") }
it "creates a record of changes to a log" do
expect { user.update!(name: "new test name") }.to change(user.versions, :count).by(1)
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 1b62196bb4..868b1d1f26 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -1261,8 +1261,8 @@
end
context "when user is signed in as a support user" do
- let(:user) { create(:user, :support, organisation: create(:organisation, :without_dpc)) }
- let(:other_user) { create(:user, organisation: user.organisation, last_sign_in_at: Time.zone.now) }
+ let(:user) { create(:user, :support, name: "Danny Rojas", organisation: create(:organisation, :without_dpc)) }
+ let(:other_user) { create(:user, name: "Danny Rojas", organisation: user.organisation, last_sign_in_at: Time.zone.now) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
diff --git a/spec/services/csv/sales_log_csv_service_spec.rb b/spec/services/csv/sales_log_csv_service_spec.rb
index 4bbbaf6451..d6ba36c6c2 100644
--- a/spec/services/csv/sales_log_csv_service_spec.rb
+++ b/spec/services/csv/sales_log_csv_service_spec.rb
@@ -19,13 +19,20 @@
owning_organisation: organisation,
purchid: nil,
hholdcount: 3,
+ age1: 30,
+ sex1: "X",
+ age2: 35,
+ sex2: "X",
+ sex3: "X",
age4_known: 1,
+ sex4: "X",
details_known_5: 2,
age6_known: nil,
age6: nil,
ecstat6: nil,
relat6: nil,
sex6: nil,
+ town_or_city: "Town or city",
address_line1_as_entered: "address line 1 as entered",
address_line2_as_entered: "address line 2 as entered",
town_or_city_as_entered: "town or city as entered",
diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb
index 6f7d88c91a..abece2e125 100644
--- a/spec/services/exports/lettings_log_export_service_spec.rb
+++ b/spec/services/exports/lettings_log_export_service_spec.rb
@@ -79,7 +79,7 @@ def replace_record_number(export_template, record_number)
end
context "and one lettings log is available for export" do
- let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
+ let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
@@ -123,7 +123,7 @@ def replace_record_number(export_template, record_number)
end
context "and one lettings log with unknown user details is available for export" do
- let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, details_known_2: 1, assigned_to: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
+ let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, details_known_2: 1, assigned_to: user, age1: 35, sex1: "F", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
def replace_person_details(export_file)
export_file.sub!("32", "-9")
@@ -176,7 +176,7 @@ def replace_person_details(export_file)
end
context "and one lettings log is available for export" do
- let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, uprn_known: 1, uprn: "100023336956", propcode: "123", postcode_full: "SE2 6RT", ppostcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2023, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
+ let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", uprn_known: 1, uprn: "100023336956", propcode: "123", postcode_full: "SE2 6RT", ppostcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2023, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
let(:expected_zip_filename) { "core_2023_2024_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2023_2024_apr_mar_f0001_inc0001_pt001.xml" }
let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_23_24.xml", "r:UTF-8") }
@@ -396,7 +396,7 @@ def create_fake_maifest
end
context "and one lettings log with duplicate reference is available for export" do
- let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, duplicate_set_id: 123) }
+ let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, duplicate_set_id: 123) }
def replace_duplicate_set_id(export_file)
export_file.sub!("", "123")
@@ -429,7 +429,7 @@ def replace_duplicate_set_id(export_file)
end
context "and one lettings log is available for export" do
- let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, ppostcode_full: "A1 1AA", nationality_all_group: 13, propcode: "123", postcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2024, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, creation_method: 2, bulk_upload_id: 1, address_line1_as_entered: "address line 1 as entered", address_line2_as_entered: "address line 2 as entered", town_or_city_as_entered: "town or city as entered", county_as_entered: "county as entered", postcode_full_as_entered: "AB1 2CD", la_as_entered: "la as entered") }
+ let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", ppostcode_full: "A1 1AA", nationality_all_group: 13, propcode: "123", postcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2024, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, creation_method: 2, bulk_upload_id: 1, address_line1_as_entered: "address line 1 as entered", address_line2_as_entered: "address line 2 as entered", town_or_city_as_entered: "town or city as entered", county_as_entered: "county as entered", postcode_full_as_entered: "AB1 2CD", la_as_entered: "la as entered") }
let(:expected_zip_filename) { "core_2024_2025_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2024_2025_apr_mar_f0001_inc0001_pt001.xml" }
let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_24_25.xml", "r:UTF-8") }
@@ -456,7 +456,7 @@ def replace_duplicate_set_id(export_file)
let(:scheme) { FactoryBot.create(:scheme, :export, owning_organisation: organisation) }
let(:location) { FactoryBot.create(:location, :export, scheme:, startdate: Time.zone.local(2021, 4, 1), old_id: "1a") }
- let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, assigned_to: user, updated_by: other_user, owning_organisation: organisation, startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), underoccupation_benefitcap: 4, sheltered: 1) }
+ let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, assigned_to: user, updated_by: other_user, owning_organisation: organisation, age1: 35, sex1: "F", age2: 32, sex2: "M", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), underoccupation_benefitcap: 4, sheltered: 1) }
before do
lettings_log.postcode_full = nil
diff --git a/spec/services/exports/user_export_service_spec.rb b/spec/services/exports/user_export_service_spec.rb
index 713d6f9078..51dfd724b2 100644
--- a/spec/services/exports/user_export_service_spec.rb
+++ b/spec/services/exports/user_export_service_spec.rb
@@ -42,7 +42,7 @@ def replace_record_number(export_template, record_number)
end
context "and one user is available for export" do
- let!(:user) { create(:user, organisation:, phone_extension: "123") }
+ let!(:user) { create(:user, organisation:, name: "Danny Rojas", phone_extension: "123") }
it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb
index 7163a142f6..2a155ad5d1 100644
--- a/spec/services/merge/merge_organisations_service_spec.rb
+++ b/spec/services/merge/merge_organisations_service_spec.rb
@@ -28,7 +28,7 @@
it "moves the users from merging organisation to absorbing organisation" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
merge_organisations_service.call
@@ -477,7 +477,7 @@
it "logs the merged schemes and locations" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@@ -744,7 +744,7 @@
it "logs the merged schemes" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@@ -922,7 +922,7 @@
let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") }
before do
- create_list(:user, 5, organisation: merging_organisation_too)
+ create_list(:user, 5, organisation: merging_organisation_too, name: "Danny Rojas")
end
it "sets merge date and absorbing organisation on merged organisations" do
@@ -961,10 +961,11 @@
context "and merging users" do
it "moves the users from merging organisations to absorbing organisation" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("Merged users from second org:")
- expect(Rails.logger).to receive(:info).with(/\tDanny Rojas/).exactly(6).times
+ expect(Rails.logger).to receive(:info).with(/\tDanny Rojas/).exactly(5).times
+ expect(Rails.logger).to receive(:info).with(/\t#{merging_organisation_too.data_protection_officers.first.name}/)
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with("New schemes from second org:")
merge_organisations_service.call
@@ -1113,7 +1114,7 @@
it "moves the users from merging organisation to absorbing organisation" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
merge_organisations_service.call
@@ -1251,7 +1252,7 @@
it "logs the merged schemes" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@@ -1462,7 +1463,7 @@
it "logs the merged schemes" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@@ -1590,15 +1591,16 @@
let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") }
before do
- create_list(:user, 5, organisation: merging_organisation_too)
+ create_list(:user, 5, organisation: merging_organisation_too, name: "Danny Rojas")
end
it "moves the users from merging organisations to absorbing organisation" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
- expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\t#{merging_organisation.data_protection_officers.first.name} (#{merging_organisation.data_protection_officers.first.email})")
expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("Merged users from second org:")
- expect(Rails.logger).to receive(:info).with(/\tDanny Rojas/).exactly(6).times
+ expect(Rails.logger).to receive(:info).with(/\tDanny Rojas/).exactly(5).times
+ expect(Rails.logger).to receive(:info).with(/\t#{merging_organisation_too.data_protection_officers.first.name}/)
expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with("New schemes from second org:")
merge_organisations_service.call