diff --git a/lib/file_store/s3_store.rb b/lib/file_store/s3_store.rb index cbfee317f..0615dbc52 100644 --- a/lib/file_store/s3_store.rb +++ b/lib/file_store/s3_store.rb @@ -6,12 +6,11 @@ require_dependency "file_helper" module FileStore class S3Store < BaseStore - attr_reader :s3_bucket - TOMBSTONE_PREFIX ||= "tombstone/" - def initialize(s3_helper=nil) - @s3_helper = s3_helper || S3Helper.new(s3_bucket, TOMBSTONE_PREFIX) + def initialize(s3_helper=nil, s3_bucket=get_s3_bucket) + @s3_bucket = s3_bucket + @s3_helper = s3_helper || S3Helper.new(@s3_bucket, TOMBSTONE_PREFIX) end def store_upload(file, upload, content_type = nil) @@ -63,7 +62,7 @@ module FileStore end def absolute_base_url - bucket = s3_bucket.split("/".freeze, 2).first + bucket = @s3_bucket.split("/".freeze, 2).first # cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region @absolute_base_url ||= if SiteSetting.s3_region == "us-east-1" @@ -104,13 +103,9 @@ module FileStore UserAvatar.external_avatar_url(user_id, avatar.upload_id, avatar.width) end - def s3_bucket - @s3_bucket ||= begin - raise Discourse::SiteSettingMissing.new("s3_upload_bucket") if SiteSetting.s3_upload_bucket.blank? - SiteSetting.s3_upload_bucket.downcase - end + def get_s3_bucket + raise Discourse::SiteSettingMissing.new("s3_upload_bucket") if SiteSetting.s3_upload_bucket.blank? + SiteSetting.s3_upload_bucket.downcase end - end - end diff --git a/spec/components/file_store/s3_store_spec.rb b/spec/components/file_store/s3_store_spec.rb index 49ad6af2c..97bad8faf 100644 --- a/spec/components/file_store/s3_store_spec.rb +++ b/spec/components/file_store/s3_store_spec.rb @@ -256,10 +256,4 @@ describe FileStore::S3Store do assert_path("https://hello", nil) end end - - describe "#s3_bucket" do - it "should return the right bucket name" do - expect(store.s3_bucket).to eq('s3-upload-bucket') - end - end end