Skip to content

Commit

Permalink
wip: new test for gzippiness
Browse files Browse the repository at this point in the history
  • Loading branch information
robbkidd committed May 14, 2019
1 parent 7042ef8 commit 00d941a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/supermarket/app/models/cookbook_upload/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def read(path)
#
def each_entry
raise NoPath unless @source.respond_to?(:path)
raise NotGzipped unless gzipped?(@source.path)
raise NotGzipped if !gzipped?

begin
::Archive::Reader.open_filename(@source.path) do |tar|
Expand All @@ -112,17 +112,10 @@ def each_entry
#
# Determines whether a file at a path is gzipped or not
#
#
# @return true/false
#
# @example
# archive = CookbookUpload::Archive.new(tarball)
# archive.each do |entry|
# puts "#{entry.full_name} has the following content:\n#{entry.read}"
# end
#
def gzipped?(file_path)
FileMagic.mime.file(file_path) == "application/x-gzip; charset=binary"
def gzipped?
FileMagic.mime.file(@source.path).match? %r{application\/x?-?gzip;}
end
end
end
15 changes: 15 additions & 0 deletions src/supermarket/spec/models/cookbook_upload/archive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

describe CookbookUpload::Archive do
describe '#gzipped?' do
it 'returns true if a tar file is GZipped' do
tarball = described_class.new(File.new('spec/support/cookbook_fixtures/redis-test-v1.tgz'))
expect(tarball.send(:gzipped?)).to be true
end

it 'fails if a tar file is not GZipped' do
tarball = described_class.new(File.new('spec/support/cookbook_fixtures/not-actually-gzipped.tgz'))
expect(tarball.send(:gzipped?)).to be false
end
end
end

0 comments on commit 00d941a

Please sign in to comment.