diff --git a/app/controllers/meeting_contents_controller.rb b/app/controllers/meeting_contents_controller.rb index b2c00e7d12..4077ee1d13 100644 --- a/app/controllers/meeting_contents_controller.rb +++ b/app/controllers/meeting_contents_controller.rb @@ -84,7 +84,7 @@ class MeetingContentsController < ApplicationController def notify unless @content.new_record? recipients = @content.meeting.participants.collect{|p| p.mail}.reject{|r| r == @content.meeting.author.mail} - recipients << @content.meeting.author.mail if @content.meeting.author.preference[:no_self_notified] + recipients << @content.meeting.author.mail unless @content.meeting.author.preference[:no_self_notified] recipients.each do |recipient| MeetingMailer.content_for_review(@content, @content_type, recipient).deliver end diff --git a/spec/controllers/meeting_contents_controller_spec.rb b/spec/controllers/meeting_contents_controller_spec.rb index 614e741c29..ced8c13a86 100644 --- a/spec/controllers/meeting_contents_controller_spec.rb +++ b/spec/controllers/meeting_contents_controller_spec.rb @@ -42,31 +42,33 @@ describe MeetingContentsController do controller.instance_variable_set(:@content_type, 'meeting_agenda') end + shared_examples_for 'delivered by mail' do + before { put "notify", meeting_id: meeting.id } + + it { expect(ActionMailer::Base.deliveries.count).to eql(mail_count) } + end + describe "PUT" do describe "notify" do context "when author no_self_notified property is true" do before do author.pref[:no_self_notified] = true author.save! - - put "notify", :meeting_id => meeting.id end - it 'should send mail to all meeting participants' do - expect(ActionMailer::Base.deliveries.count).to eql(3) + it_behaves_like 'delivered by mail' do + let(:mail_count) { 2 } end end context "when author no_self_notified property is false" do before do author.pref[:no_self_notified] = false - author.save - - put "notify", :meeting_id => meeting.id + author.save! end - it 'should send mail to all meeting participants except author' do - expect(ActionMailer::Base.deliveries.count).to eql(2) + it_behaves_like 'delivered by mail' do + let(:mail_count) { 3 } end end end diff --git a/spec/mailers/meeting_mailer_spec.rb b/spec/mailers/meeting_mailer_spec.rb index 5767eaee7d..0605c4654f 100644 --- a/spec/mailers/meeting_mailer_spec.rb +++ b/spec/mailers/meeting_mailer_spec.rb @@ -32,7 +32,7 @@ describe MeetingMailer do end before(:each) do - author.pref[:no_self_notified] = true + author.pref[:no_self_notified] = false author.save! meeting.participants.merge([meeting.participants.build(user: watcher1, invited: true, attended: false), meeting.participants.build(user: watcher1, invited: true, attended: false)])