From 235c8c2fb3253987509ac435ce5bd63ccc5318ae Mon Sep 17 00:00:00 2001 From: Jamie Little Date: Tue, 29 Oct 2019 11:07:48 -0500 Subject: [PATCH] Only show the basename for PreIngestFile This adds a method to the `PreIngestFile` model to get the basename for the stored filepath. Connected to https://github.com/curationexperts/in-house/issues/422 --- app/models/zizia/pre_ingest_file.rb | 4 ++++ app/views/zizia/csv_import_details/show.html.erb | 2 +- spec/factories/pre_ingest_file.rb | 13 +++++++++++++ spec/factories/pre_ingest_work.rb | 10 ++++++++++ spec/models/zizia/pre_ingest_file_spec.rb | 12 ++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 spec/factories/pre_ingest_file.rb create mode 100644 spec/factories/pre_ingest_work.rb create mode 100644 spec/models/zizia/pre_ingest_file_spec.rb diff --git a/app/models/zizia/pre_ingest_file.rb b/app/models/zizia/pre_ingest_file.rb index e645226..c23f79f 100644 --- a/app/models/zizia/pre_ingest_file.rb +++ b/app/models/zizia/pre_ingest_file.rb @@ -2,5 +2,9 @@ module Zizia class PreIngestFile < ::ApplicationRecord belongs_to :pre_ingest_work + + def basename + File.basename(filename) + end end end diff --git a/app/views/zizia/csv_import_details/show.html.erb b/app/views/zizia/csv_import_details/show.html.erb index f5f93bc..b4d0dcd 100644 --- a/app/views/zizia/csv_import_details/show.html.erb +++ b/app/views/zizia/csv_import_details/show.html.erb @@ -18,7 +18,7 @@ <% @csv_import_detail.pre_ingest_files.each do |pre_ingest_file| %> - <%= pre_ingest_file.filename %> + <%= pre_ingest_file.basename %> <%= number_to_human_size(pre_ingest_file.size) %> diff --git a/spec/factories/pre_ingest_file.rb b/spec/factories/pre_ingest_file.rb new file mode 100644 index 0000000..bc29afa --- /dev/null +++ b/spec/factories/pre_ingest_file.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +# This will guess the User class +FactoryBot.define do + factory :pre_ingest_file, class: Zizia::PreIngestFile do + pre_ingest_work_id { 1 } + created_at { Time.current } + updated_at { Time.current } + row_number { 1 } + row { 'sample,row' } + filename { '/a/path/to/my.csv' } + size { 100_203_424 } + end +end diff --git a/spec/factories/pre_ingest_work.rb b/spec/factories/pre_ingest_work.rb new file mode 100644 index 0000000..348cad6 --- /dev/null +++ b/spec/factories/pre_ingest_work.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true +# This will guess the User class +FactoryBot.define do + factory :pre_ingest_work, class: Zizia::PreIngestWork do + id { 1 } + created_at { Time.current } + updated_at { Time.current } + csv_import_detail_id { 1 } + end +end diff --git a/spec/models/zizia/pre_ingest_file_spec.rb b/spec/models/zizia/pre_ingest_file_spec.rb new file mode 100644 index 0000000..c5e9840 --- /dev/null +++ b/spec/models/zizia/pre_ingest_file_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +require 'rails_helper' + +RSpec.describe Zizia::PreIngestFile do + let(:pre_ingest_work) { FactoryBot.create(:pre_ingest_work) } + let(:pre_ingest_file) { FactoryBot.create(:pre_ingest_file, pre_ingest_work_id: pre_ingest_work.id) } + let(:basename) { 'my.csv' } + + it 'can get the basename for the file' do + expect(pre_ingest_file.basename).to eq(basename) + end +end