From 052887c29678a960e841dbcaf4abfc52bcf19236 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 7 Mar 2013 12:45:49 -0500 Subject: [PATCH] Category Topics are no longer invisible, they are pinned. --- app/models/category.rb | 3 ++- spec/components/category_list_spec.rb | 2 +- spec/components/topic_query_spec.rb | 12 +++++++----- spec/models/category_spec.rb | 8 ++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/models/category.rb b/app/models/category.rb index 0c4e76a41..c1643c68a 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -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) diff --git a/spec/components/category_list_spec.rb b/spec/components/category_list_spec.rb index 1abefbb7c..c0d411446 100644 --- a/spec/components/category_list_spec.rb +++ b/spec/components/category_list_spec.rb @@ -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 diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 4536cec36..20717e452 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -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 diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 8a69e80a0..9ae7ced90 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -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