From 343fe3531238ebaf04c5d00507e3e1e7b7c062ce Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 11 May 2015 12:29:58 +0500 Subject: [PATCH] fix comment commit specs --- spec/models/comment_for_commit_spec.rb | 19 +++++++++++++------ spec/spec_helper.rb | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index b8df9cad8..4f7ef13b6 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -30,8 +30,15 @@ def should_send_email(args={}) end def should_not_send_email(args={}) - expect(UserMailer).to_not receive(:new_comment_notification) 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 describe Comment do @@ -47,28 +54,28 @@ describe Comment do create_relation(@project, @admin, 'admin') end - it 'should send an e-mail by default settings' do - should_send_email(commentor: @stranger, receiver: @user) + it 'should send two emails by default settings' do + should_send_emails(commentor: @stranger, receivers: [@user, @admin]) end context 'for disabled notify setting new_comment_commit_repo_owner' do it 'should send an e-mail' do @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 context 'for disabled notify setting new_comment_commit_owner' do it 'should send an e-mail' do @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 context 'for disabled notify setting new_comment_commit_commentor' do it 'should send an e-mail' do @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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fcf0b5993..c4f047b4b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -93,3 +93,7 @@ end def clean_projects_dir FileUtils.rm_rf "#{APP_CONFIG['git_path']}" end + +def reset_email + ActionMailer::Base.deliveries = [] +end