diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 6e8fbea0f7f..b870ebdbeea 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -78,7 +78,7 @@ class PostAction < ActiveRecord::Base if message [:notify_moderators, :notify_user].each do |k| if post_action_type_id == PostActionType.types[k] - target_usernames = target_moderators(user) + target_usernames = k == :notify_moderators ? target_moderators(user) : post.user.username title = I18n.t("post_action_types.#{k}.email_title", title: post.topic.title) body = I18n.t("post_action_types.#{k}.email_body", diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 64cc448b024..bb55eaffc1b 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -20,6 +20,15 @@ describe PostAction do PostCreator.any_instance.expects(:create).returns(nil) PostAction.act(build(:user), build(:post), PostActionType.types[:notify_moderators], "this is my special message"); end + + it "sends an email to user if selected" do + PostAction.stubs(:create) + PostAction.expects(:target_moderators).returns("bob") + PostCreator.any_instance.expects(:create).returns(nil) + post = build(:post) + post.user = build(:user) + PostAction.act(build(:user), build(:post), PostActionType.types[:notify_user], "this is my special message"); + end end describe "flag counts" do