demock spec
This commit is contained in:
parent
87e9510bb0
commit
a4ce039c85
|
@ -9,26 +9,41 @@ describe Jobs::ProcessPost do
|
||||||
|
|
||||||
context 'with a post' do
|
context 'with a post' do
|
||||||
|
|
||||||
before do
|
let(:post) do
|
||||||
@post = Fabricate(:post)
|
Fabricate(:post)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls process on a CookedPostProcessor' do
|
it 'does not erase posts when CookedPostProcessor malfunctions' do
|
||||||
CookedPostProcessor.any_instance.expects(:post_process).once
|
# Look kids, an actual reason why you want to use mocks
|
||||||
Jobs::ProcessPost.new.execute(post_id: @post.id)
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates the html if the dirty flag is true' do
|
it 'recooks if needed' do
|
||||||
CookedPostProcessor.any_instance.expects(:dirty?).returns(true)
|
cooked = post.cooked
|
||||||
CookedPostProcessor.any_instance.expects(:html).returns('test')
|
|
||||||
Post.any_instance.expects(:update_column).with(:cooked, 'test').once
|
post.update_columns(cooked: "frogs")
|
||||||
Jobs::ProcessPost.new.execute(post_id: @post.id)
|
Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
|
||||||
|
|
||||||
|
post.reload
|
||||||
|
post.cooked.should == cooked
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't update the cooked content if dirty is false" do
|
it 'processes posts' do
|
||||||
CookedPostProcessor.any_instance.expects(:dirty?).returns(false)
|
|
||||||
Post.any_instance.expects(:update_column).never
|
post = Fabricate(:post, raw: "<img src='#{Discourse.base_url_no_prefix}/awesome/picture.png'>")
|
||||||
Jobs::ProcessPost.new.execute(post_id: @post.id)
|
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/
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue