From 0f73026c21b3d28c5cfeff51e6f96a6c435fd6f1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 25 Jan 2019 15:24:44 -0500 Subject: [PATCH] FIX: Heisentest These tests were failing for the same reason as: https://github.com/discourse/discourse/commit/bee68bba2e2a354fd79178c6a08bc90cf419f5cd Fix was the same. --- spec/multisite/s3_store_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/multisite/s3_store_spec.rb b/spec/multisite/s3_store_spec.rb index e95de89c069..f5ac4e5bb16 100644 --- a/spec/multisite/s3_store_spec.rb +++ b/spec/multisite/s3_store_spec.rb @@ -5,6 +5,10 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do let(:uploaded_file) { file_from_fixtures("smallest.png") } let(:upload_sha1) { Digest::SHA1.hexdigest(File.read(uploaded_file)) } + def build_upload + Fabricate.build(:upload, sha1: upload_sha1, id: 1) + end + context 'uploading to s3' do before(:each) do SiteSetting.s3_upload_bucket = "some-really-cool-bucket" @@ -20,7 +24,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do it "returns the correct url for default and second multisite db" do test_multisite_connection('default') do - upload = Fabricate(:upload, sha1: upload_sha1) + upload = build_upload expect(store.store_upload(uploaded_file, upload)).to eq( "//#{SiteSetting.s3_upload_bucket}.s3.dualstack.us-east-1.amazonaws.com/uploads/default/original/1X/c530c06cf89c410c0355d7852644a73fc3ec8c04.png" ) @@ -28,7 +32,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do end test_multisite_connection('second') do - upload = Fabricate(:upload, sha1: upload_sha1) + upload = build_upload expect(store.store_upload(uploaded_file, upload)).to eq( "//#{SiteSetting.s3_upload_bucket}.s3.dualstack.us-east-1.amazonaws.com/uploads/second/original/1X/c530c06cf89c410c0355d7852644a73fc3ec8c04.png" ) @@ -56,7 +60,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do it "removes the file from s3 on multisite" do test_multisite_connection('default') do - upload = Fabricate(:upload, sha1: upload_sha1) + upload = build_upload store.expects(:get_depth_for).with(upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/uploads/default/original/1X/#{upload.sha1}.png") @@ -73,7 +77,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do it "removes the file from s3 on another multisite db" do test_multisite_connection('second') do - upload = Fabricate(:upload, sha1: upload_sha1) + upload = build_upload store.expects(:get_depth_for).with(upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/uploads/second/original/1X/#{upload.sha1}.png") @@ -95,7 +99,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do it "removes the file from s3 on multisite" do test_multisite_connection('default') do - upload = Fabricate(:upload, sha1: upload_sha1) + upload = build_upload store.expects(:get_depth_for).with(upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once upload.update_attributes!(url: "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/uploads/default/original/1X/#{upload.sha1}.png")