Replace Bzip2Uploader#decompressed with #decompressed_path
This commit is contained in:
parent
7fce3537d3
commit
fa4c5e4664
@ -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
|
||||
|
@ -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(<<EOS)
|
||||
it 'returns a path to the decompressed data' do
|
||||
expect(decompressed_data).to eq(<<EOS)
|
||||
Edvard Munch - The Scream
|
||||
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXP
|
||||
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXY?""" .
|
||||
|
Loading…
Reference in New Issue
Block a user