From d84650917ae3eee95fc0aae31ad49fe824fe71d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mica=C3=ABl=20Bergeron?= Date: Tue, 30 Jan 2018 09:21:28 -0500 Subject: remove file after `Upload#destroy` it will also automatically prune empty directories for `FileUploader`-based uploaders. --- spec/uploaders/file_uploader_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'spec/uploaders') diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb index a559681a079..80af2a206af 100644 --- a/spec/uploaders/file_uploader_spec.rb +++ b/spec/uploaders/file_uploader_spec.rb @@ -48,6 +48,29 @@ describe FileUploader do end end + describe 'callbacks' do + describe '#prune_store_dir after :remove' do + before do + uploader.store!(fixture_file_upload('spec/fixtures/doc_sample.txt')) + end + + def store_dir + File.expand_path(uploader.store_dir, uploader.root) + end + + it 'is called' do + expect(uploader).to receive(:prune_store_dir).once + + uploader.remove! + end + + it 'prune the store directory' do + expect { uploader.remove! } + .to change { File.exists?(store_dir) }.from(true).to(false) + end + end + end + describe '#secret' do it 'generates a secret if none is provided' do expect(described_class).to receive(:generate_secret).and_return('secret') -- cgit v1.2.1 From 939391af7bc471f1588ab75ab0cf08d8e4286a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mica=C3=ABl=20Bergeron?= Date: Wed, 31 Jan 2018 10:59:35 -0500 Subject: improvements from feedback --- spec/uploaders/file_uploader_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/uploaders') diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb index 80af2a206af..6a92e7fae51 100644 --- a/spec/uploaders/file_uploader_spec.rb +++ b/spec/uploaders/file_uploader_spec.rb @@ -66,7 +66,7 @@ describe FileUploader do it 'prune the store directory' do expect { uploader.remove! } - .to change { File.exists?(store_dir) }.from(true).to(false) + .to change { File.exist?(store_dir) }.from(true).to(false) end end end -- cgit v1.2.1