mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Category Topics are no longer invisible, they are pinned.
This commit is contained in:
parent
c7359145aa
commit
052887c296
4 changed files with 16 additions and 9 deletions
|
@ -30,6 +30,7 @@ class Category < ActiveRecord::Base
|
||||||
topics = Topic
|
topics = Topic
|
||||||
.select("COUNT(*)")
|
.select("COUNT(*)")
|
||||||
.where("topics.category_id = categories.id")
|
.where("topics.category_id = categories.id")
|
||||||
|
.where("categories.topic_id <> topics.id")
|
||||||
.visible
|
.visible
|
||||||
|
|
||||||
topics_year = topics.created_since(1.year.ago).to_sql
|
topics_year = topics.created_since(1.year.ago).to_sql
|
||||||
|
@ -50,7 +51,7 @@ class Category < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
after_create do
|
after_create do
|
||||||
topic = Topic.create!(title: I18n.t("category.topic_prefix", category: name), user: user, visible: false)
|
topic = Topic.create!(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now)
|
||||||
|
|
||||||
post_contents = I18n.t("category.post_template", replace_paragraph: I18n.t("category.replace_paragraph"))
|
post_contents = I18n.t("category.post_template", replace_paragraph: I18n.t("category.replace_paragraph"))
|
||||||
topic.posts.create!(raw: post_contents, user: user)
|
topic.posts.create!(raw: post_contents, user: user)
|
||||||
|
|
|
@ -72,7 +72,7 @@ describe CategoryList do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should contain our topic" do
|
it "should contain our topic" do
|
||||||
category.featured_topics.should == [topic]
|
category.featured_topics.include?(topic).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ describe TopicQuery do
|
||||||
|
|
||||||
context 'categorized' do
|
context 'categorized' do
|
||||||
let(:category) { Fabricate(:category) }
|
let(:category) { Fabricate(:category) }
|
||||||
|
let(:topic_category) { category.topic }
|
||||||
let!(:topic_no_cat) { Fabricate(:topic) }
|
let!(:topic_no_cat) { Fabricate(:topic) }
|
||||||
let!(:topic_in_cat) { Fabricate(:topic, category: category) }
|
let!(:topic_in_cat) { Fabricate(:topic, category: category) }
|
||||||
|
|
||||||
|
@ -55,16 +56,17 @@ describe TopicQuery do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the topic with a category when filtering by category" do
|
it "returns the topic with a category when filtering by category" do
|
||||||
topic_query.list_category(category).topics.should == [topic_in_cat]
|
topic_query.list_category(category).topics.should == [topic_category, topic_in_cat]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nothing when filtering by another category" do
|
it "returns only the topic category when filtering by another category" do
|
||||||
topic_query.list_category(Fabricate(:category, name: 'new cat')).topics.should be_blank
|
another_category = Fabricate(:category, name: 'new cat')
|
||||||
|
topic_query.list_category(another_category).topics.should == [another_category.topic]
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#list_new_in_category' do
|
describe '#list_new_in_category' do
|
||||||
it 'returns only the categorized topic' do
|
it 'returns the topic category and the categorized topic' do
|
||||||
topic_query.list_new_in_category(category).topics.should == [topic_in_cat]
|
topic_query.list_new_in_category(category).topics.should == [topic_in_cat, topic_category]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,8 +99,12 @@ describe Category do
|
||||||
@topic.category.should == @category
|
@topic.category.should == @category
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is an invisible topic' do
|
it 'is a visible topic' do
|
||||||
@topic.should_not be_visible
|
@topic.should be_visible
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is pinned' do
|
||||||
|
@topic.pinned_at.should be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is an undeletable topic' do
|
it 'is an undeletable topic' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue