parent
1d76b7b7b5
commit
45aebd00a5
|
@ -4,6 +4,8 @@ require "s3_helper"
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "S3Helper" do
|
describe "S3Helper" do
|
||||||
|
let(:client) { Aws::S3::Client.new(stub_responses: true) }
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
SiteSetting.enable_s3_uploads = true
|
SiteSetting.enable_s3_uploads = true
|
||||||
SiteSetting.s3_access_key_id = "abc"
|
SiteSetting.s3_access_key_id = "abc"
|
||||||
|
@ -70,23 +72,19 @@ describe "S3Helper" do
|
||||||
'some/bucket' => 'bucket/testing',
|
'some/bucket' => 'bucket/testing',
|
||||||
'some' => 'testing'
|
'some' => 'testing'
|
||||||
}.each do |bucket_name, prefix|
|
}.each do |bucket_name, prefix|
|
||||||
s3_helper = S3Helper.new(bucket_name)
|
s3_helper = S3Helper.new(bucket_name, "", client: client)
|
||||||
bucket = stub('s3_bucket')
|
Aws::S3::Bucket.any_instance.expects(:objects).with(prefix: prefix)
|
||||||
s3_helper.expects(:s3_bucket).returns(bucket)
|
|
||||||
bucket.expects(:objects).with(prefix: prefix)
|
|
||||||
s3_helper.list('testing')
|
s3_helper.list('testing')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should prefix bucket folder path only if not exists" do
|
it "should prefix bucket folder path only if not exists" do
|
||||||
s3_helper = S3Helper.new('bucket/folder_path')
|
s3_helper = S3Helper.new('bucket/folder_path', "", client: client)
|
||||||
bucket = stub('s3_bucket')
|
|
||||||
|
|
||||||
s3_helper.expects(:s3_bucket).returns(bucket).twice
|
object1 = s3_helper.object("original/1X/def.xyz")
|
||||||
bucket.expects(:object).with("folder_path/original/1X/def.xyz").twice
|
object2 = s3_helper.object("folder_path/original/1X/def.xyz")
|
||||||
|
|
||||||
s3_helper.object("original/1X/def.xyz")
|
expect(object1.key).to eq(object2.key)
|
||||||
s3_helper.object("folder_path/original/1X/def.xyz")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue