DEV: Add missing test cases for `Topic.for_digest` and `Topic.secured`.
This commit is contained in:
parent
c9ddc6ce30
commit
d299197392
|
@ -1656,7 +1656,7 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'for_digest' do
|
||||
describe '.for_digest' do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
|
||||
context "no edit grace period" do
|
||||
|
@ -1688,6 +1688,18 @@ describe Topic do
|
|||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
|
||||
end
|
||||
|
||||
it "doesn't return topics that a user has muted" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
Fabricate(:topic_user,
|
||||
user: user,
|
||||
topic: topic,
|
||||
notification_level: TopicUser.notification_levels[:muted]
|
||||
)
|
||||
|
||||
expect(Topic.for_digest(user, 1.year.ago)).to eq([])
|
||||
end
|
||||
|
||||
it "doesn't return topics from suppressed categories" do
|
||||
user = Fabricate(:user)
|
||||
category = Fabricate(:category)
|
||||
|
@ -1784,21 +1796,24 @@ describe Topic do
|
|||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic1])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'secured' do
|
||||
it 'can remove secure groups' do
|
||||
describe '.secured' do
|
||||
it 'should return the right topics' do
|
||||
category = Fabricate(:category, read_restricted: true)
|
||||
Fabricate(:topic, category: category, created_at: 1.day.ago)
|
||||
topic = Fabricate(:topic, category: category, created_at: 1.day.ago)
|
||||
group = Fabricate(:group)
|
||||
user = Fabricate(:user)
|
||||
group.add(user)
|
||||
private_category = Fabricate(:private_category, group: group)
|
||||
|
||||
expect(Topic.secured(Guardian.new(nil)).count).to eq(0)
|
||||
expect(Topic.secured(Guardian.new(Fabricate(:admin))).count).to eq(2)
|
||||
expect(Topic.secured(Guardian.new(nil))).to eq([])
|
||||
|
||||
# for_digest
|
||||
expect(Topic.secured(Guardian.new(user)))
|
||||
.to contain_exactly(private_category.topic)
|
||||
|
||||
expect(Topic.for_digest(Fabricate(:user), 1.year.ago).count).to eq(0)
|
||||
expect(Topic.for_digest(Fabricate(:admin), 1.year.ago).count).to eq(1)
|
||||
expect(Topic.secured(Guardian.new(Fabricate(:admin))))
|
||||
.to contain_exactly(category.topic, private_category.topic, topic)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue