From a249b5b1eb7c36b58718e21693571aa70d4a169a Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 9 Dec 2022 09:29:14 +0000 Subject: [PATCH] store filename on bulk upload (#1071) --- app/models/forms/bulk_upload_lettings/upload_your_file.rb | 1 + app/models/forms/bulk_upload_sales/upload_your_file.rb | 1 + db/migrate/20221207113235_add_bulk_upload_filename.rb | 5 +++++ db/schema.rb | 3 ++- .../forms/bulk_upload_lettings/upload_your_file_spec.rb | 8 +++++++- .../forms/bulk_upload_sales/upload_your_file_spec.rb | 8 +++++++- 6 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20221207113235_add_bulk_upload_filename.rb diff --git a/app/models/forms/bulk_upload_lettings/upload_your_file.rb b/app/models/forms/bulk_upload_lettings/upload_your_file.rb index 0f6325b75..f49efafbf 100644 --- a/app/models/forms/bulk_upload_lettings/upload_your_file.rb +++ b/app/models/forms/bulk_upload_lettings/upload_your_file.rb @@ -35,6 +35,7 @@ module Forms user: current_user, log_type: BulkUpload.log_types[:lettings], year:, + filename: file.original_filename, ) if upload_enabled? diff --git a/app/models/forms/bulk_upload_sales/upload_your_file.rb b/app/models/forms/bulk_upload_sales/upload_your_file.rb index 7211d67a7..b8454000b 100644 --- a/app/models/forms/bulk_upload_sales/upload_your_file.rb +++ b/app/models/forms/bulk_upload_sales/upload_your_file.rb @@ -35,6 +35,7 @@ module Forms user: current_user, log_type: BulkUpload.log_types[:sales], year:, + filename: file.original_filename, ) if upload_enabled? diff --git a/db/migrate/20221207113235_add_bulk_upload_filename.rb b/db/migrate/20221207113235_add_bulk_upload_filename.rb new file mode 100644 index 000000000..1807893ec --- /dev/null +++ b/db/migrate/20221207113235_add_bulk_upload_filename.rb @@ -0,0 +1,5 @@ +class AddBulkUploadFilename < ActiveRecord::Migration[7.0] + def change + add_column :bulk_uploads, :filename, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f7d267ce..501f738aa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_12_06_081127) do +ActiveRecord::Schema[7.0].define(version: 2022_12_07_113235) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,6 +21,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_06_081127) do t.uuid "identifier", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "filename" t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["user_id"], name: "index_bulk_uploads_on_user_id" end diff --git a/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb b/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb index 1199201fa..5101d10a9 100644 --- a/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb +++ b/spec/models/forms/bulk_upload_lettings/upload_your_file_spec.rb @@ -5,7 +5,12 @@ RSpec.describe Forms::BulkUploadLettings::UploadYourFile do let(:year) { 2022 } let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } - let(:file) { ActionDispatch::Http::UploadedFile.new(tempfile: actual_file) } + let(:file) do + ActionDispatch::Http::UploadedFile.new( + tempfile: actual_file, + filename: "my-file.csv", + ) + end let(:current_user) { create(:user) } let(:mock_storage_service) { instance_double("S3Service") } @@ -32,6 +37,7 @@ RSpec.describe Forms::BulkUploadLettings::UploadYourFile do expect(bulk_upload.user).to eql(current_user) expect(bulk_upload.log_type).to eql("lettings") expect(bulk_upload.year).to eql(year) + expect(bulk_upload.filename).to eql("my-file.csv") expect(bulk_upload.identifier).to be_present end diff --git a/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb b/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb index 1b11b0f82..8e7497633 100644 --- a/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb +++ b/spec/models/forms/bulk_upload_sales/upload_your_file_spec.rb @@ -5,7 +5,12 @@ RSpec.describe Forms::BulkUploadSales::UploadYourFile do let(:year) { 2022 } let(:actual_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } - let(:file) { ActionDispatch::Http::UploadedFile.new(tempfile: actual_file) } + let(:file) do + ActionDispatch::Http::UploadedFile.new( + tempfile: actual_file, + filename: "my-file.csv", + ) + end let(:current_user) { create(:user) } let(:mock_storage_service) { instance_double("S3Service") } @@ -32,6 +37,7 @@ RSpec.describe Forms::BulkUploadSales::UploadYourFile do expect(bulk_upload.user).to eql(current_user) expect(bulk_upload.log_type).to eql("sales") expect(bulk_upload.year).to eql(year) + expect(bulk_upload.filename).to eql("my-file.csv") expect(bulk_upload.identifier).to be_present end