From b368667703f9785974c85fb3197ebb885eb5a626 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 1 Aug 2014 17:28:00 -0400 Subject: [PATCH] FIX: don't validate topic title if it isn't changing. topic stats were failing to update, causing necro topic warnings and other problems. --- app/models/topic.rb | 3 ++- spec/models/topic_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 327f12b5972..260cf3f9910 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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?) }, diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 4fd096b0381..2d67a3c6b88 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -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