Browse Source

Refactor

pull/2144/head
Kat 2 years ago
parent
commit
c0b927cf1e
  1. 121
      app/services/bulk_update_from_csv/update_locations_from_csv_service.rb
  2. 103
      app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb
  3. 196
      lib/tasks/update_schemes_and_locations_from_csv.rake
  4. 58
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

121
app/services/bulk_update_from_csv/update_locations_from_csv_service.rb

@ -0,0 +1,121 @@
class BulkUpdateFromCsv::UpdateLocationsFromCsvService
def initialize(original_file_name:, updated_file_name:)
@original_file_name = original_file_name
@updated_file_name = updated_file_name
end
def call
s3_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
original_locations_csv = csv_from_path(@original_file_name, s3_service)
updated_locations_csv = csv_from_path(@updated_file_name, s3_service)
updated_locations_csv.each do |row|
updated_attributes = attributes_from_row(row)
original_row = original_locations_csv.find { |original_locations_row| original_locations_row[1] == updated_attributes["location_code"] }
if original_row.blank? || original_row["location_code"].nil?
Rails.logger.info("Location with id #{updated_attributes['location_code']} is not in the original location csv")
next
end
original_attributes = attributes_from_row(original_row)
location = Location.find_by(id: original_attributes["location_code"])
if location.blank?
Rails.logger.info("Location with id #{original_attributes['location_code']} is not in the database")
next
end
updated_attributes.each do |key, value|
next unless value != original_attributes[key] && value.present?
case key
when "location_admin_district"
update_location_admin_district(location, original_attributes, value)
when "postcode"
update_postcode(location, original_attributes, value)
when "scheme_code"
update_scheme(location, original_attributes, value)
when "name", "units", "type_of_unit", "mobility_type"
begin
location[key] = value
Rails.logger.info("Updating location #{original_attributes['location_code']} with #{key}: #{value}")
rescue ArgumentError => e
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key}: #{value}. #{e.message}")
end
when "location_code", "status", "active_dates"
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key} as it it not a permitted field")
end
end
unless location.changed?
Rails.logger.info("No changes to location #{original_attributes['location_code']}.")
next
end
save_location(location, original_attributes)
end
end
private
def csv_from_path(path, s3_service)
original_file_io = s3_service.get_file_io(path)
original_file_io.set_encoding_by_bom
CSV.parse(original_file_io, headers: true)
end
def attributes_from_row(row)
attributes = {}
attributes["scheme_code"] = row[0]
attributes["location_code"] = row[1]
attributes["postcode"] = row[2]
attributes["name"] = row[3]
attributes["status"] = row[4]
attributes["location_admin_district"] = row[5]
attributes["units"] = row[6]
attributes["type_of_unit"] = row[7]
attributes["mobility_type"] = row[8]
attributes["active_dates"] = row[9]
attributes
end
def update_location_admin_district(location, original_attributes, value)
location_code = Location.local_authorities_for_current_year.key(value)
if location_code.present?
location.location_code = location_code
location.location_admin_district = value
Rails.logger.info("Updating location #{original_attributes['location_code']} with location_code: #{location_code}")
else
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with location_admin_district: #{value}. Location admin distrint #{value} is not a valid option")
end
end
def update_postcode(location, original_attributes, value)
if !value&.match(POSTCODE_REGEXP)
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with postcode: #{value}. #{I18n.t('validations.postcode')}")
else
location.postcode = PostcodeService.clean(value)
Rails.logger.info("Updating location #{original_attributes['location_code']} with postcode: #{value}")
end
end
def update_scheme(location, original_attributes, value)
scheme = Scheme.find_by(id: value.delete("S"))
if scheme.present?
location["scheme_id"] = scheme.id
Rails.logger.info("Updating location #{original_attributes['location_code']} with scheme: S#{scheme.id}")
else
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with scheme_code: #{value}. Scheme with id #{value} is not in the database")
end
end
def save_location(location, original_attributes)
location.save!
Rails.logger.info("Saved location #{original_attributes['location_code']}.")
LettingsLog.where(location_id: location.id).update_all(values_updated_at: Time.zone.now)
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error("Cannot update location #{original_attributes['location_code']}. #{e.message}")
end
end

103
app/services/bulk_update_from_csv/update_schemes_from_csv_service.rb

@ -0,0 +1,103 @@
class BulkUpdateFromCsv::UpdateSchemesFromCsvService
def initialize(original_file_name:, updated_file_name:)
@original_file_name = original_file_name
@updated_file_name = updated_file_name
end
def call
s3_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
original_schemes_csv = csv_from_path(@original_file_name, s3_service)
updated_schemes_csv = csv_from_path(@updated_file_name, s3_service)
updated_schemes_csv.each do |row|
updated_attributes = attributes_from_row(row)
original_row = original_schemes_csv.find { |original_schemes_row| original_schemes_row[0] == updated_attributes["scheme_code"] }
if original_row.blank? || original_row["scheme_code"].nil?
Rails.logger.info("Scheme with id #{updated_attributes['scheme_code']} is not in the original scheme csv")
next
end
original_attributes = attributes_from_row(original_row)
scheme = Scheme.find_by(id: original_attributes["scheme_code"].delete("S"))
if scheme.blank?
Rails.logger.info("Scheme with id #{original_attributes['scheme_code']} is not in the database")
next
end
updated_attributes.each do |key, value|
next unless value != original_attributes[key] && value.present?
case key
when "owning_organisation"
update_owning_organisation(scheme, original_attributes, value)
when "service_name", "sensitive", "scheme_type", "registered_under_care_act", "arrangement_type", "primary_client_group", "has_other_client_group", "secondary_client_group", "support_type", "intended_stay"
begin
scheme[key] = value
Rails.logger.info("Updating scheme #{original_attributes['scheme_code']} with #{key}: #{value}")
rescue ArgumentError => e
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with #{key}: #{value}. #{e.message}")
end
when "scheme_code", "status", "created_at", "active_dates"
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with #{key} as it it not a permitted field")
end
end
unless scheme.changed?
Rails.logger.info("No changes to scheme #{original_attributes['scheme_code']}.")
next
end
save_scheme(scheme, original_attributes)
end
end
private
def csv_from_path(path, s3_service)
original_file_io = s3_service.get_file_io(path)
original_file_io.set_encoding_by_bom
CSV.parse(original_file_io, headers: true)
end
def attributes_from_row(row)
attributes = {}
attributes["scheme_code"] = row[0]
attributes["service_name"] = row[1]
attributes["status"] = row[2]
attributes["sensitive"] = row[3]
attributes["scheme_type"] = row[4]
attributes["registered_under_care_act"] = row[5]
attributes["owning_organisation"] = row[6]
attributes["arrangement_type"] = row[7]
attributes["primary_client_group"] = row[8]
attributes["has_other_client_group"] = row[9]
attributes["secondary_client_group"] = row[10]
attributes["support_type"] = row[11]
attributes["intended_stay"] = row[12]
attributes["created_at"] = row[13]
attributes["active_dates"] = row[14]
attributes
end
def update_owning_organisation(scheme, original_attributes, value)
organisation = Organisation.find_by(name: value)
if organisation.present?
scheme["owning_organisation_id"] = organisation.id
Rails.logger.info("Updating scheme #{original_attributes['scheme_code']} with owning_organisation: #{organisation.name}")
else
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with owning_organisation: #{value}. Organisation with name #{value} is not in the database")
end
end
def save_scheme(scheme, original_attributes)
scheme.save!
Rails.logger.info("Saved scheme #{original_attributes['scheme_code']}.")
LettingsLog.where(scheme_id: scheme.id).update_all(values_updated_at: Time.zone.now)
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error("Cannot update scheme #{original_attributes['scheme_code']}. #{e.message}")
end
end

196
lib/tasks/update_schemes_and_locations_from_csv.rake

@ -6,100 +6,7 @@ namespace :bulk_update do
raise "Usage: rake bulk_update:update_schemes_from_csv['original_file_name','updated_file_name']" if original_file_name.blank? || updated_file_name.blank?
s3_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
original_file_io = s3_service.get_file_io(original_file_name)
original_file_io.set_encoding_by_bom
original_schemes_csv = CSV.parse(original_file_io, headers: true)
updated_file_io = s3_service.get_file_io(updated_file_name)
updated_file_io.set_encoding_by_bom
updated_schemes_csv = CSV.parse(updated_file_io, headers: true)
updated_schemes_csv.each do |row|
original_attributes = {}
updated_attributes = {}
updated_attributes["scheme_code"] = row[0]
updated_attributes["service_name"] = row[1]
updated_attributes["status"] = row[2]
updated_attributes["sensitive"] = row[3]
updated_attributes["scheme_type"] = row[4]
updated_attributes["registered_under_care_act"] = row[5]
updated_attributes["owning_organisation_name"] = row[6]
updated_attributes["arrangement_type"] = row[7]
updated_attributes["primary_client_group"] = row[8]
updated_attributes["has_other_client_group"] = row[9]
updated_attributes["secondary_client_group"] = row[10]
updated_attributes["support_type"] = row[11]
updated_attributes["intended_stay"] = row[12]
updated_attributes["created_at"] = row[13]
updated_attributes["active_dates"] = row[14]
original_row = original_schemes_csv.find { |original_schemes_row| original_schemes_row[0] == updated_attributes["scheme_code"] }
if original_row.blank? || original_row["scheme_code"].nil?
Rails.logger.info("Scheme with id #{updated_attributes['scheme_code']} is not in the original scheme csv")
next
end
original_attributes["scheme_code"] = original_row[0]
original_attributes["service_name"] = original_row[1]
original_attributes["status"] = original_row[2]
original_attributes["sensitive"] = original_row[3]
original_attributes["scheme_type"] = original_row[4]
original_attributes["registered_under_care_act"] = original_row[5]
original_attributes["owning_organisation_name"] = original_row[6]
original_attributes["arrangement_type"] = original_row[7]
original_attributes["primary_client_group"] = original_row[8]
original_attributes["has_other_client_group"] = original_row[9]
original_attributes["secondary_client_group"] = original_row[10]
original_attributes["support_type"] = original_row[11]
original_attributes["intended_stay"] = original_row[12]
original_attributes["created_at"] = original_row[13]
original_attributes["active_dates"] = original_row[14]
scheme = Scheme.find_by(id: original_attributes["scheme_code"].delete("S"))
if scheme.blank?
Rails.logger.info("Scheme with id #{original_attributes['scheme_code']} is not in the database")
next
end
updated_attributes.each do |key, value|
next unless value != original_attributes[key] && value.present?
case key
when "service_name", "sensitive", "scheme_type", "registered_under_care_act", "arrangement_type", "primary_client_group", "has_other_client_group", "secondary_client_group", "support_type", "intended_stay"
begin
scheme[key] = value
Rails.logger.info("Updating scheme #{original_attributes['scheme_code']}, with #{key}: #{value}")
rescue ArgumentError => e
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with #{key}: #{value}. #{e.message}")
end
when "owning_organisation_name"
organisation = Organisation.find_by(name: value)
if organisation.present?
scheme["owning_organisation_id"] = organisation.id
Rails.logger.info("Updating scheme #{original_attributes['scheme_code']}, with owning_organisation: #{organisation.name}")
else
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with #{key}: #{value}. Organisation with name #{value} is not in the database")
end
when "scheme_code", "status", "created_at", "active_dates"
Rails.logger.info("Cannot update scheme #{original_attributes['scheme_code']} with #{key} as it it not a permitted field")
end
end
unless scheme.changed?
Rails.logger.info("No changes to scheme #{original_attributes['scheme_code']}.")
next
end
begin
scheme.save!
Rails.logger.info("Saved scheme #{original_attributes['scheme_code']}.")
LettingsLog.where(scheme_id: scheme.id).update_all(values_updated_at: Time.zone.now)
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error("Cannot update scheme #{original_attributes['scheme_code']}. #{e.message}")
end
end
BulkUpdateFromCsv::UpdateSchemesFromCsvService.new(original_file_name:, updated_file_name:).call
end
desc "Bulk update location data from a csv file"
@ -109,105 +16,6 @@ namespace :bulk_update do
raise "Usage: rake bulk_update:update_locations_from_csv['original_file_name','updated_file_name']" if original_file_name.blank? || updated_file_name.blank?
s3_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
original_file_io = s3_service.get_file_io(original_file_name)
original_file_io.set_encoding_by_bom
original_locations_csv = CSV.parse(original_file_io, headers: true)
updated_file_io = s3_service.get_file_io(updated_file_name)
updated_file_io.set_encoding_by_bom
updated_locations_csv = CSV.parse(updated_file_io, headers: true)
updated_locations_csv.each do |row|
original_attributes = {}
updated_attributes = {}
updated_attributes["scheme_code"] = row[0]
updated_attributes["location_code"] = row[1]
updated_attributes["postcode"] = row[2]
updated_attributes["name"] = row[3]
updated_attributes["status"] = row[4]
updated_attributes["location_admin_district"] = row[5]
updated_attributes["units"] = row[6]
updated_attributes["type_of_unit"] = row[7]
updated_attributes["mobility_type"] = row[8]
updated_attributes["active_dates"] = row[9]
original_row = original_locations_csv.find { |original_locations_row| original_locations_row[1] == updated_attributes["location_code"] }
if original_row.blank? || original_row["location_code"].nil?
Rails.logger.info("Location with id #{updated_attributes['location_code']} is not in the original location csv")
next
end
original_attributes["scheme_code"] = original_row[0]
original_attributes["location_code"] = original_row[1]
original_attributes["postcode"] = original_row[2]
original_attributes["name"] = original_row[3]
original_attributes["status"] = original_row[4]
original_attributes["location_admin_district"] = original_row[5]
original_attributes["units"] = original_row[6]
original_attributes["type_of_unit"] = original_row[7]
original_attributes["mobility_type"] = original_row[8]
original_attributes["active_dates"] = original_row[9]
location = Location.find_by(id: original_attributes["location_code"])
if location.blank?
Rails.logger.info("Location with id #{original_attributes['location_code']} is not in the database")
next
end
updated_attributes.each do |key, value|
next unless value != original_attributes[key] && value.present?
case key
when "location_admin_district"
location_code = Location.local_authorities_for_current_year.key(value)
if location_code.present?
location.location_code = location_code
location.location_admin_district = value
Rails.logger.info("Updating location #{original_attributes['location_code']}, with location_code: #{location_code}")
else
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key}: #{value}. Location admin distrint #{value} is not a valid option")
end
when "postcode"
if !value&.match(POSTCODE_REGEXP)
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key}: #{value}. #{I18n.t('validations.postcode')}")
else
location.postcode = PostcodeService.clean(value)
Rails.logger.info("Updating location #{original_attributes['location_code']}, with postcode: #{value}")
end
when "name", "units", "type_of_unit", "mobility_type"
begin
location[key] = value
Rails.logger.info("Updating location #{original_attributes['location_code']}, with #{key}: #{value}")
rescue ArgumentError => e
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key}: #{value}. #{e.message}")
end
when "scheme_code"
scheme = Scheme.find_by(id: value.delete("S"))
if scheme.present?
location["scheme_id"] = scheme.id
Rails.logger.info("Updating location #{original_attributes['location_code']}, with scheme: S#{scheme.id}")
else
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key}: #{value}. Scheme with id #{value} is not in the database")
end
when "location_code", "status", "active_dates"
Rails.logger.info("Cannot update location #{original_attributes['location_code']} with #{key} as it it not a permitted field")
end
end
unless location.changed?
Rails.logger.info("No changes to location #{original_attributes['location_code']}.")
next
end
begin
location.save!
Rails.logger.info("Saved location #{original_attributes['location_code']}.")
LettingsLog.where(location_id: location.id).update_all(values_updated_at: Time.zone.now)
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error("Cannot update location #{original_attributes['location_code']}. #{e.message}")
end
end
BulkUpdateFromCsv::UpdateLocationsFromCsvService.new(original_file_name:, updated_file_name:).call
end
end

