FIX: don't validate topic title if it isn't changing. topic stats were failing to update, causing necro topic warnings and other problems.

This commit is contained in:
Neil Lalonde 2014-08-01 17:28:00 -04:00
parent 436ea982ae
commit b368667703
2 changed files with 12 additions and 1 deletions

View File

@ -48,7 +48,8 @@ class Topic < ActiveRecord::Base
rate_limit :limit_topics_per_day
rate_limit :limit_private_messages_per_day
validates :title, :presence => true,
validates :title, :if => Proc.new { |t| t.title_changed? },
:presence => true,
:topic_title_length => true,
:quality_title => { :unless => :private_message? },
:unique_among => { :unless => Proc.new { |t| (SiteSetting.allow_duplicate_topic_titles? || t.private_message?) },

View File

@ -1411,4 +1411,14 @@ describe Topic do
topic = Topic.find(topic.id)
topic.custom_fields.should == {"bob" => "marley", "jack" => "black"}
end
it "doesn't validate the title again if it isn't changing" do
SiteSetting.stubs(:min_topic_title_length).returns(5)
topic = Fabricate(:topic, title: "Short")
topic.should be_valid
SiteSetting.stubs(:min_topic_title_length).returns(15)
topic.last_posted_at = 1.minute.ago
topic.save.should == true
end
end