push some work out of AR callbacks into PostCreator, add a couple of helpers for post and topic creation in test

fix it so the auto_track false marks topics as new
This commit is contained in:
Sam
2013-07-22 15:07:20 +10:00
parent 0ec1438b9a
commit 58e7c3e1f3
15 changed files with 89 additions and 95 deletions
+14 -13
View File
@@ -66,6 +66,7 @@ class PostCreator
store_unique_post_key
send_notifications_for_private_message
track_topic
update_topic_stats
update_user_counts
publish
@post.advance_draft_sequence
@@ -100,19 +101,6 @@ class PostCreator
post.last_version_at ||= Time.now
end
def self.after_create_tasks(post)
# Update attributes on the topic - featured users and last posted.
attrs = {last_posted_at: post.created_at, last_post_user_id: post.user_id}
attrs[:bumped_at] = post.created_at unless post.no_bump
post.topic.update_attributes(attrs)
# Update topic user data
TopicUser.change(post.user.id,
post.topic.id,
posted: true,
last_read_post_number: post.post_number,
seen_post_count: post.post_number)
end
protected
@@ -184,6 +172,13 @@ class PostCreator
@topic = topic
end
def update_topic_stats
# Update attributes on the topic - featured users and last posted.
attrs = {last_posted_at: @post.created_at, last_post_user_id: @post.user_id}
attrs[:bumped_at] = @post.created_at unless @post.no_bump
@topic.update_attributes(attrs)
end
def setup_post
post = @topic.posts.new(raw: @opts[:raw],
user: @user,
@@ -267,6 +262,12 @@ class PostCreator
def track_topic
unless @opts[:auto_track] == false
TopicUser.auto_track(@user.id, @topic.id, TopicUser.notification_reasons[:created_post])
# Update topic user data
TopicUser.change(@post.user.id,
@post.topic.id,
posted: true,
last_read_post_number: @post.post_number,
seen_post_count: @post.post_number)
end
end