mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
Added forumer exclusion on recent_topics
This commit is contained in:
parent
25f184aeb0
commit
f990e74d57
2 changed files with 14 additions and 2 deletions
|
@ -42,7 +42,13 @@ class Topic < ActiveRecord::Base
|
|||
acts_as_readable
|
||||
|
||||
def self.recent_topics
|
||||
Post.order("id desc").select("DISTINCT topic_id").limit(5).map(&:topic)
|
||||
Post.joins("LEFT OUTER JOIN topics ON topics.id = posts.topic_id")
|
||||
.joins("LEFT OUTER JOIN forums on forums.id = topics.forum_id")
|
||||
.joins("LEFT OUTER JOIN forumers on forums.id = forumers.forum_id")
|
||||
.order("posts.id desc")
|
||||
.where("forumers.id IS NULL")
|
||||
.select("DISTINCT topic_id")
|
||||
.limit(5).map(&:topic)
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -29,7 +29,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
describe ".recent_topics" do
|
||||
before(:all) do
|
||||
before(:each) do
|
||||
5.times do
|
||||
topic = create :topic
|
||||
3.times { create :post, topic: topic }
|
||||
|
@ -40,5 +40,11 @@ describe Topic do
|
|||
expect(recent_topics.length).to eq(5)
|
||||
expect(recent_topics.map(&:id).uniq.length).to eq(5)
|
||||
end
|
||||
it "does not return posts from restricted forums" do
|
||||
restricted_topic = create :topic, title: "Restricted"
|
||||
create :forumer, forum: restricted_topic.forum
|
||||
create :post, topic: restricted_topic
|
||||
expect(Topic.recent_topics).to_not include(restricted_topic)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue