Fix undefined variable in TopicCreator.

This commit is contained in:
Guo Xiang Tan
2017-09-28 12:25:42 +08:00
parent 4319d8a142
commit 426d2178c3
2 changed files with 37 additions and 16 deletions

View File

@ -8,7 +8,15 @@ describe TopicCreator do
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
let(:pm_valid_attrs) { { raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: moderator.username } }
let(:pm_to_email_valid_attrs) { { raw: 'this is a new email', title: 'this is a new subject', archetype: Archetype.private_message, target_emails: 'moderator@example.com' } }
let(:pm_to_email_valid_attrs) do
{
raw: 'this is a new email',
title: 'this is a new subject',
archetype: Archetype.private_message,
target_emails: 'moderator@example.com'
}
end
describe '#create' do
context 'topic success cases' do
@ -72,15 +80,25 @@ describe TopicCreator do
end
it "should be possible for a trusted user to send private messages via email" do
SiteSetting.expects(:enable_staged_users).returns(true)
SiteSetting.expects(:enable_staged_users).returns(true)
SiteSetting.expects(:enable_private_email_messages).returns(true)
SiteSetting.min_trust_to_send_email_messages = TrustLevel[1]
expect(TopicCreator.create(user, Guardian.new(user), pm_to_email_valid_attrs)).to be_valid
end
end
context 'failure cases' do
it "should be rollback the changes when email is invalid" do
SiteSetting.expects(:enable_private_email_messages).returns(true)
SiteSetting.min_trust_to_send_email_messages = TrustLevel[1]
attrs = pm_to_email_valid_attrs.dup
attrs[:target_emails] = "t" * 256
expect do
TopicCreator.create(user, Guardian.new(user), attrs)
end.to raise_error(ActiveRecord::Rollback)
end
it "min_trust_to_send_messages setting should be checked when sending private message" do
SiteSetting.min_trust_to_send_messages = TrustLevel[4]