fix comment commit specs

This commit is contained in:
Alexander Machehin 2015-05-11 12:29:58 +05:00
parent 0034250f33
commit 343fe35312
2 changed files with 17 additions and 6 deletions

View File

@ -30,8 +30,15 @@ def should_send_email(args={})
end end
def should_not_send_email(args={}) def should_not_send_email(args={})
expect(UserMailer).to_not receive(:new_comment_notification)
create_comment args[:commentor] create_comment args[:commentor]
expect(UserMailer).to_not receive(:new_comment_notification)
end
def should_send_emails(commentor:, receivers:)
reset_email
create_comment commentor
expect(ActionMailer::Base.deliveries.count).to eq(receivers.count)
expect(ActionMailer::Base.deliveries.map &:to).to match_array(receivers.map {|u| [u.email]})
end end
describe Comment do describe Comment do
@ -47,28 +54,28 @@ describe Comment do
create_relation(@project, @admin, 'admin') create_relation(@project, @admin, 'admin')
end end
it 'should send an e-mail by default settings' do it 'should send two emails by default settings' do
should_send_email(commentor: @stranger, receiver: @user) should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end end
context 'for disabled notify setting new_comment_commit_repo_owner' do context 'for disabled notify setting new_comment_commit_repo_owner' do
it 'should send an e-mail' do it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_repo_owner, false @user.notifier.update_column :new_comment_commit_repo_owner, false
should_send_email(commentor: @stranger, receiver: @user) should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end end
end end
context 'for disabled notify setting new_comment_commit_owner' do context 'for disabled notify setting new_comment_commit_owner' do
it 'should send an e-mail' do it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_owner, false @user.notifier.update_column :new_comment_commit_owner, false
should_send_email(commentor: @stranger, receiver: @user) should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end end
end end
context 'for disabled notify setting new_comment_commit_commentor' do context 'for disabled notify setting new_comment_commit_commentor' do
it 'should send an e-mail' do it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_commentor, false @user.notifier.update_column :new_comment_commit_commentor, false
should_send_email(commentor: @stranger, receiver: @user) should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end end
end end

View File

@ -93,3 +93,7 @@ end
def clean_projects_dir def clean_projects_dir
FileUtils.rm_rf "#{APP_CONFIG['git_path']}" FileUtils.rm_rf "#{APP_CONFIG['git_path']}"
end end
def reset_email
ActionMailer::Base.deliveries = []
end