DEV: Add missing test cases for Topic.for_digest and Topic.secured.

This commit is contained in:
Guo Xiang Tan 2019-04-05 09:00:48 +08:00
parent c9ddc6ce30
commit d299197392

View File

@ -1656,7 +1656,7 @@ describe Topic do
end end
end end
describe 'for_digest' do describe '.for_digest' do
let(:user) { Fabricate.build(:user) } let(:user) { Fabricate.build(:user) }
context "no edit grace period" do 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 expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
end 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 it "doesn't return topics from suppressed categories" do
user = Fabricate(:user) user = Fabricate(:user)
category = Fabricate(:category) category = Fabricate(:category)
@ -1784,21 +1796,24 @@ describe Topic do
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic1]) expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic1])
end end
end end
end end
describe 'secured' do describe '.secured' do
it 'can remove secure groups' do it 'should return the right topics' do
category = Fabricate(:category, read_restricted: true) 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(nil))).to eq([])
expect(Topic.secured(Guardian.new(Fabricate(:admin))).count).to eq(2)
# 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.secured(Guardian.new(Fabricate(:admin))))
expect(Topic.for_digest(Fabricate(:admin), 1.year.ago).count).to eq(1) .to contain_exactly(category.topic, private_category.topic, topic)
end end
end end