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,19 +109,37 @@ describe TopicView do
expect { TopicView.new(topic.id, nil) }.to raise_error(Discourse::NotLoggedIn)
end
it "logs personal message views if log_check_personal_message is enabled" do
SiteSetting.log_personal_messages_views = true
private_message = Fabricate(:private_message_topic)
allowed_user = private_message.topic_allowed_users.first.user
context 'log_check_personal_message is enabled' do
let(:group) { Fabricate(:group) }
let(:private_message) { Fabricate(:private_message_topic, allowed_groups: [group]) }
before do
SiteSetting.log_personal_messages_views = true
evil_trout.admin = true
end
it "logs view if Admin views personal message for other user/group" do
allowed_user = private_message.topic_allowed_users.first.user
TopicView.new(private_message.id, allowed_user)
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
evil_trout.admin = true
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
it "provides an absolute url" do
expect(topic_view.absolute_url).to be_present
end