Guo Xiang Tan
2017-10-06 15:56:58 +08:00
parent 814c7ab503
commit 79de10b212
14 changed files with 101 additions and 16 deletions

View File

@ -233,6 +233,27 @@ describe Guardian do
end
end
end
context 'target user has private message disabled' do
before do
another_user.user_option.update!(allow_private_messages: false)
end
context 'for a normal user' do
it 'should return false' do
expect(Guardian.new(user).can_send_private_message?(another_user)).to eq(false)
end
end
context 'for a staff user' do
it 'should return true' do
[admin, moderator].each do |staff_user|
expect(Guardian.new(staff_user).can_send_private_message?(another_user))
.to eq(true)
end
end
end
end
end
describe 'can_reply_as_new_topic' do

View File

@ -954,6 +954,30 @@ describe PostCreator do
end
end
context 'private message to a user that has disabled private messages' do
let(:another_user) { Fabricate(:user) }
before do
another_user.user_option.update!(allow_private_messages: false)
end
it 'should not be valid' do
post_creator = PostCreator.new(
user,
title: 'this message is to someone who muted me!',
raw: "you will have to see this even if you muted me!",
archetype: Archetype.private_message,
target_usernames: "#{another_user.username}"
)
expect(post_creator).to_not be_valid
expect(post_creator.errors.full_messages).to include(I18n.t(
"not_accepting_pms", username: another_user.username
))
end
end
context "private message to a muted user" do
let(:muted_me) { Fabricate(:evil_trout) }