Move draft sequence incrementing out of `after_save`

This commit is contained in:
Robin Ward 2013-03-18 15:12:31 -04:00
parent 5aec5261a7
commit d5e4243f02
4 changed files with 16 additions and 4 deletions

View File

@ -2,6 +2,7 @@ require_dependency 'jobs'
require_dependency 'pretty_text'
require_dependency 'rate_limiter'
require_dependency 'post_revisor'
require_dependency 'enum'
require 'archetype'
require 'digest/sha1'
@ -369,9 +370,13 @@ class Post < ActiveRecord::Base
Notification.delete_all topic_id: topic_id, post_number: post_number
end
after_save do
DraftSequence.next! last_editor_id, topic.draft_key if topic # could be deleted
def advance_draft_sequence
return if topic.blank? # could be deleted
DraftSequence.next!(last_editor_id, topic.draft_key)
end
after_save do
quoted_post_numbers << reply_to_post_number if reply_to_post_number.present?
# Create a reply relationship between quoted posts and this new post

View File

@ -117,6 +117,9 @@ class PostCreator
created_at: post.created_at,
user: BasicUserSerializer.new(post.user).as_json(root: false),
post_number: post.post_number)
# Advance the draft sequence
post.advance_draft_sequence
end
post

View File

@ -13,6 +13,7 @@ class PostRevisor
revise_post
update_category_description
post_process_post
@post.advance_draft_sequence
true
end

View File

@ -61,9 +61,12 @@ describe Draft do
end
it 'nukes the post draft when a post is created' do
p = Fabricate(:post)
user = Fabricate(:user)
topic = Fabricate(:topic)
p = PostCreator.new(user, raw: Fabricate.build(:post).raw, topic_id: topic.id).create
Draft.set(p.user, p.topic.draft_key, 0,'hello')
Fabricate(:post, topic: p.topic, user: p.user)
PostCreator.new(user, raw: Fabricate.build(:post).raw).create
Draft.get(p.user, p.topic.draft_key, DraftSequence.current(p.user, p.topic.draft_key)).should be_nil
end