Compare commits

..

1 Commits

Author SHA1 Message Date
SuperrrrrFrank 12cfa7a4f7 CLDC-4029: Add filters for roles and responsibilities 2 months ago
  1. 4
      Gemfile.lock
  2. 5
      app/controllers/auth/passwords_controller.rb
  3. 2
      app/models/lettings_log.rb
  4. 12
      app/models/log.rb
  5. 2
      app/models/sales_log.rb
  6. 8
      app/models/user.rb
  7. 11
      app/models/validations/household_validations.rb
  8. 4
      app/services/bulk_upload/sales/year2025/row_parser.rb
  9. 11
      app/services/exports/lettings_log_export_service.rb
  10. 8
      app/services/exports/sales_log_export_service.rb
  11. 2
      app/services/exports/user_export_service.rb
  12. 8
      app/services/merge/merge_organisations_service.rb
  13. 6
      app/views/devise/passwords/reset_resend_confirmation.html.erb
  14. 2
      app/views/layouts/_feedback.html.erb
  15. 5
      app/views/users/show.html.erb
  16. 2
      config/locales/en.yml
  17. 7
      config/locales/validations/lettings/household.en.yml
  18. 67
      docs/setup.md
  19. 13
      spec/features/user_spec.rb
  20. 8
      spec/models/validations/household_validations_spec.rb
  21. 16
      spec/services/exports/lettings_log_export_service_spec.rb
  22. 16
      spec/services/exports/sales_log_export_service_spec.rb
  23. 25
      spec/services/merge/merge_organisations_service_spec.rb

4
Gemfile.lock

@ -343,7 +343,7 @@ GEM
activesupport (>= 3.0.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.18)
rack (3.1.16)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-mini-profiler (3.3.1)
@ -511,7 +511,7 @@ GEM
unicode-display_width (2.5.0)
unread (0.14.0)
activerecord (>= 6.1)
uri (1.0.4)
uri (1.0.3)
useragent (0.16.11)
view_component (3.10.0)
activesupport (>= 5.2.0, < 8.0)

5
app/controllers/auth/passwords_controller.rb

@ -4,7 +4,6 @@ class Auth::PasswordsController < Devise::PasswordsController
def reset_confirmation
self.resource = resource_class.new
@email = params["email"]
@unconfirmed = params["unconfirmed"] == "true"
if @email.blank?
resource.errors.add :email, I18n.t("validations.email.blank")
render "devise/passwords/new", status: :unprocessable_entity
@ -66,8 +65,8 @@ protected
resource.need_two_factor_authentication?(request) ? :updated_2FA : :updated
end
def after_sending_reset_password_instructions_path_for(_resource_name)
account_password_reset_confirmation_path(email: params.dig("user", "email"), unconfirmed: resource.initial_confirmation_sent && !resource.confirmed?)
def after_sending_reset_password_instructions_path_for(_resource)
account_password_reset_confirmation_path(email: params.dig("user", "email"))
end
def after_resetting_password_path_for(resource)

2
app/models/lettings_log.rb

@ -915,7 +915,6 @@ private
def should_process_uprn_change?
return unless uprn
return unless startdate
return if skip_uprn_lookup
uprn_changed? || startdate_changed?
end
@ -924,7 +923,6 @@ private
return unless uprn_selection || select_best_address_match
return unless startdate
return unless form.start_year_2024_or_later?
return if skip_address_lookup
if select_best_address_match
address_line1_input.present? && postcode_full_input.present?

12
app/models/log.rb

@ -57,7 +57,7 @@ class Log < ApplicationRecord
scope :filter_by_owning_organisation_text_search, ->(param, _user) { where(owning_organisation: Organisation.search_by(param)) }
scope :filter_by_managing_organisation_text_search, ->(param, _user) { where(managing_organisation: Organisation.search_by(param)) }
attr_accessor :skip_update_status, :skip_update_uprn_confirmed, :select_best_address_match, :skip_dpo_validation, :skip_uprn_lookup, :skip_address_lookup
attr_accessor :skip_update_status, :skip_update_uprn_confirmed, :select_best_address_match, :skip_dpo_validation
delegate :present?, to: :address_options, prefix: true
@ -74,9 +74,6 @@ class Log < ApplicationRecord
presenter = UprnDataPresenter.new(service.result)
# the address for this uprn is already known, skip further lookups for this object
self.skip_uprn_lookup = true if address_line1 == presenter.address_line1 && address_line2 == presenter.address_line2 && town_or_city == presenter.town_or_city && postcode_full == presenter.postcode
self.uprn_known = 1
self.uprn_selection = uprn
self.address_line1 = presenter.address_line1
@ -101,14 +98,9 @@ class Log < ApplicationRecord
presenter = AddressDataPresenter.new(service.result.first)
os_match_threshold_for_bulk_upload = 0.7
if presenter.match >= os_match_threshold_for_bulk_upload
# the address for this uprn is already known, skip further lookups for this object
self.skip_address_lookup = true if uprn_selection == presenter.uprn
self.uprn_selection = presenter.uprn
else
select_manual_address_entry!
# this uprn cannot be used for lookup
self.skip_address_lookup = true
return nil
end
end
@ -127,7 +119,7 @@ class Log < ApplicationRecord
self.uprn = uprn_selection
self.uprn_confirmed = 1
self.skip_update_uprn_confirmed = true
process_uprn_change! unless skip_uprn_lookup
process_uprn_change!
end
end
end

2
app/models/sales_log.rb

@ -435,7 +435,6 @@ class SalesLog < Log
def should_process_uprn_change?
return unless uprn
return unless saledate
return if skip_uprn_lookup
uprn_changed? || saledate_changed?
end
@ -444,7 +443,6 @@ class SalesLog < Log
return unless uprn_selection || select_best_address_match
return unless saledate
return unless form.start_year_2024_or_later?
return if skip_address_lookup
if select_best_address_match
address_line1_input.present? && postcode_full_input.present?

8
app/models/user.rb

@ -381,14 +381,6 @@ class User < ApplicationRecord
end
end
def send_reset_password_instructions
if confirmed?
super
else
send_confirmation_instructions
end
end
protected
# Checks whether a password is needed or not. For validations only.

11
app/models/validations/household_validations.rb

@ -30,6 +30,17 @@ module Validations::HouseholdValidations
end
validate_other_field(record, 20, :reason, :reasonother)
if record.is_reason_permanently_decanted?
if record.referral_type.present? && !record.is_from_prp_only_housing_register_or_waiting_list?
record.errors.add :referral_type, I18n.t("validations.lettings.household.referral_type.leaving_last_settled_home.reason_permanently_decanted")
end
if record.referral.present? && !record.is_internal_transfer?
record.errors.add :referral, I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted")
record.errors.add :reason, I18n.t("validations.lettings.household.reason.leaving_last_settled_home.not_internal_transfer")
end
end
return unless record.form.start_year_2024_or_later?
if record.reason == 20 && PHRASES_INDICATING_HOMELESSNESS_REGEX.match?(record.reasonother)

4
app/services/bulk_upload/sales/year2025/row_parser.rb

@ -12,7 +12,7 @@ class BulkUpload::Sales::Year2025::RowParser
field_5: "Which organisation is reporting this sale?",
field_6: "Username",
field_7: "What is the purchaser code?",
field_8: "Is this a shared ownership or discounted ownership sale?",
field_8: "What is the sale type?",
field_9: "What is the type of shared ownership sale?",
field_10: "Is this a staircasing transaction?",
field_11: "What is the type of discounted ownership sale?",
@ -311,7 +311,7 @@ class BulkUpload::Sales::Year2025::RowParser
validates :field_8,
presence: {
message: I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "sale type."),
message: I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "shared ownership sale type."),
category: :setup,
},
on: :after_log

11
app/services/exports/lettings_log_export_service.rb

@ -31,8 +31,7 @@ module Exports
end
def retrieve_resources_from_range(range, year)
relation = LettingsLog.exportable.filter_by_year(year)
.left_joins(:created_by, :updated_by, :assigned_to, :owning_organisation, :managing_organisation)
relation = LettingsLog.exportable.filter_by_year(year).left_joins(:created_by, :updated_by, :assigned_to, :owning_organisation, :managing_organisation)
ids = relation
.where({ updated_at: range })
@ -56,14 +55,6 @@ module Exports
)
.pluck(:id)
# these must be separate as activerecord struggles to join to two different name change tables in the same query
ids.concat(
relation.left_joins(owning_organisation: :organisation_name_changes).where(owning_organisation: { organisation_name_changes: { updated_at: range } }).pluck(:id),
)
ids.concat(
relation.left_joins(managing_organisation: :organisation_name_changes).where(managing_organisation: { organisation_name_changes: { updated_at: range } }).pluck(:id),
)
LettingsLog.where(id: ids)
end

8
app/services/exports/sales_log_export_service.rb

@ -55,14 +55,6 @@ module Exports
)
.pluck(:id)
# these must be separate as activerecord struggles to join to two different name change tables in the same query
ids.concat(
relation.left_joins(owning_organisation: :organisation_name_changes).where(owning_organisation: { organisation_name_changes: { updated_at: range } }).pluck(:id),
)
ids.concat(
relation.left_joins(managing_organisation: :organisation_name_changes).where(managing_organisation: { organisation_name_changes: { updated_at: range } }).pluck(:id),
)
SalesLog.where(id: ids)
end

2
app/services/exports/user_export_service.rb

@ -33,7 +33,7 @@ module Exports
relation.where.not(organisations: { updated_at: nil }).where(organisations: { updated_at: range }),
)
.or(
relation.where(organisation_name_changes: { updated_at: range }),
relation.where(organisation_name_changes: { created_at: range }),
)
.pluck(:id)

8
app/services/merge/merge_organisations_service.rb

@ -4,8 +4,6 @@ class Merge::MergeOrganisationsService
@merging_organisations = Organisation.find(merging_organisation_ids)
@merge_date = merge_date || Time.zone.today
@absorbing_organisation_active_from_merge_date = absorbing_organisation_active_from_merge_date
@pre_to_post_merge_scheme_ids = {}
@pre_to_post_merge_location_ids = {}
end
def call
@ -72,14 +70,12 @@ private
merging_organisation.owned_schemes.each do |scheme|
new_scheme = Scheme.new(scheme.attributes.except("id", "owning_organisation_id", "old_id", "old_visible_id").merge(owning_organisation: @absorbing_organisation, startdate: [scheme&.startdate, @merge_date].compact.max))
new_scheme.save!(validate: false)
@pre_to_post_merge_scheme_ids[scheme.id] = new_scheme.id
scheme.scheme_deactivation_periods.each do |deactivation_period|
split_scheme_deactivation_period_between_organisations(deactivation_period, new_scheme)
end
scheme.locations.each do |location|
new_location = Location.new(location.attributes.except("id", "scheme_id", "old_id", "old_visible_id").merge(scheme: new_scheme, startdate: [location&.startdate, @merge_date].compact.max))
new_location.save!(validate: false)
@pre_to_post_merge_location_ids[location.id] = new_location.id
location.location_deactivation_periods.each do |deactivation_period|
split_location_deactivation_period_between_organisations(deactivation_period, new_location)
end
@ -102,8 +98,8 @@ private
lettings_log.managing_organisation = @absorbing_organisation
end
if lettings_log.scheme.present?
scheme_to_set = @absorbing_organisation.owned_schemes.find_by(id: @pre_to_post_merge_scheme_ids[lettings_log.scheme.id])
location_to_set = scheme_to_set.locations.find_by(id: @pre_to_post_merge_location_ids[lettings_log.location&.id])
scheme_to_set = @absorbing_organisation.owned_schemes.find_by(service_name: lettings_log.scheme.service_name)
location_to_set = scheme_to_set.locations.find_by(name: lettings_log.location&.name, postcode: lettings_log.location&.postcode)
lettings_log.scheme = scheme_to_set if scheme_to_set.present?
# in some cases the lettings_log location is nil even if scheme is present (they're two different questions).

6
app/views/devise/passwords/reset_resend_confirmation.html.erb

@ -6,11 +6,7 @@
<%= content_for(:title) %>
</h1>
<% if @unconfirmed %>
<p class="govuk-body">We’ve sent a link to confirm your email address to <strong><%= @email %></strong>. This will complete your registration onto the CORE service.</p>
<% else %>
<p class="govuk-body">We’ve sent a link to reset your password to <strong><%= @email %></strong>.</p>
<% end %>
<p class="govuk-body">We’ve sent a link to reset your password to <strong><%= @email %></strong>.</p>
<p class="govuk-body">You’ll only receive this link if your email address already exists in our system.</p>
<p class="govuk-body">If you don’t receive the email within 5 minutes, check your spam or junk folders. Try again if you still haven’t received the email.</p>
</div>

