mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
change it so all topics MUST include a category, we store a special uncategorized category to compensate
this cleans up a bunch of internals and removes some settings
This commit is contained in:
@@ -6,35 +6,6 @@ describe CategoryList do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:category_list) { CategoryList.new(Guardian.new user) }
|
||||
|
||||
context "with no categories" do
|
||||
|
||||
it "has no categories" do
|
||||
category_list.categories.should be_blank
|
||||
end
|
||||
|
||||
context "with an uncategorized topic" do
|
||||
let!(:topic) { Fabricate(:topic)}
|
||||
let(:category) { category_list.categories.first }
|
||||
|
||||
it "has the right category" do
|
||||
category.should be_present
|
||||
category.name.should == SiteSetting.uncategorized_name
|
||||
category.slug.should == SiteSetting.uncategorized_name
|
||||
category.topics_week.should == 1
|
||||
category.featured_topics.should == [topic]
|
||||
category.displayable_topics.should == [topic] # CategoryDetailedSerializer needs this attribute
|
||||
end
|
||||
|
||||
it 'does not return an invisible topic' do
|
||||
invisible_topic = Fabricate(:topic)
|
||||
invisible_topic.update_status('visible', false, Fabricate(:admin))
|
||||
expect(category.featured_topics).to_not include(invisible_topic)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "security" do
|
||||
it "properly hide secure categories" do
|
||||
admin = Fabricate(:admin)
|
||||
@@ -45,7 +16,9 @@ describe CategoryList do
|
||||
cat.set_permissions(:admins => :full)
|
||||
cat.save
|
||||
|
||||
CategoryList.new(Guardian.new admin).categories.count.should == 1
|
||||
# uncategorized + this
|
||||
CategoryList.new(Guardian.new admin).categories.count.should == 2
|
||||
|
||||
CategoryList.new(Guardian.new user).categories.count.should == 0
|
||||
CategoryList.new(Guardian.new nil).categories.count.should == 0
|
||||
end
|
||||
@@ -75,13 +48,12 @@ describe CategoryList do
|
||||
it 'returns the empty category and a non-empty category for those who can create them' do
|
||||
category_with_topics = Fabricate(:topic, category: Fabricate(:category))
|
||||
Guardian.any_instance.expects(:can_create?).with(Category).returns(true)
|
||||
category_list.categories.should have(2).categories
|
||||
category_list.categories.should have(3).categories
|
||||
category_list.categories.should include(topic_category)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
context "with a topic in a category" do
|
||||
let!(:topic) { Fabricate(:topic, category: topic_category)}
|
||||
let(:category) { category_list.categories.first }
|
||||
|
||||
@@ -687,9 +687,6 @@ describe Guardian do
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
context 'can_delete?' do
|
||||
|
||||
it 'returns false with a nil object' do
|
||||
@@ -697,6 +694,10 @@ describe Guardian do
|
||||
end
|
||||
|
||||
context 'a Topic' do
|
||||
before do
|
||||
# pretend we have a real topic
|
||||
topic.id = 9999999
|
||||
end
|
||||
|
||||
it 'returns false when not logged in' do
|
||||
Guardian.new.can_delete?(topic).should be_false
|
||||
|
||||
@@ -49,7 +49,7 @@ describe TopicQuery do
|
||||
|
||||
context 'list_latest' do
|
||||
it "returns the topics in the correct order" do
|
||||
topics.should == [pinned_topic, closed_topic, archived_topic, regular_topic]
|
||||
topics.map(&:title).should == [pinned_topic, closed_topic, archived_topic, regular_topic].map(&:title)
|
||||
end
|
||||
|
||||
it "includes the invisible topic if you're a moderator" do
|
||||
@@ -80,10 +80,6 @@ describe TopicQuery do
|
||||
let!(:topic_no_cat) { Fabricate(:topic) }
|
||||
let!(:topic_in_cat) { Fabricate(:topic, category: category) }
|
||||
|
||||
it "returns the topic without a category when filtering uncategorized" do
|
||||
topic_query.list_uncategorized.topics.should == [topic_no_cat]
|
||||
end
|
||||
|
||||
it "returns the topic with a category when filtering by category" do
|
||||
topic_query.list_category(category).topics.should == [topic_category, topic_in_cat]
|
||||
end
|
||||
|
||||
@@ -7,12 +7,8 @@ describe Trashable do
|
||||
p1 = Fabricate(:post)
|
||||
p2 = Fabricate(:post)
|
||||
|
||||
Post.count.should == 2
|
||||
p1.trash!
|
||||
|
||||
Post.count.should == 1
|
||||
|
||||
Post.with_deleted.count.should == 2
|
||||
expect { p1.trash! }.to change{Post.count}.by(-1)
|
||||
Post.with_deleted.count.should == Post.count + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user