diff --git a/lib/suggested_topics_builder.rb b/lib/suggested_topics_builder.rb index 9aec8a1da..bd4c3e54c 100644 --- a/lib/suggested_topics_builder.rb +++ b/lib/suggested_topics_builder.rb @@ -19,7 +19,7 @@ class SuggestedTopicsBuilder # Only add results if we don't have those topic ids already results = results.where('topics.id NOT IN (?)', @excluded_topic_ids) - .where(closed: false, archived: false, visible: true) + .where(visible: true) .to_a .reject { |topic| @category_topic_ids.include?(topic.id) } diff --git a/lib/topic_query.rb b/lib/topic_query.rb index a1faa1cb5..c6f86c4f2 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -309,7 +309,7 @@ class TopicQuery end def random_suggested(topic, count, excluded_topic_ids=[]) - result = default_results(unordered: true, per_page: count) + result = default_results(unordered: true, per_page: count).where(closed: false, archived: false) excluded_topic_ids += Category.pluck(:topic_id).compact result = result.where("topics.id NOT IN (?)", excluded_topic_ids) unless excluded_topic_ids.empty? diff --git a/spec/components/suggested_topics_builder_spec.rb b/spec/components/suggested_topics_builder_spec.rb index dc2f17bfa..a10e3eddd 100644 --- a/spec/components/suggested_topics_builder_spec.rb +++ b/spec/components/suggested_topics_builder_spec.rb @@ -83,14 +83,14 @@ describe SuggestedTopicsBuilder do end - context "adding invalid status topics" do + context "adding topics that are not open" do let!(:archived_topic) { Fabricate(:topic, archived: true)} let!(:closed_topic) { Fabricate(:topic, closed: true)} let!(:invisible_topic) { Fabricate(:topic, visible: false)} - it "doesn't add archived, closed or invisible topics" do + it "adds archived and closed, but not invisible topics" do builder.add_results(Topic) - builder.size.should == 0 + builder.size.should == 2 builder.should_not be_full end end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 76f5f82a1..28e1410ed 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -366,7 +366,7 @@ describe TopicQuery do end end - context "anonymously browswing with invisible, closed and archived" do + context "anonymously browsing with invisible, closed and archived" do let!(:topic) { Fabricate(:topic) } let!(:regular_topic) { Fabricate(:post, user: creator).topic } let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) } @@ -394,12 +394,20 @@ describe TopicQuery do let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) } let!(:archived_topic) { Fabricate(:topic, user: creator, archived: true) } let!(:invisible_topic) { Fabricate(:topic, user: creator, visible: false) } + let!(:fully_read_closed) { Fabricate(:post, user: creator).topic } + let!(:fully_read_archived) { Fabricate(:post, user: creator).topic } before do user.auto_track_topics_after_msecs = 0 user.save TopicUser.update_last_read(user, partially_read.id, 0, 0) TopicUser.update_last_read(user, fully_read.id, 1, 0) + TopicUser.update_last_read(user, fully_read_closed.id, 1, 0) + TopicUser.update_last_read(user, fully_read_archived.id, 1, 0) + fully_read_closed.closed = true + fully_read_closed.save + fully_read_archived.archived = true + fully_read_archived.save end it "won't return new or fully read if there are enough partially read topics" do @@ -407,14 +415,22 @@ describe TopicQuery do suggested_topics.should == [partially_read.id] end - it "won't fully read if there are enough partially read topics and new topics" do - SiteSetting.stubs(:suggested_topics).returns(2) - suggested_topics.should == [partially_read.id, new_topic.id] + it "won't return fully read if there are enough partially read topics and new topics" do + SiteSetting.stubs(:suggested_topics).returns(4) + suggested_topics[0].should == partially_read.id + suggested_topics[1,3].should include(new_topic.id) + suggested_topics[1,3].should include(closed_topic.id) + suggested_topics[1,3].should include(archived_topic.id) end it "returns unread, then new, then random" do - SiteSetting.stubs(:suggested_topics).returns(3) - suggested_topics.should == [partially_read.id, new_topic.id, fully_read.id] + SiteSetting.stubs(:suggested_topics).returns(7) + suggested_topics[0].should == partially_read.id + suggested_topics[1,3].should include(new_topic.id) + suggested_topics[1,3].should include(closed_topic.id) + suggested_topics[1,3].should include(archived_topic.id) + suggested_topics[4].should == fully_read.id + # random doesn't include closed and archived end end