mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -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 'pretty_text'
|
||||||
require_dependency 'rate_limiter'
|
require_dependency 'rate_limiter'
|
||||||
require_dependency 'post_revisor'
|
require_dependency 'post_revisor'
|
||||||
|
require_dependency 'enum'
|
||||||
|
|
||||||
require 'archetype'
|
require 'archetype'
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
|
@ -369,9 +370,13 @@ class Post < ActiveRecord::Base
|
||||||
Notification.delete_all topic_id: topic_id, post_number: post_number
|
Notification.delete_all topic_id: topic_id, post_number: post_number
|
||||||
end
|
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?
|
quoted_post_numbers << reply_to_post_number if reply_to_post_number.present?
|
||||||
|
|
||||||
# Create a reply relationship between quoted posts and this new post
|
# Create a reply relationship between quoted posts and this new post
|
||||||
|
|
|
@ -117,6 +117,9 @@ class PostCreator
|
||||||
created_at: post.created_at,
|
created_at: post.created_at,
|
||||||
user: BasicUserSerializer.new(post.user).as_json(root: false),
|
user: BasicUserSerializer.new(post.user).as_json(root: false),
|
||||||
post_number: post.post_number)
|
post_number: post.post_number)
|
||||||
|
|
||||||
|
# Advance the draft sequence
|
||||||
|
post.advance_draft_sequence
|
||||||
end
|
end
|
||||||
|
|
||||||
post
|
post
|
||||||
|
|
|
@ -13,6 +13,7 @@ class PostRevisor
|
||||||
revise_post
|
revise_post
|
||||||
update_category_description
|
update_category_description
|
||||||
post_process_post
|
post_process_post
|
||||||
|
@post.advance_draft_sequence
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,12 @@ describe Draft do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'nukes the post draft when a post is created' do
|
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')
|
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
|
Draft.get(p.user, p.topic.draft_key, DraftSequence.current(p.user, p.topic.draft_key)).should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue