Move a bunch of callbacks into PostCreator

This commit is contained in:
Robin Ward
2013-03-18 13:55:34 -04:00
parent 12768f1d42
commit b6224b014c
7 changed files with 114 additions and 105 deletions

View File

@ -66,43 +66,6 @@ describe Post do
end
describe 'post uniqueness' do
context "disabled" do
before do
SiteSetting.stubs(:unique_posts_mins).returns(0)
Fabricate(:post, post_args)
end
it "returns true for another post with the same content" do
Fabricate.build(:post, post_args).should be_valid
end
end
context 'enabled' do
before do
SiteSetting.stubs(:unique_posts_mins).returns(10)
Fabricate(:post, post_args)
end
it "returns false for another post with the same content" do
Fabricate.build(:post, post_args).should_not be_valid
end
it "returns true for admins" do
topic.user.admin = true
Fabricate.build(:post, post_args).should be_valid
end
it "returns true for moderators" do
topic.user.trust_level = TrustLevel.levels[:moderator]
Fabricate.build(:post, post_args).should be_valid
end
end
end
describe 'flagging helpers' do
it 'isFlagged is accurate' do
post = Fabricate(:post)
@ -476,34 +439,6 @@ describe Post do
end
end
it 'should feature users after create' do
Jobs.stubs(:enqueue).with(:process_post, anything)
Jobs.expects(:enqueue).with(:feature_topic_users, has_key(:topic_id))
Fabricate(:post, post_args)
end
it 'should queue up a post processing job when saved' do
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
Jobs.expects(:enqueue).with(:process_post, has_key(:post_id))
Fabricate(:post, post_args)
end
it 'passes the invalidate_oneboxes along to the job if present' do
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
Jobs.expects(:enqueue).with(:process_post, has_key(:invalidate_oneboxes))
post = Fabricate.build(:post, post_args)
post.invalidate_oneboxes = true
post.save
end
it 'passes the image_sizes along to the job if present' do
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
Jobs.expects(:enqueue).with(:process_post, has_key(:image_sizes))
post = Fabricate.build(:post, post_args)
post.image_sizes = {'http://an.image.host/image.jpg' => {'width' => 17, 'height' => 31}}
post.save
end
describe 'notifications' do
let(:coding_horror) { Fabricate(:coding_horror) }

View File

@ -432,15 +432,17 @@ describe Topic do
context "other user" do
let(:creator) { PostCreator.new(topic.user, raw: Fabricate.build(:post).raw, topic_id: topic.id )}
it "sends the other user an email when there's a new post" do
UserNotifications.expects(:private_message).with(coding_horror, has_key(:post))
Fabricate(:post, topic: topic, user: topic.user)
creator.create
end
it "doesn't send the user an email when they have them disabled" do
coding_horror.update_column(:email_private_messages, false)
UserNotifications.expects(:private_message).with(coding_horror, has_key(:post)).never
Fabricate(:post, topic: topic, user: topic.user)
creator.create
end
end

View File

@ -137,18 +137,20 @@ describe TopicUser do
context 'auto tracking' do
let(:post_creator) { PostCreator.new(new_user, raw: Fabricate.build(:post).raw, topic_id: topic.id) }
before do
TopicUser.update_last_read(new_user, topic.id, 2, 0)
end
it 'should automatically track topics you reply to' do
post = Fabricate(:post, topic: topic, user: new_user)
post_creator.create
topic_new_user.notification_level.should == TopicUser.notification_levels[:tracking]
topic_new_user.notifications_reason_id.should == TopicUser.notification_reasons[:created_post]
end
it 'should not automatically track topics you reply to and have set state manually' do
Fabricate(:post, topic: topic, user: new_user)
post_creator.create
TopicUser.change(new_user, topic, notification_level: TopicUser.notification_levels[:regular])
topic_new_user.notification_level.should == TopicUser.notification_levels[:regular]
topic_new_user.notifications_reason_id.should == TopicUser.notification_reasons[:user_changed]