Suggested topics includes closed and archived in new and unread, but not in random results

This commit is contained in:
Neil Lalonde 2014-02-04 12:26:38 -05:00
parent 359f03ca73
commit 9601684405
4 changed files with 27 additions and 11 deletions

View file

@ -19,7 +19,7 @@ class SuggestedTopicsBuilder
# Only add results if we don't have those topic ids already # Only add results if we don't have those topic ids already
results = results.where('topics.id NOT IN (?)', @excluded_topic_ids) results = results.where('topics.id NOT IN (?)', @excluded_topic_ids)
.where(closed: false, archived: false, visible: true) .where(visible: true)
.to_a .to_a
.reject { |topic| @category_topic_ids.include?(topic.id) } .reject { |topic| @category_topic_ids.include?(topic.id) }

View file

@ -309,7 +309,7 @@ class TopicQuery
end end
def random_suggested(topic, count, excluded_topic_ids=[]) 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 excluded_topic_ids += Category.pluck(:topic_id).compact
result = result.where("topics.id NOT IN (?)", excluded_topic_ids) unless excluded_topic_ids.empty? result = result.where("topics.id NOT IN (?)", excluded_topic_ids) unless excluded_topic_ids.empty?

View file

@ -83,14 +83,14 @@ describe SuggestedTopicsBuilder do
end end
context "adding invalid status topics" do context "adding topics that are not open" do
let!(:archived_topic) { Fabricate(:topic, archived: true)} let!(:archived_topic) { Fabricate(:topic, archived: true)}
let!(:closed_topic) { Fabricate(:topic, closed: true)} let!(:closed_topic) { Fabricate(:topic, closed: true)}
let!(:invisible_topic) { Fabricate(:topic, visible: false)} 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.add_results(Topic)
builder.size.should == 0 builder.size.should == 2
builder.should_not be_full builder.should_not be_full
end end
end end

View file

@ -366,7 +366,7 @@ describe TopicQuery do
end end
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!(:topic) { Fabricate(:topic) }
let!(:regular_topic) { Fabricate(:post, user: creator).topic } let!(:regular_topic) { Fabricate(:post, user: creator).topic }
let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) } 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!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) }
let!(:archived_topic) { Fabricate(:topic, user: creator, archived: true) } let!(:archived_topic) { Fabricate(:topic, user: creator, archived: true) }
let!(:invisible_topic) { Fabricate(:topic, user: creator, visible: false) } 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 before do
user.auto_track_topics_after_msecs = 0 user.auto_track_topics_after_msecs = 0
user.save user.save
TopicUser.update_last_read(user, partially_read.id, 0, 0) 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.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 end
it "won't return new or fully read if there are enough partially read topics" do 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] suggested_topics.should == [partially_read.id]
end end
it "won't fully read if there are enough partially read topics and new topics" do it "won't return fully read if there are enough partially read topics and new topics" do
SiteSetting.stubs(:suggested_topics).returns(2) SiteSetting.stubs(:suggested_topics).returns(4)
suggested_topics.should == [partially_read.id, new_topic.id] 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 end
it "returns unread, then new, then random" do it "returns unread, then new, then random" do
SiteSetting.stubs(:suggested_topics).returns(3) SiteSetting.stubs(:suggested_topics).returns(7)
suggested_topics.should == [partially_read.id, new_topic.id, fully_read.id] 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
end end