From c9ddc6ce301d6addb5b63da2168f24a007097e2f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 4 Apr 2019 17:44:10 -0400 Subject: [PATCH] FIX: Make sure the site setting works and fix build --- .../ensure_post_uploads_existence.rb | 2 +- .../ensure_post_uploads_existence_spec.rb | 47 ++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/jobs/scheduled/ensure_post_uploads_existence.rb b/app/jobs/scheduled/ensure_post_uploads_existence.rb index 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 Jobs MISSING_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.rb index 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 do let(: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 ") - 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 ") + 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 ") + described_class.new.execute({}) + field = PostCustomField.find_by(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS) + expect(field).to be_present + expect(field.value).to eq(nil) + end end - it 'should create post custom field with nil value' do - post = Fabricate(:post, cooked: "A sample post ") - 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 ") + upload.destroy! + described_class.new.execute({}) + field = PostCustomField.find_by(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS) + expect(field).to be_blank + end end + end end