Permalink
Browse files

Move draft sequence incrementing out of `after_save`

  • Loading branch information...
1 parent 5aec526 commit d5e4243f027fce7d1eac1824bb5c14c204cfe788 @eviltrout eviltrout committed Mar 18, 2013
Showing with 16 additions and 4 deletions.
  1. +7 −2 app/models/post.rb
  2. +3 −0 lib/post_creator.rb
  3. +1 −0 lib/post_revisor.rb
  4. +5 −2 spec/models/draft_spec.rb
View
@@ -2,6 +2,7 @@
require_dependency 'pretty_text'
require_dependency 'rate_limiter'
require_dependency 'post_revisor'
+require_dependency 'enum'
require 'archetype'
require 'digest/sha1'
@@ -369,9 +370,13 @@ def self.calculate_avg_time
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
@@ -117,6 +117,9 @@ def create
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
@@ -13,6 +13,7 @@ def revise!(user, new_raw, opts = {})
revise_post
update_category_description
post_process_post
+ @post.advance_draft_sequence
true
end
@@ -61,9 +61,12 @@
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

0 comments on commit d5e4243

Please sign in to comment.