A platform for community discussion. Free, open, simple.
FIX: Make sure the site setting works and fix build
Robin Wardc9ddc6ce301d
diff --git a/app/jobs/scheduled/ensure_post_uploads_existence.rb b/app/jobs/scheduled/ensure_post_uploads_existence.rbindex e1bde48fe91..ea1103d6f06 100644--- a/app/jobs/scheduled/ensure_post_uploads_existence.rb+++ b/app/jobs/scheduled/ensure_post_uploads_existence.rb@@ -8,7 +8,7 @@ module JobsMISSING_UPLOADS ||= "missing_uploads"def execute(args)- return unless SiteSetting.enable_missing_post_uploads_check+ return unless SiteSetting.enable_missing_post_uploads_check?PostCustomField.where(name: MISSING_UPLOADS)diff --git a/spec/jobs/ensure_post_uploads_existence_spec.rb b/spec/jobs/ensure_post_uploads_existence_spec.rbindex 2e8a9f9ede3..99d187a2ac5 100644--- a/spec/jobs/ensure_post_uploads_existence_spec.rb+++ b/spec/jobs/ensure_post_uploads_existence_spec.rb@@ -6,21 +6,42 @@ describe Jobs::EnsurePostUploadsExistence dolet(:upload) { Fabricate(:upload) }let(:optimized) { Fabricate(:optimized_image, url: '/uploads/default/optimized/1X/d1c2d40ab994e8410c_100x200.png') }- it 'should create post custom field for missing upload' do- post = Fabricate(:post, cooked: "A sample post <img src='#{upload.url}'>")- upload.destroy!- described_class.new.execute({})- field = PostCustomField.last- expect(field.name).to eq(Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS)- expect(field.value).to eq(upload.url)+ context "when enabled" do+ before do+ SiteSetting.enable_missing_post_uploads_check = true+ end++ it 'should create post custom field for missing upload' do+ Fabricate(:post, cooked: "A sample post <img src='#{upload.url}'>")+ upload.destroy!+ described_class.new.execute({})+ field = PostCustomField.find_by(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS)+ expect(field).to be_present+ expect(field.value).to eq(upload.url)+ end++ it 'should create post custom field with nil value' do+ Fabricate(:post, cooked: "A sample post <a href='#{upload.url}'> <img src='#{optimized.url}'>")+ described_class.new.execute({})+ field = PostCustomField.find_by(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS)+ expect(field).to be_present+ expect(field.value).to eq(nil)+ endend- it 'should create post custom field with nil value' do- post = Fabricate(:post, cooked: "A sample post <a href='#{upload.url}'> <img src='#{optimized.url}'>")- described_class.new.execute({})- field = PostCustomField.last- expect(field.name).to eq(Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS)- expect(field.value).to eq(nil)+ context "when disabled" do+ before do+ SiteSetting.enable_missing_post_uploads_check = false+ end++ it "does not execute" do+ Fabricate(:post, cooked: "A sample post <img src='#{upload.url}'>")+ upload.destroy!+ described_class.new.execute({})+ field = PostCustomField.find_by(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS)+ expect(field).to be_blank+ endend+endend