FIX: Make sure the site setting works and fix build

This commit is contained in:
Robin Ward 2019-04-04 17:44:10 -04:00
parent aa4a38b08a
commit c9ddc6ce30
2 changed files with 35 additions and 14 deletions

View File

@ -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)

View File

@ -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