2
app/views/layouts/_feedback.html.erb

@ -10,7 +10,7 @@
</div>
</div>
<div class="gem-c-feedback__prompt-questions">
<a class="govuk-button gem-c-feedback__prompt-link" target="_blank" href="https://forms.office.com/e/thT1Vm7edm">
<a class="govuk-button gem-c-feedback__prompt-link" target="_blank" href="https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqC4YDsCJ3llAvEZelBFBLUBURFVUTzFDTUJPQlM4M0laTE5DTlNFSjJBQi4u">
Give feedback (opens in a new tab)
</a>
</div>

5
app/views/users/show.html.erb

@ -154,10 +154,7 @@
<div class="govuk-button-group">
<% if @user.active? %>
<%= govuk_button_link_to "Deactivate user", deactivate_user_path(@user), warning: true %>
<%# Some users are confirmed but have no sign in date, since logging in is a separate step that happens after confirmation %>
<%# Some users are unconfirmed but have a sign in date, since deactivating an account will unconfirm but not reset login date %>
<%# So, allow both cases to receive invite links %>
<% if current_user.support? && (@user.last_sign_in_at.nil? || !@user.confirmed?) %>
<% if current_user.support? && @user.last_sign_in_at.nil? %>
<%= govuk_button_to "Resend invite link", resend_invite_user_path(@user), secondary: true %>
<% end %>
<% else %>

2
config/locales/en.yml

@ -31,7 +31,7 @@
en:
service_name: "Submit social housing lettings and sales data (CORE)"
feedback_form: "https://forms.office.com/e/thT1Vm7edm"
feedback_form: "https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqC4YDsCJ3llAvEZelBFBLUBURFVUTzFDTUJPQlM4M0laTE5DTlNFSjJBQi4u"
organisation:
created: "%{organisation} was created."
updated: "Organisation details updated."

7
config/locales/validations/lettings/household.en.yml

@ -28,6 +28,7 @@ en:
reason:
leaving_last_settled_home:
dont_know_required: "Answer must be ‘don’t know’ as you told us you don’t know the tenant’s main reason for leaving."
not_internal_transfer: "Answer cannot be ‘permanently decanted from another property owned by this landlord’ as you told us the source of referral for this tenancy was not an internal transfer."
other_not_settled: "Please give the reason for the tenant leaving their last settled home. This is where they were living before they became homeless, were living in temporary accommodation or sleeping rough."
condition_effects:
@ -101,5 +102,11 @@ en:
referral:
prevten_invalid: "Answer cannot be internal transfer as the household situation immediately before this letting was %{prevten}."
leaving_last_settled_home:
reason_permanently_decanted: "Answer must be internal transfer as the tenant was permanently decanted from another property owned by this landlord."
la_general_needs:
internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting."
referral_type:
leaving_last_settled_home:
reason_permanently_decanted: "Answer must be from a PRP-only housing register or waiting list (no local authority involvement) as the tenant was permanently decanted from another property owned by this landlord."

67
docs/setup.md

@ -22,8 +22,6 @@ We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage NodeJS version
1. Install PostgreSQL
If you already have a valid Postgres installation you can skip this step.
macOS:
```bash
@ -40,8 +38,6 @@ We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage NodeJS version
2. Create a Postgres user
If you already have a valid Postgres installation you can skip this step.
```bash
sudo su - postgres -c "createuser <username> -s -P"
```
@ -88,22 +84,35 @@ We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage NodeJS version
brew install yarn
```
or you could run it without specifying the version and it should use the version from .nvmrc
```bash
nvm install
nvm use
brew install yarn
```
Linux (Debian):
```bash
npm install --global yarn
curl -sL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt -y install nodejs
mkdir -p ~/.npm-packages
npm config set prefix ~/.npm-packages
echo 'NPM_PACKAGES="~/.npm-packages"' >> ~/.bashrc
echo 'export PATH="$PATH:$NPM_PACKAGES/bin"' >> ~/.bashrc
source ~/.bashrc
npm install --location=global yarn
```
6. (For running tests) Install Gecko Driver
Linux (Debian):
Find the latest version at https://github.com/mozilla/geckodriver/releases/, right click the linux64.tar.gz download and copy URL.
```bash
wget <url copied>
tar -xvzf <file downloaded>
rm <file downloaded>
wget https://github.com/mozilla/geckodriver/releases/download/v0.31.0/geckodriver-v0.31.0-linux64.tar.gz
tar -xvzf geckodriver-v0.31.0-linux64.tar.gz
rm geckodriver-v0.31.0-linux64.tar.gz
chmod +x geckodriver
sudo mv geckodriver /usr/local/bin/
```
@ -138,30 +147,22 @@ Also ensure you have firefox installed
bundle exec rake db:seed
```
5. Build assets once before running the app for the first time:
```bash
yarn build --mode=development
```
6. For Ordinance Survey related functionality, such as using the UPRN, you will need to set `OS_DATA_KEY` in your .env file. This key is shared across the team and can be found in AWS Secrets Manager.
7. For email functionality, you will need a GOV.UK Notify API key, which is individual to you. Ask an existing team member to invite you to the "CORE Helpdesk" Notify service. Once invited, sign in and go to "API integration" to generate an API key, and set this as `GOVUK_NOTIFY_API_KEY` in your .env file.
5. For Ordinance Survey related functionality, such as using the UPRN, you will need to set `OS_DATA_KEY` in your .env file. This key is shared across the team and can be found in AWS Secrets Manager.
6. For email functionality, you will need a GOV.UK Notify API key, which is individual to you. Ask an existing team member to invite you to the "CORE Helpdesk" Notify service. Once invited, sign in and go to "API integration" to generate an API key, and set this as `GOVUK_NOTIFY_API_KEY` in your .env file.
## Running Locally
### Application
Start the dev servers via one of the following methods:
Start the dev servers
a. If using RubyMine, run the "submit-social-housing-lettings-and-sales-data" Rails configuration.
b. Using Foreman:
a. Using Foreman:
```bash
./bin/dev
```
c. Individually:
b. Individually:
Rails:
@ -175,18 +176,20 @@ JavaScript (for hot reloading):
yarn build --mode=development --watch
```
If you’re not modifying front end assets you can bundle them as a one off task:
```bash
yarn build --mode=development
```
Development mode will target the latest versions of Chrome, Firefox and Safari for transpilation while production mode will target older browsers.
The Rails server will start on <http://localhost:3000>.
To sign in locally, you can use any username and password from your local database. The seed task in `seeds.rb` creates users in various roles all with the password `REVIEW_APP_USER_PASSWORD` from your .env file (which has default value `password`).
To create any other users, you can log in as a support user and create new users via the admin interface. Or, you can edit the seed commands, or run similar commands in the rails console.
To create any other users, you can edit the seed commands, or run similar commands in the rails console.
You can also insert a new user row using SQL, but you will need to generate a correctly encrypted password. You can find the value to use for encrypted password which corresponds to the password `YOURPASSWORDHERE` using `User.new(:password => [YOURPASSWORDHERE]).encrypted_password`.
### rbenv
In general, whenever needing to run a Ruby command, use `bundle exec <command>` to ensure the correct Ruby version and gemset are used. Rbenv will automatically use the correct Ruby version.
### Debugging
Add the line `binding.pry` to the code to pause the execution of the code at that line and open a powerful interactive console for debugging.
@ -216,8 +219,6 @@ More details on debugging in RubyMine can be found at <https://www.jetbrains.com
bundle exec rspec
```
Or if using RubyMine, right click a spec file and select the 'Run' option.
To run a specific folder use
```bash
@ -232,12 +233,6 @@ bundle exec rspec ./spec/path/to/file.rb
or run individual files/tests from your IDE
If you have made database changes, you may need to run the migrations for the test database:
```bash
bundle exec rake db:migrate RAILS_ENV=test
```
### Feature toggles
Feature toggles can be found in `app/services/feature_toggle.rb`

13
spec/features/user_spec.rb

@ -608,19 +608,6 @@ RSpec.describe "User Features" do
click_button("Resend invite link")
end
end
context "when reactivating a user" do
let!(:other_user) { create(:user, name: "Other name", active: false, organisation: user.organisation, last_sign_in_at: Time.zone.now, confirmed_at: nil) }
it "allows for reactivation email to be resent" do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in(user)
visit(user_path(other_user))
click_link("Reactivate user")
click_button("I’m sure – reactivate this user")
expect(page).to have_button("Resend invite link")
end
end
end
context "when the user is a customer support person" do

8
spec/models/validations/household_validations_spec.rb

@ -116,17 +116,17 @@ RSpec.describe Validations::HouseholdValidations do
end
context "when referral is not internal transfer" do
it "can be permanently decanted from another property owned by this landlord" do
it "cannot be permanently decanted from another property owned by this landlord" do
record.reason = 1
record.referral_type = 1
record.referral = 2
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"])
.to be_empty
.to include(match(I18n.t("validations.lettings.household.reason.leaving_last_settled_home.not_internal_transfer")))
expect(record.errors["referral"])
.to be_empty
.to include(match(I18n.t("validations.lettings.household.referral.leaving_last_settled_home.reason_permanently_decanted")))
expect(record.errors["referral_type"])
.to be_empty
.to include(match(I18n.t("validations.lettings.household.referral_type.leaving_last_settled_home.reason_permanently_decanted")))
end
end

16
spec/services/exports/lettings_log_export_service_spec.rb

@ -550,22 +550,6 @@ RSpec.describe Exports::LettingsLogExportService do
export_service.export_xml_lettings_logs(collection_year: current_collection_start_year)
end
it "does export the lettings log if owning_organisation name change is created" do
create(:organisation_name_change, organisation: owning_organisation)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
export_service.export_xml_lettings_logs(collection_year: current_collection_start_year)
end
it "does export the lettings log if managing_organisation name change is created" do
create(:organisation_name_change, organisation: managing_organisation)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
export_service.export_xml_lettings_logs(collection_year: current_collection_start_year)
end
end
end

16
spec/services/exports/sales_log_export_service_spec.rb

@ -491,22 +491,6 @@ RSpec.describe Exports::SalesLogExportService do
export_service.export_xml_sales_logs(collection_year: current_collection_start_year)
end
it "does export the sales log if owning_organisation name change is created" do
create(:organisation_name_change, organisation: owning_organisation)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
export_service.export_xml_sales_logs(collection_year: current_collection_start_year)
end
it "does export the sales log if managing_organisation name change is created" do
create(:organisation_name_change, organisation: managing_organisation)
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
export_service.export_xml_sales_logs(collection_year: current_collection_start_year)
end
end
end
end

25
spec/services/merge/merge_organisations_service_spec.rb

@ -728,31 +728,6 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(incomplete_lettings_log.location).to be_nil
end
it "associates correct lettings logs with correct locations which share a name and postcode" do
scheme = create(:scheme, owning_organisation: merging_organisation)
location_0 = create(:location, scheme:, name: "duplicate name", postcode: "EE1 1EE", location_admin_district: "dist1", startdate: Time.zone.today)
location_1 = create(:location, scheme:, name: "duplicate name", postcode: "EE1 1EE", location_admin_district: "dist2", startdate: Time.zone.today)
location_2 = create(:location, scheme:, name: "duplicate name", postcode: "EE1 1EE", location_admin_district: "dist3", startdate: Time.zone.today)
lettings_log_0 = build(:lettings_log, scheme:, owning_organisation: merging_organisation, startdate: Time.zone.today, location: location_0)
lettings_log_0.save!(validate: false)
lettings_log_1 = build(:lettings_log, scheme:, owning_organisation: merging_organisation, startdate: Time.zone.today, location: location_1)
lettings_log_1.save!(validate: false)
lettings_log_2 = build(:lettings_log, scheme:, owning_organisation: merging_organisation, startdate: Time.zone.today, location: location_2)
lettings_log_2.save!(validate: false)
expect(Rails.logger).not_to receive(:error)
merge_organisations_service.call
lettings_log_0.reload
lettings_log_1.reload
lettings_log_2.reload
expect(lettings_log_0.location.location_admin_district).to eq("dist1")
expect(lettings_log_1.location.location_admin_district).to eq("dist2")
expect(lettings_log_2.location.location_admin_district).to eq("dist3")
end
context "with merge date in closed collection year" do
subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.local(2021, 3, 3)) }

Loading…
Cancel
Save