FIX: Make sure the site setting works and fix build

FIX: Make sure the site setting works and fix build

diff --git a/app/jobs/scheduled/ensure_post_uploads_existence.rb b/app/jobs/scheduled/ensure_post_uploads_existence.rb
index e1bde48..ea1103d 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 2e8a9f9..99d187a 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 <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)
+      end
     end
 
-    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
+      end
     end
+
   end
 end

GitHub sha: c9ddc6ce