add more tests for 'log private message views' feature

This commit is contained in:
Arpit Jalan 2018-01-29 13:09:07 +05:30
parent 073d072aa6
commit 8ab585e25f
1 changed files with 27 additions and 9 deletions

View File

@ -109,17 +109,35 @@ describe TopicView do
expect { TopicView.new(topic.id, nil) }.to raise_error(Discourse::NotLoggedIn) expect { TopicView.new(topic.id, nil) }.to raise_error(Discourse::NotLoggedIn)
end end
it "logs personal message views if log_check_personal_message is enabled" do context 'log_check_personal_message is enabled' do
SiteSetting.log_personal_messages_views = true let(:group) { Fabricate(:group) }
private_message = Fabricate(:private_message_topic) let(:private_message) { Fabricate(:private_message_topic, allowed_groups: [group]) }
allowed_user = private_message.topic_allowed_users.first.user
TopicView.new(private_message.id, allowed_user) before do
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0) SiteSetting.log_personal_messages_views = true
evil_trout.admin = true
end
evil_trout.admin = true it "logs view if Admin views personal message for other user/group" do
TopicView.new(private_message.id, evil_trout) allowed_user = private_message.topic_allowed_users.first.user
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(1) TopicView.new(private_message.id, allowed_user)
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
TopicView.new(private_message.id, evil_trout)
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(1)
end
it "does not log personal message view for group he belongs to" do
group.users << evil_trout
TopicView.new(private_message.id, evil_trout)
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
end
it "does not log personal message view for his own personal message" do
private_message.allowed_users << evil_trout
TopicView.new(private_message.id, evil_trout)
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
end
end end
it "provides an absolute url" do it "provides an absolute url" do