FIX: setting min_topic_title_length is ignored
This commit is contained in:
parent
33e3ad1603
commit
d120a5d139
|
@ -26,7 +26,7 @@ class Post < ActiveRecord::Base
|
||||||
has_many :post_actions
|
has_many :post_actions
|
||||||
|
|
||||||
validates_presence_of :raw, :user_id, :topic_id
|
validates_presence_of :raw, :user_id, :topic_id
|
||||||
validates :raw, stripped_length: { in: SiteSetting.post_length }
|
validates :raw, stripped_length: { in: -> { SiteSetting.post_length } }
|
||||||
validate :raw_quality
|
validate :raw_quality
|
||||||
validate :max_mention_validator
|
validate :max_mention_validator
|
||||||
validate :max_images_validator
|
validate :max_images_validator
|
||||||
|
@ -40,8 +40,8 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
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)
|
||||||
scope :public_posts, lambda { joins(:topic).where('topics.archetype <> ?', [Archetype.private_message]) }
|
scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) }
|
||||||
scope :private_posts, lambda { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
|
scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
|
||||||
|
|
||||||
def self.hidden_reasons
|
def self.hidden_reasons
|
||||||
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)
|
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)
|
||||||
|
|
|
@ -2,7 +2,8 @@ class StrippedLengthValidator < ActiveModel::EachValidator
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
unless value.nil?
|
unless value.nil?
|
||||||
stripped_length = value.strip.length
|
stripped_length = value.strip.length
|
||||||
range = options[:in]
|
# the `in` parameter might be a lambda when the range is dynamic
|
||||||
|
range = options[:in].lambda? ? options[:in].call : options[:in]
|
||||||
record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_short', count: range.begin)) unless
|
record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_short', count: range.begin)) unless
|
||||||
stripped_length >= range.begin
|
stripped_length >= range.begin
|
||||||
record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_long', count: range.end)) unless
|
record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_long', count: range.end)) unless
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
validate :title_quality
|
validate :title_quality
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
validates :title, length: { in: SiteSetting.topic_title_length }
|
validate :title, -> { SiteSetting.topic_title_length.include? :length }
|
||||||
|
|
||||||
serialize :meta_data, ActiveRecord::Coders::Hstore
|
serialize :meta_data, ActiveRecord::Coders::Hstore
|
||||||
|
|
||||||
|
|
|
@ -146,19 +146,14 @@ describe SiteSetting do
|
||||||
|
|
||||||
describe 'topic_title_length' do
|
describe 'topic_title_length' do
|
||||||
it 'returns a range of min/max topic title length' do
|
it 'returns a range of min/max topic title length' do
|
||||||
SiteSetting.min_topic_title_length = 1
|
SiteSetting.topic_title_length.should ==
|
||||||
SiteSetting.max_topic_title_length = 2
|
(SiteSetting.defaults[:min_topic_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
||||||
|
|
||||||
SiteSetting.topic_title_length.should == (1..2)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'post_length' do
|
describe 'post_length' do
|
||||||
it 'returns a range of min/max post length' do
|
it 'returns a range of min/max post length' do
|
||||||
SiteSetting.min_post_length = 1
|
SiteSetting.post_length.should == (SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length])
|
||||||
SiteSetting.max_post_length = 2
|
|
||||||
|
|
||||||
SiteSetting.post_length.should == (1..2)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue