diff --git a/app/controllers/api/comments_controller.rb b/app/controllers/api/comments_controller.rb index ab6ec89..07412df 100644 --- a/app/controllers/api/comments_controller.rb +++ b/app/controllers/api/comments_controller.rb @@ -38,7 +38,7 @@ class Api::CommentsController < ApplicationController end def notify_via_email(user, comment) - if user.email.present? && user != comment.user + if user && user.email.present? && user != comment.user UserMailer.new_comment_email(user, comment).deliver end end diff --git a/spec/controllers/api/comments_controller_spec.rb b/spec/controllers/api/comments_controller_spec.rb index c2fecd4..b9ff9f8 100644 --- a/spec/controllers/api/comments_controller_spec.rb +++ b/spec/controllers/api/comments_controller_spec.rb @@ -141,5 +141,14 @@ describe Api::CommentsController do @controller.send(:notify_via_email, user, comment) end end + + context 'when asciicast author is unknown (nil)' do + let(:user) { nil } + + it "doesn't send email" do + UserMailer.should_not_receive(:new_comment_email) + @controller.send(:notify_via_email, user, comment) + end + end end end