diff --git a/app/models/topic.rb b/app/models/topic.rb index 619afa123f0..e3f5b745c5e 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -59,7 +59,8 @@ class Topic < ActiveRecord::Base validates :category_id, :presence => true ,:exclusion => {:in => [SiteSetting.uncategorized_category_id]}, :if => Proc.new { |t| (t.new_record? || t.category_id_changed?) && - !SiteSetting.allow_uncategorized_topics + !SiteSetting.allow_uncategorized_topics && + (t.archetype.nil? || t.archetype == Archetype.default) } @@ -106,7 +107,7 @@ class Topic < ActiveRecord::Base # Return private message topics scope :private_messages, lambda { - where(archetype: Archetype::private_message) + where(archetype: Archetype.private_message) } scope :listable_topics, lambda { where('topics.archetype <> ?', [Archetype.private_message]) } @@ -169,7 +170,7 @@ class Topic < ActiveRecord::Base Jobs.cancel_scheduled_job(:close_topic, {topic_id: id}) true end - if category_id.nil? && (archetype.nil? || archetype == "regular") + if category_id.nil? && (archetype.nil? || archetype == Archetype.default) self.category_id = SiteSetting.uncategorized_category_id end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 92fb51d5be7..acdbfdb0529 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -185,6 +185,11 @@ describe Topic do topic.errors[:category_id].should be_present end + it "allows PMs" do + topic = Fabricate.build(:topic, category: nil, archetype: Archetype.private_message) + topic.should be_valid + end + it 'passes for topics with a category' do Fabricate.build(:topic, category: Fabricate(:category)).should be_valid end