Skip to content

Commit 0d57a61

Browse files
committed
Exclude current topic from recent topics list of the node
Fixed ruby-china#180
1 parent 58dabcb commit 0d57a61

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/cells/topics_cell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def sidebar_for_node_recent_topics(args = {})
4545
topic = args[:topic]
4646
limit = topic.replies_count > 20 ? 20 : topic.replies_count
4747
limit = 1 if limit == 0
48-
@topics = topic.node.topics.recent.limit(limit)
48+
@topics = topic.node.topics.recent.not_in(id: [topic.id]).limit(limit)
4949
render
5050
end
5151

spec/cells/topics_cell_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@
7373
describe "sidebar_for_node_recent_topics" do
7474
let(:node) { Factory(:node) }
7575
let(:topic0) { Factory(:topic, :node => node) }
76+
77+
it "should not render if node only has one topic" do
78+
render_cell(:topics, :sidebar_for_node_recent_topics, :topic => topic0).should_not have_css("div.box ul li")
79+
end
80+
7681
it "should render" do
82+
topic1 = Factory(:topic, :node => node)
7783
render_cell(:topics, :sidebar_for_node_recent_topics, :topic => topic0).should have_css("div.box ul li", :count => 1)
7884
end
7985

@@ -82,6 +88,7 @@
8288
reply1 = Factory(:reply, :topic => topic0)
8389
reply2 = Factory(:reply, :topic => topic0)
8490
topic1 = Factory(:topic, :node => node)
91+
topic2 = Factory(:topic, :node => node)
8592
render_cell(:topics, :sidebar_for_node_recent_topics, :topic => topic0).should have_css("div.box ul li", :count => 2)
8693
end
8794
end

0 commit comments

Comments
 (0)