mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Category descriptions should not appear in digests
This commit is contained in:
parent
de30af9302
commit
948a545cb1
2 changed files with 36 additions and 9 deletions
|
@ -5,6 +5,7 @@ require_dependency 'rate_limiter'
|
|||
require_dependency 'text_sentinel'
|
||||
require_dependency 'text_cleaner'
|
||||
require_dependency 'trashable'
|
||||
require_dependency 'archetype'
|
||||
|
||||
class Topic < ActiveRecord::Base
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
|
@ -228,14 +229,21 @@ class Topic < ActiveRecord::Base
|
|||
|
||||
# Returns hot topics since a date for display in email digest.
|
||||
def self.for_digest(user, since)
|
||||
Topic
|
||||
.visible
|
||||
.secured(Guardian.new(user))
|
||||
.where(closed: false, archived: false)
|
||||
.created_since(since)
|
||||
.listable_topics
|
||||
.order(:percent_rank)
|
||||
.limit(100)
|
||||
topics = Topic
|
||||
.visible
|
||||
.secured(Guardian.new(user))
|
||||
.where(closed: false, archived: false)
|
||||
.created_since(since)
|
||||
.listable_topics
|
||||
.order(:percent_rank)
|
||||
.limit(100)
|
||||
|
||||
category_topic_ids = Category.pluck(:topic_id).compact!
|
||||
if category_topic_ids.present?
|
||||
topics = topics.where("id NOT IN (?)", category_topic_ids)
|
||||
end
|
||||
|
||||
topics
|
||||
end
|
||||
|
||||
def update_meta_data(data)
|
||||
|
|
|
@ -1116,6 +1116,25 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'for_digest' do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
|
||||
it "returns none when there are no topics" do
|
||||
Topic.for_digest(user, 1.year.ago).should be_blank
|
||||
end
|
||||
|
||||
it "doesn't return category topics" do
|
||||
Fabricate(:category)
|
||||
Topic.for_digest(user, 1.year.ago).should be_blank
|
||||
end
|
||||
|
||||
it "returns regular topics" do
|
||||
topic = Fabricate(:topic)
|
||||
Topic.for_digest(user, 1.year.ago).should == [topic]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'secured' do
|
||||
it 'can remove secure groups' do
|
||||
category = Fabricate(:category, read_restricted: true)
|
||||
|
@ -1127,7 +1146,7 @@ describe Topic do
|
|||
# for_digest
|
||||
|
||||
Topic.for_digest(Fabricate(:user), 1.year.ago).count.should == 0
|
||||
Topic.for_digest(Fabricate(:admin), 1.year.ago).count.should == 2
|
||||
Topic.for_digest(Fabricate(:admin), 1.year.ago).count.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue