discourse/spec/jobs/process_post_spec.rb

60 lines
1.6 KiB
Ruby
Raw Normal View History

require 'rails_helper'
require 'jobs/regular/process_post'
2013-02-06 03:16:51 +08:00
describe Jobs::ProcessPost do
it "returns when the post cannot be found" do
expect { Jobs::ProcessPost.new.perform(post_id: 1, sync_exec: true) }.not_to raise_error
2013-02-06 03:16:51 +08:00
end
context 'with a post' do
2014-12-07 15:11:38 +08:00
let(:post) do
Fabricate(:post)
2013-02-06 03:16:51 +08:00
end
2014-12-07 15:11:38 +08:00
it 'does not erase posts when CookedPostProcessor malfunctions' do
# Look kids, an actual reason why you want to use mocks
CookedPostProcessor.any_instance.expects(:html).returns(' ')
cooked = post.cooked
post.reload
expect(post.cooked).to eq(cooked)
2014-12-07 15:11:38 +08:00
Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
2013-02-06 03:16:51 +08:00
end
2014-12-07 15:11:38 +08:00
it 'recooks if needed' do
cooked = post.cooked
post.update_columns(cooked: "frogs")
Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
post.reload
expect(post.cooked).to eq(cooked)
2013-02-06 03:16:51 +08:00
end
2014-12-07 15:11:38 +08:00
it 'processes posts' do
post = Fabricate(:post, raw: "<img src='#{Discourse.base_url_no_prefix}/awesome/picture.png'>")
expect(post.cooked).to match(/http/)
2014-12-07 15:11:38 +08:00
Jobs::ProcessPost.new.execute(post_id: post.id)
post.reload
# subtle but cooked post processor strip this stuff, this ensures all the code gets a workout
expect(post.cooked).not_to match(/http/)
2013-02-26 00:42:20 +08:00
end
2013-02-06 03:16:51 +08:00
it "always re-extracts links on post process" do
post.update_columns(raw: "sam has a blog at https://samsaffron.com")
TopicLink.destroy_all
Jobs::ProcessPost.new.execute(post_id: post.id)
expect(TopicLink.count).to eq(1)
end
2013-02-06 03:16:51 +08:00
end
end