2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
2013-10-01 03:04:02 -04:00
|
|
|
require 'jobs/regular/process_post'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe Jobs::ProcessPost do
|
|
|
|
|
|
|
|
it "returns when the post cannot be found" do
|
2013-02-25 11:42:20 -05:00
|
|
|
lambda { Jobs::ProcessPost.new.perform(post_id: 1, sync_exec: true) }.should_not raise_error
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a post' do
|
|
|
|
|
2014-12-07 02:11:38 -05:00
|
|
|
let(:post) do
|
|
|
|
Fabricate(:post)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-12-07 02:11:38 -05: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
|
|
|
|
post.cooked.should == cooked
|
|
|
|
|
|
|
|
Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-12-07 02:11:38 -05: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
|
|
|
|
post.cooked.should == cooked
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-12-07 02:11:38 -05:00
|
|
|
it 'processes posts' do
|
|
|
|
|
|
|
|
post = Fabricate(:post, raw: "<img src='#{Discourse.base_url_no_prefix}/awesome/picture.png'>")
|
|
|
|
post.cooked.should =~ /http/
|
|
|
|
|
|
|
|
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
|
|
|
|
post.cooked.should_not =~ /http/
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|