Convert Post type constants to Enum
This commit is contained in:
parent
897d48b145
commit
c1e40f5d19
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@ class SiteSerializer < ApplicationSerializer
|
|||
end
|
||||
|
||||
def post_types
|
||||
{regular: Post::REGULAR, moderator_action: Post::MODERATOR_ACTION}
|
||||
Post.types
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue