add more tests for 'log private message views' feature
This commit is contained in:
parent
073d072aa6
commit
8ab585e25f
|
@ -109,19 +109,37 @@ 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
|
|
||||||
|
|
||||||
|
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)
|
TopicView.new(private_message.id, allowed_user)
|
||||||
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
|
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
|
||||||
|
|
||||||
evil_trout.admin = true
|
|
||||||
TopicView.new(private_message.id, evil_trout)
|
TopicView.new(private_message.id, evil_trout)
|
||||||
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(1)
|
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(1)
|
||||||
end
|
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
|
it "provides an absolute url" do
|
||||||
expect(topic_view.absolute_url).to be_present
|
expect(topic_view.absolute_url).to be_present
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue