mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 13:01:02 +00:00
Added forumer exclusion on recent_topics
This commit is contained in:
parent
e34d21dd00
commit
5f53893756
2 changed files with 14 additions and 2 deletions
|
@ -42,7 +42,13 @@ class Topic < ActiveRecord::Base
|
||||||
acts_as_readable
|
acts_as_readable
|
||||||
|
|
||||||
def self.recent_topics
|
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
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe Topic do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".recent_topics" do
|
describe ".recent_topics" do
|
||||||
before(:all) do
|
before(:each) do
|
||||||
5.times do
|
5.times do
|
||||||
topic = create :topic
|
topic = create :topic
|
||||||
3.times { create :post, topic: topic }
|
3.times { create :post, topic: topic }
|
||||||
|
@ -40,5 +40,11 @@ describe Topic do
|
||||||
expect(recent_topics.length).to eq(5)
|
expect(recent_topics.length).to eq(5)
|
||||||
expect(recent_topics.map(&:id).uniq.length).to eq(5)
|
expect(recent_topics.map(&:id).uniq.length).to eq(5)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue