FIX: `S3Helper#list` creates incorrect prefix.

This commit is contained in:
Guo Xiang Tan 2018-09-10 16:34:40 +08:00
parent 68572b8afc
commit df04e69cde
2 changed files with 19 additions and 1 deletions

View File

@ -136,7 +136,11 @@ class S3Helper
end
def list(prefix = "")
s3_bucket.objects(prefix: "#{@s3_bucket_folder_path}/#{prefix}")
if @s3_bucket_folder_path.present?
prefix = File.join(@s3_bucket_folder_path, prefix)
end
s3_bucket.objects(prefix: prefix)
end
def tag_file(key, tags)

View File

@ -53,4 +53,18 @@ describe "S3Helper" do
helper.update_tombstone_lifecycle(100)
end
describe '#list' do
it 'creates the prefix correctly' do
{
'some/bucket' => 'bucket/testing',
'some' => 'testing'
}.each do |bucket_name, prefix|
s3_helper = S3Helper.new(bucket_name)
bucket = stub('s3_bucket')
s3_helper.expects(:s3_bucket).returns(bucket)
bucket.expects(:objects).with(prefix: prefix)
s3_helper.list('testing')
end
end
end
end