FIX: setting min_topic_title_length is ignored

This commit is contained in:
Régis Hanol 2013-04-10 14:54:10 +02:00
parent 33e3ad1603
commit d120a5d139
4 changed files with 9 additions and 13 deletions

View File

@ -26,7 +26,7 @@ class Post < ActiveRecord::Base
has_many :post_actions
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 :max_mention_validator
validate :max_images_validator
@ -40,8 +40,8 @@ class Post < ActiveRecord::Base
scope :by_newest, order('created_at desc, id desc')
scope :with_user, includes(:user)
scope :public_posts, lambda { joins(:topic).where('topics.archetype <> ?', [Archetype.private_message]) }
scope :private_posts, lambda { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) }
scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
def self.hidden_reasons
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)

View File

@ -2,7 +2,8 @@ class StrippedLengthValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.nil?
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
stripped_length >= range.begin
record.errors.add attribute, (options[:message] || I18n.t('errors.messages.too_long', count: range.end)) unless

View File

@ -27,7 +27,7 @@ class Topic < ActiveRecord::Base
validate :title_quality
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

View File

@ -146,19 +146,14 @@ describe SiteSetting do
describe 'topic_title_length' do
it 'returns a range of min/max topic title length' do
SiteSetting.min_topic_title_length = 1
SiteSetting.max_topic_title_length = 2
SiteSetting.topic_title_length.should == (1..2)
SiteSetting.topic_title_length.should ==
(SiteSetting.defaults[:min_topic_title_length]..SiteSetting.defaults[:max_topic_title_length])
end
end
describe 'post_length' do
it 'returns a range of min/max post length' do
SiteSetting.min_post_length = 1
SiteSetting.max_post_length = 2
SiteSetting.post_length.should == (1..2)
SiteSetting.post_length.should == (SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length])
end
end
end