58
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -149,17 +149,16 @@ RSpec.describe "bulk_update" do
end
it "logs the progress of the update" do
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with service_name: Updated test name")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with sensitive: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with scheme_type: Direct Access Hostel")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with arrangement_type: Another registered stock owner")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with primary_client_group: People with drug problems")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with has_other_client_group: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with support_type: Low level")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with intended_stay: Permanent")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with registered_under_care_act: No")
# expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with secondary_client_group: nil")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with owning_organisation: Different organisation")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with service_name: Updated test name")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with sensitive: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with scheme_type: Direct Access Hostel")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with arrangement_type: Another registered stock owner")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with primary_client_group: People with drug problems")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with has_other_client_group: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with support_type: Low level")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with intended_stay: Permanent")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with registered_under_care_act: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with owning_organisation: Different organisation")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[0].id} with status as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[0].id} with created_at as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[0].id} with active_dates as it it not a permitted field")
@ -169,7 +168,7 @@ RSpec.describe "bulk_update" do
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with sensitive: Yse. 'Yse' is not a valid sensitive")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with scheme_type: Direct access Hostel. 'Direct access Hostel' is not a valid scheme_type")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with owning_organisation_name: non existing org. Organisation with name non existing org is not in the database")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with owning_organisation: non existing org. Organisation with name non existing org is not in the database")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with arrangement_type: wrong answer. 'wrong answer' is not a valid arrangement_type")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with primary_client_group: FD. 'FD' is not a valid primary_client_group")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with has_other_client_group: no. 'no' is not a valid has_other_client_group")
@ -200,17 +199,16 @@ RSpec.describe "bulk_update" do
it "logs an error if a validation fails and processes the rest of the rows" do
schemes[1].support_type = nil
schemes[1].save!(validate: false)
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with service_name: Updated test name")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with sensitive: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with scheme_type: Direct Access Hostel")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with arrangement_type: Another registered stock owner")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with primary_client_group: People with drug problems")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with has_other_client_group: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with support_type: Low level")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with intended_stay: Permanent")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with registered_under_care_act: No")
# expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with secondary_client_group: nil")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id}, with owning_organisation: Different organisation")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with service_name: Updated test name")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with sensitive: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with scheme_type: Direct Access Hostel")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with arrangement_type: Another registered stock owner")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with primary_client_group: People with drug problems")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with has_other_client_group: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with support_type: Low level")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with intended_stay: Permanent")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with registered_under_care_act: No")
expect(Rails.logger).to receive(:info).with("Updating scheme S#{schemes[0].id} with owning_organisation: Different organisation")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[0].id} with status as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[0].id} with created_at as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[0].id} with active_dates as it it not a permitted field")
@ -220,7 +218,7 @@ RSpec.describe "bulk_update" do
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with sensitive: Yse. 'Yse' is not a valid sensitive")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with scheme_type: Direct access Hostel. 'Direct access Hostel' is not a valid scheme_type")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with owning_organisation_name: non existing org. Organisation with name non existing org is not in the database")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with owning_organisation: non existing org. Organisation with name non existing org is not in the database")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with arrangement_type: wrong answer. 'wrong answer' is not a valid arrangement_type")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with primary_client_group: FD. 'FD' is not a valid primary_client_group")
expect(Rails.logger).to receive(:info).with("Cannot update scheme S#{schemes[2].id} with has_other_client_group: no. 'no' is not a valid has_other_client_group")
@ -339,12 +337,12 @@ RSpec.describe "bulk_update" do
end
it "logs the progress of the update" do
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id}, with postcode: B11BB")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id}, with name: Updated name")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id}, with type_of_unit: Bungalow")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id}, with units: 10")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id}, with mobility_type: Wheelchair-user standard")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id}, with scheme: S#{different_scheme.id}")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with postcode: B11BB")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with name: Updated name")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with type_of_unit: Bungalow")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with units: 10")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with mobility_type: Wheelchair-user standard")
expect(Rails.logger).to receive(:info).with("Updating location #{locations[0].id} with scheme: S#{different_scheme.id}")
expect(Rails.logger).to receive(:info).with("Cannot update location #{locations[0].id} with status as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Cannot update location #{locations[0].id} with active_dates as it it not a permitted field")
expect(Rails.logger).to receive(:info).with("Saved location #{locations[0].id}.")

Loading…
Cancel
Save