mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 22:51:24 +08:00
FEATURE: Whisper posts
This commit is contained in:
@ -437,6 +437,32 @@ describe Guardian do
|
||||
expect(Guardian.new(user).can_see?(post)).to be_falsey
|
||||
expect(Guardian.new(admin).can_see?(post)).to be_truthy
|
||||
end
|
||||
|
||||
it 'respects whispers' do
|
||||
regular_post = Fabricate.build(:post)
|
||||
whisper_post = Fabricate.build(:post, post_type: Post.types[:whisper])
|
||||
|
||||
anon_guardian = Guardian.new
|
||||
expect(anon_guardian.can_see?(regular_post)).to eq(true)
|
||||
expect(anon_guardian.can_see?(whisper_post)).to eq(false)
|
||||
|
||||
regular_user = Fabricate.build(:user)
|
||||
regular_guardian = Guardian.new(regular_user)
|
||||
expect(regular_guardian.can_see?(regular_post)).to eq(true)
|
||||
expect(regular_guardian.can_see?(whisper_post)).to eq(false)
|
||||
|
||||
# can see your own whispers
|
||||
regular_whisper = Fabricate.build(:post, post_type: Post.types[:whisper], user: regular_user)
|
||||
expect(regular_guardian.can_see?(regular_whisper)).to eq(true)
|
||||
|
||||
mod_guardian = Guardian.new(Fabricate.build(:moderator))
|
||||
expect(mod_guardian.can_see?(regular_post)).to eq(true)
|
||||
expect(mod_guardian.can_see?(whisper_post)).to eq(true)
|
||||
|
||||
admin_guardian = Guardian.new(Fabricate.build(:admin))
|
||||
expect(admin_guardian.can_see?(regular_post)).to eq(true)
|
||||
expect(admin_guardian.can_see?(whisper_post)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'a PostRevision' do
|
||||
|
@ -251,6 +251,23 @@ describe TopicView do
|
||||
|
||||
end
|
||||
|
||||
context 'whispers' do
|
||||
it "handles their visibility properly" do
|
||||
p1 = Fabricate(:post, topic: topic, user: coding_horror)
|
||||
p2 = Fabricate(:post, topic: topic, user: coding_horror, post_type: Post.types[:whisper])
|
||||
p3 = Fabricate(:post, topic: topic, user: coding_horror)
|
||||
|
||||
ch_posts = TopicView.new(topic.id, coding_horror).posts
|
||||
expect(ch_posts.map(&:id)).to eq([p1.id, p2.id, p3.id])
|
||||
|
||||
anon_posts = TopicView.new(topic.id).posts
|
||||
expect(anon_posts.map(&:id)).to eq([p1.id, p3.id])
|
||||
|
||||
admin_posts = TopicView.new(topic.id, Fabricate(:moderator)).posts
|
||||
expect(admin_posts.map(&:id)).to eq([p1.id, p2.id, p3.id])
|
||||
end
|
||||
end
|
||||
|
||||
context '.posts' do
|
||||
|
||||
# Create the posts in a different order than the sort_order
|
||||
|
Reference in New Issue
Block a user