Category Topics are no longer invisible, they are pinned.

This commit is contained in:
Robin Ward 2013-03-07 12:45:49 -05:00
parent c7359145aa
commit 052887c296
4 changed files with 16 additions and 9 deletions

View File

@ -30,6 +30,7 @@ class Category < ActiveRecord::Base
topics = Topic
.select("COUNT(*)")
.where("topics.category_id = categories.id")
.where("categories.topic_id <> topics.id")
.visible
topics_year = topics.created_since(1.year.ago).to_sql
@ -50,7 +51,7 @@ class Category < ActiveRecord::Base
end
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"))
topic.posts.create!(raw: post_contents, user: user)

View File

@ -72,7 +72,7 @@ describe CategoryList do
end
it "should contain our topic" do
category.featured_topics.should == [topic]
category.featured_topics.include?(topic).should be_true
end
end

View File

@ -47,6 +47,7 @@ describe TopicQuery do
context 'categorized' do
let(:category) { Fabricate(:category) }
let(:topic_category) { category.topic }
let!(:topic_no_cat) { Fabricate(:topic) }
let!(:topic_in_cat) { Fabricate(:topic, category: category) }
@ -55,16 +56,17 @@ describe TopicQuery do
end
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
it "returns nothing when filtering by another category" do
topic_query.list_category(Fabricate(:category, name: 'new cat')).topics.should be_blank
it "returns only the topic category when filtering by another category" do
another_category = Fabricate(:category, name: 'new cat')
topic_query.list_category(another_category).topics.should == [another_category.topic]
end
describe '#list_new_in_category' do
it 'returns only the categorized topic' do
topic_query.list_new_in_category(category).topics.should == [topic_in_cat]
it 'returns the topic category and the categorized topic' do
topic_query.list_new_in_category(category).topics.should == [topic_in_cat, topic_category]
end
end
end

View File

@ -99,8 +99,12 @@ describe Category do
@topic.category.should == @category
end
it 'is an invisible topic' do
@topic.should_not be_visible
it 'is a visible topic' do
@topic.should be_visible
end
it 'is pinned' do
@topic.pinned_at.should be_present
end
it 'is an undeletable topic' do