diff --git a/app/mailers/report_mailer.rb b/app/mailers/report_mailer.rb index 5438bd9a7..57359cc68 100644 --- a/app/mailers/report_mailer.rb +++ b/app/mailers/report_mailer.rb @@ -8,10 +8,13 @@ class ReportMailer < ActionMailer::Base :id => id } Role.admins.each do |role| - user = User.find_by_id(role.person_id) - unless user.user_preferences.exists?(:email_type => :someone_reported) - resource[:email] = user.email - format(resource).deliver + person = Person.find(role.person_id) + if person.local? + user = User.find_by_id(person.owner_id) + unless user.user_preferences.exists?(:email_type => :someone_reported) + resource[:email] = user.email + format(resource).deliver + end end end end diff --git a/spec/mailers/report_spec.rb b/spec/mailers/report_spec.rb index e5d1b1608..9b41750a5 100644 --- a/spec/mailers/report_spec.rb +++ b/spec/mailers/report_spec.rb @@ -7,12 +7,13 @@ require 'spec_helper' describe Report do describe '#make_notification' do before do - @user = bob - Role.add_admin(@user) + @remote = FactoryGirl.create(:person, :diaspora_handle => "remote@remote.net") + @user = FactoryGirl.create(:user_with_aspect, :username => "local") + Role.add_admin(@user.person) end it "should deliver successfully" do - expect { + expect { ReportMailer.new_report('post', 666) }.to_not raise_error end @@ -22,5 +23,10 @@ describe Report do ReportMailer.new_report('post', 666) }.to change(ActionMailer::Base.deliveries, :size).by(1) end + + it "should include correct recipient" do + ReportMailer.new_report('post', 666) + expect(ActionMailer::Base.deliveries[0].to[0]).to include(@user.email) + end end end