FIX: Make sure the site setting works and fix build
This commit is contained in:
parent
aa4a38b08a
commit
c9ddc6ce30
|
@ -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)
|
||||
|
|
|
@ -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') }
|
||||
|
||||
context "when enabled" do
|
||||
before do
|
||||
SiteSetting.enable_missing_post_uploads_check = true
|
||||
end
|
||||
|
||||
it 'should create post custom field for missing upload' do
|
||||
post = Fabricate(:post, cooked: "A sample post <img src='#{upload.url}'>")
|
||||
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)
|
||||
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
|
||||
post = Fabricate(:post, cooked: "A sample post <a href='#{upload.url}'> <img src='#{optimized.url}'>")
|
||||
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)
|
||||
field = PostCustomField.find_by(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS)
|
||||
expect(field).to be_present
|
||||
expect(field.value).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue