mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
Move draft sequence incrementing out of after_save
This commit is contained in:
parent
5aec5261a7
commit
d5e4243f02
4 changed files with 16 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,6 +13,7 @@ class PostRevisor
|
|||
revise_post
|
||||
update_category_description
|
||||
post_process_post
|
||||
@post.advance_draft_sequence
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue