diff --git a/app/models/post.rb b/app/models/post.rb index 012d092fcf0..62375c750c4 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -16,7 +16,6 @@ class Post < ActiveRecord::Base acts_as_paranoid after_recover :update_flagged_posts_count - after_destroy :update_flagged_posts_count belongs_to :user belongs_to :topic, counter_cache: :posts_count @@ -38,10 +37,6 @@ class Post < ActiveRecord::Base SHORT_POST_CHARS = 1200 - # Post Types - REGULAR = 1 - MODERATOR_ACTION = 2 - scope :by_newest, order('created_at desc, id desc') scope :with_user, includes(:user) @@ -49,6 +44,10 @@ class Post < ActiveRecord::Base @hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again) end + def self.types + @types ||= Enum.new(:regular, :moderator_action) + end + def raw_quality sentinel = TextSentinel.new(raw, min_entropy: SiteSetting.body_min_entropy) if sentinel.valid? @@ -151,12 +150,14 @@ class Post < ActiveRecord::Base Post.transaction do self.destroy Topic.reset_highest(topic_id) + update_flagged_posts_count end elsif deleted_by.id == user_id # As the poster, make a revision that says deleted. Post.transaction do revise(deleted_by, I18n.t('js.post.deleted_by_author'), force_new_version: true) update_column(:user_deleted, true) + update_flagged_posts_count end end end diff --git a/app/models/topic.rb b/app/models/topic.rb index 50d0d3a4e01..411ee59d1de 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -320,7 +320,7 @@ class Topic < ActiveRecord::Base def add_moderator_post(user, text, opts={}) new_post = nil Topic.transaction do - new_post = posts.create(user: user, raw: text, post_type: Post::MODERATOR_ACTION, no_bump: opts[:bump].blank?) + new_post = posts.create(user: user, raw: text, post_type: Post.types[:moderator_action], no_bump: opts[:bump].blank?) increment!(:moderator_posts_count) new_post end diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index bbe962f7a4b..119025eb619 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -15,7 +15,7 @@ class SiteSerializer < ApplicationSerializer end def post_types - {regular: Post::REGULAR, moderator_action: Post::MODERATOR_ACTION} + Post.types end end diff --git a/spec/fabricators/post_fabricator.rb b/spec/fabricators/post_fabricator.rb index 7636465bf97..73f84fb1be2 100644 --- a/spec/fabricators/post_fabricator.rb +++ b/spec/fabricators/post_fabricator.rb @@ -16,7 +16,7 @@ end Fabricator(:moderator_post, from: :post) do user topic {|attrs| Fabricate(:topic, user: attrs[:user] ) } - post_type Post::MODERATOR_ACTION + post_type Post.types[:moderator_action] raw "Hello world" end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 43a9b2dc5db..aefe5720759 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -579,7 +579,7 @@ describe Post do end it 'is of the regular post type' do - post.post_type.should == Post::REGULAR + post.post_type.should == Post.types[:regular] end it 'has no versions' do diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 9a7b9676660..efd96b46460 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -514,7 +514,7 @@ describe Topic do end it 'has the moderator action type' do - @mod_post.post_type.should == Post::MODERATOR_ACTION + @mod_post.post_type.should == Post.types[:moderator_action] end it 'increases the moderator_posts count' do