Browse Source

correct minor error and linting

pull/1268/head
Arthur Campbell 3 years ago
parent
commit
c7c63f6333
  1. 2
      app/jobs/email_csv_job.rb
  2. 6
      app/services/csv/lettings_log_csv_service.rb
  3. 12
      spec/models/lettings_log_spec.rb

2
app/jobs/email_csv_job.rb

@ -12,7 +12,7 @@ class EmailCsvJob < ApplicationJob
filename = organisation.present? ? "logs-#{organisation.name}-#{Time.zone.now}.csv" : "logs-#{Time.zone.now}.csv" filename = organisation.present? ? "logs-#{organisation.name}-#{Time.zone.now}.csv" : "logs-#{Time.zone.now}.csv"
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"]) storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
storage_service.write_file(filename, BYTE_ORDER_MARK + filtered_logs.to_csv(user, is_codes_only_export)) storage_service.write_file(filename, BYTE_ORDER_MARK + filtered_logs.to_csv(user, is_codes_only_export:))
url = storage_service.get_presigned_url(filename, EXPIRATION_TIME) url = storage_service.get_presigned_url(filename, EXPIRATION_TIME)

6
app/services/csv/lettings_log_csv_service.rb

@ -26,9 +26,9 @@ module Csv
record.send(att) record.send(att)
elsif %w[mrcdate startdate voiddate].include? att elsif %w[mrcdate startdate voiddate].include? att
record.send(att)&.to_formatted_s(:govuk_date) record.send(att)&.to_formatted_s(:govuk_date)
elsif is_codes_only_export && (att.start_with?("location_", "scheme_")) elsif is_codes_only_export && att.start_with?("location_", "scheme_")
att = att + "_before_type_cast" unless %w[location_code scheme_code scheme_owning_organisation_name scheme_created_at location_startdate].include? att att += "_before_type_cast" unless %w[location_code scheme_code scheme_owning_organisation_name scheme_created_at location_startdate].include? att
value = record.send(att) record.send(att)
else else
att = att.remove("_label", "_detail") # a couple of csv column headers have suffixes for the user that are not reflected in the app domain att = att.remove("_label", "_detail") # a couple of csv column headers have suffixes for the user that are not reflected in the app domain
field_value = record.send(att) field_value = record.send(att)

12
spec/models/lettings_log_spec.rb

@ -2688,7 +2688,7 @@ RSpec.describe LettingsLog do
after do after do
Timecop.unfreeze Timecop.unfreeze
end end
context "with values represented as human readable labels" do context "with values represented as human readable labels" do
before do before do
Timecop.freeze(Time.utc(2022, 6, 5)) Timecop.freeze(Time.utc(2022, 6, 5))
@ -2707,18 +2707,18 @@ RSpec.describe LettingsLog do
expected_content.sub!(/\{location_id\}/, location["id"].to_s) expected_content.sub!(/\{location_id\}/, location["id"].to_s)
expected_content.gsub!("\r\n", "\n") expected_content.gsub!("\r\n", "\n")
end end
context "with a support user" do context "with a support user" do
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") } let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") }
it "generates a correct csv from a lettings log" do it "generates a correct csv from a lettings log" do
expect(described_class.to_csv(is_codes_only_export: false).strip).to eq(expected_content.strip) expect(described_class.to_csv(is_codes_only_export: false).strip).to eq(expected_content.strip)
end end
end end
context "with a non support user" do context "with a non support user" do
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_non_support.csv", "r:UTF-8") } let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_non_support.csv", "r:UTF-8") }
it "generates a correct csv from a lettings log" do it "generates a correct csv from a lettings log" do
expect(described_class.to_csv(user, is_codes_only_export: false).strip).to eq(expected_content.strip) expect(described_class.to_csv(user, is_codes_only_export: false).strip).to eq(expected_content.strip)
end end
@ -2743,7 +2743,7 @@ RSpec.describe LettingsLog do
expected_content.sub!(/\{location_id\}/, location.id.to_s) expected_content.sub!(/\{location_id\}/, location.id.to_s)
expected_content.gsub!("\r\n", "\n") expected_content.gsub!("\r\n", "\n")
end end
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_codes_only.csv", "r:UTF-8") } let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_codes_only.csv", "r:UTF-8") }
it "generates a correct csv from a lettings log" do it "generates a correct csv from a lettings log" do

Loading…
Cancel
Save