From fa4c5e4664e2ed29737926b49d7c8756cb1e1cd0 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Tue, 13 Aug 2013 19:46:43 +0200 Subject: [PATCH] Replace Bzip2Uploader#decompressed with #decompressed_path --- app/uploaders/bzip2_uploader.rb | 12 +++++------- spec/uploaders/bzip2_uploader_spec.rb | 12 ++++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/uploaders/bzip2_uploader.rb b/app/uploaders/bzip2_uploader.rb index 459ebaa..8cb3f36 100644 --- a/app/uploaders/bzip2_uploader.rb +++ b/app/uploaders/bzip2_uploader.rb @@ -1,17 +1,15 @@ class Bzip2Uploader < BaseUploader - def decompressed + def decompressed_path return unless file + out_path = "#{path}.decompressed" - unless @decompressed + unless File.exist?(out_path) cache_stored_file! unless cached? - - file = IO.popen("bzip2 -d -c #{path}", "r") - @decompressed = file.read - file.close + system("bzip2 -d -k -c #{path} >#{out_path}") end - @decompressed + out_path end end diff --git a/spec/uploaders/bzip2_uploader_spec.rb b/spec/uploaders/bzip2_uploader_spec.rb index 8b68981..7f496ad 100644 --- a/spec/uploaders/bzip2_uploader_spec.rb +++ b/spec/uploaders/bzip2_uploader_spec.rb @@ -4,20 +4,24 @@ describe Bzip2Uploader do let(:uploader) { Bzip2Uploader.new(user, :photo) } let(:user) { User.new } - describe '#decompressed' do + describe '#decompressed_path' do + subject { uploader.decompressed_path } + context "when file wasn't stored" do it 'returns nil' do - expect(uploader.decompressed).to be(nil) + expect(subject).to be(nil) end end context "when file was stored" do + let(:decompressed_data) { File.read(subject) } + before do uploader.store!(File.open('spec/fixtures/munch.bz2')) end - it 'returns decompressed data as a string' do - expect(uploader.decompressed).to eq(<