FIX: when allow_uncategorized_topics was false, PMs can not be created
This commit is contained in:
parent
d149066ac6
commit
4929c5db71
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue