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
|
acts_as_paranoid
|
||||||
|
|
||||||
after_recover :update_flagged_posts_count
|
after_recover :update_flagged_posts_count
|
||||||
after_destroy :update_flagged_posts_count
|
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :topic, counter_cache: :posts_count
|
belongs_to :topic, counter_cache: :posts_count
|
||||||
|
@ -38,10 +37,6 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
SHORT_POST_CHARS = 1200
|
SHORT_POST_CHARS = 1200
|
||||||
|
|
||||||
# Post Types
|
|
||||||
REGULAR = 1
|
|
||||||
MODERATOR_ACTION = 2
|
|
||||||
|
|
||||||
scope :by_newest, order('created_at desc, id desc')
|
scope :by_newest, order('created_at desc, id desc')
|
||||||
scope :with_user, includes(:user)
|
scope :with_user, includes(:user)
|
||||||
|
|
||||||
|
@ -49,6 +44,10 @@ class Post < ActiveRecord::Base
|
||||||
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)
|
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.types
|
||||||
|
@types ||= Enum.new(:regular, :moderator_action)
|
||||||
|
end
|
||||||
|
|
||||||
def raw_quality
|
def raw_quality
|
||||||
sentinel = TextSentinel.new(raw, min_entropy: SiteSetting.body_min_entropy)
|
sentinel = TextSentinel.new(raw, min_entropy: SiteSetting.body_min_entropy)
|
||||||
if sentinel.valid?
|
if sentinel.valid?
|
||||||
|
@ -151,12 +150,14 @@ class Post < ActiveRecord::Base
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
self.destroy
|
self.destroy
|
||||||
Topic.reset_highest(topic_id)
|
Topic.reset_highest(topic_id)
|
||||||
|
update_flagged_posts_count
|
||||||
end
|
end
|
||||||
elsif deleted_by.id == user_id
|
elsif deleted_by.id == user_id
|
||||||
# As the poster, make a revision that says deleted.
|
# As the poster, make a revision that says deleted.
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
revise(deleted_by, I18n.t('js.post.deleted_by_author'), force_new_version: true)
|
revise(deleted_by, I18n.t('js.post.deleted_by_author'), force_new_version: true)
|
||||||
update_column(:user_deleted, true)
|
update_column(:user_deleted, true)
|
||||||
|
update_flagged_posts_count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -320,7 +320,7 @@ class Topic < ActiveRecord::Base
|
||||||
def add_moderator_post(user, text, opts={})
|
def add_moderator_post(user, text, opts={})
|
||||||
new_post = nil
|
new_post = nil
|
||||||
Topic.transaction do
|
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)
|
increment!(:moderator_posts_count)
|
||||||
new_post
|
new_post
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ class SiteSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_types
|
def post_types
|
||||||
{regular: Post::REGULAR, moderator_action: Post::MODERATOR_ACTION}
|
Post.types
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ end
|
||||||
Fabricator(:moderator_post, from: :post) do
|
Fabricator(:moderator_post, from: :post) do
|
||||||
user
|
user
|
||||||
topic {|attrs| Fabricate(:topic, user: attrs[:user] ) }
|
topic {|attrs| Fabricate(:topic, user: attrs[:user] ) }
|
||||||
post_type Post::MODERATOR_ACTION
|
post_type Post.types[:moderator_action]
|
||||||
raw "Hello world"
|
raw "Hello world"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -579,7 +579,7 @@ describe Post do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is of the regular post type' do
|
it 'is of the regular post type' do
|
||||||
post.post_type.should == Post::REGULAR
|
post.post_type.should == Post.types[:regular]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has no versions' do
|
it 'has no versions' do
|
||||||
|
|
|
@ -514,7 +514,7 @@ describe Topic do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has the moderator action type' do
|
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
|
end
|
||||||
|
|
||||||
it 'increases the moderator_posts count' do
|
it 'increases the moderator_posts count' do
|
||||||
|
|
Loading…
Reference in New Issue