<commit_before>require 'rails_helper'

describe Events::UserMentioned do
  describe "::publish!" do
    let(:discussion) { double :discussion }
    let(:comment) { double :comment, discussion: discussion }
    let(:mentioned_user) { double :user, email_when_mentioned?: false  }
    let(:discussion_reader) { double :discussion_reader, following?: false, follow!: true }
    let(:event) { double :event }

    before do
      allow(DiscussionReader).to receive(:for) { discussion_reader }
      allow(Events::UserMentioned).to receive(:create!) { event }
      allow(Events::UserMentioned).to receive(:notify!)
    end

    after do
      Events::UserMentioned.publish!(comment, mentioned_user)
    end

    it 'creates an event' do
      expect(Events::UserMentioned).to receive(:create!).with(kind: 'user_mentioned',
                                                              eventable: comment,
                                                              user: mentioned_user)
    end

    it 'returns an event' do
      Events::UserMentioned.publish!(comment, mentioned_user).should == event
    end

    context "mentioned user is not following" do
      before { allow(discussion_reader).to receive(:following?) { false } }

      context "wants email when mentioned" do
        before { allow(mentioned_user).to receive(:email_when_mentioned?) { true } }

        it "sends a mentioned email" do
          expect(UserMailer).to receive(:mentioned).with(mentioned_user, comment) { double deliver: true }
        end
      end

      context "does not want email when mentioned" do
        before { allow(mentioned_user).to receive(:email_when_mentioned?) { false } }

        it "does not send a mentioned email" do
          expect(UserMailer).to_not receive(:mentioned)
        end
      end

      it "enfollows the user" do
        expect(discussion_reader).to receive(:follow!)
      end
    end

    it "creates an in-app mentioned notification" do
      expect(Events::UserMentioned).to receive(:notify!).with(mentioned_user)
    end
  end
end
<commit_msg>wowza<commit_after>require 'rails_helper'

describe Events::UserMentioned do
  describe "::publish!" do
    let(:discussion) { double :discussion }
    let(:comment) { double :comment, discussion: discussion }
    let(:mentioned_user) { double :user, email_when_mentioned?: false  }
    let(:discussion_reader) { double :discussion_reader, following?: false, follow!: true }
    let(:event) { double :event }

    before do
      allow(DiscussionReader).to receive(:for) { discussion_reader }
      allow(Events::UserMentioned).to receive(:create!) { event }
      allow(Events::UserMentioned).to receive(:notify!)
    end

    after do
      Events::UserMentioned.publish!(comment, mentioned_user)
    end

    it 'creates an event' do
      expect(Events::UserMentioned).to receive(:create!).with(kind: 'user_mentioned',
                                                              eventable: comment,
                                                              user: mentioned_user)
    end

    it 'returns an event' do
      Events::UserMentioned.publish!(comment, mentioned_user).should == event
    end

    it "enfollows the user" do
      expect(discussion_reader).to receive(:follow!)
    end

    it "creates an in-app mentioned notification" do
      expect(Events::UserMentioned).to receive(:notify!).with(mentioned_user)
    end
  end
end

{'fraction_non_alphanumeric': 0.10262390670553936, 'fraction_numerical': 0.0, 'mean_word_length': 2.6734475374732334, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6027117', 'n_tokens_mistral': 943, 'n_tokens_neox': 887, 'n_words': 238}