Sha256: cbc965bcbe4715984f78b9a5180e92d95d15e44a0d3c024ddff430761c23a4b7

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require "spec_helper"

module SocialNetworking
  RSpec.describe Notification do
    let(:participant) { instance_double(Participant) }
    let(:recipient) { instance_double(Participant) }
    let(:mailer) { double("mailer") }

    def notification(attributes = {})
      Notification.new({
        current_participant: participant,
        mailer: mailer,
        recipient: recipient,
        message_body: "foo",
        subject: "bar"
      }.merge(attributes))
    end

    describe ".notify" do
      describe "when recipient is the current_participant" do
        it "returns nil" do
          new_notification = notification(recipient: participant)

          expect(new_notification.notify).to be_nil
        end
      end

      describe "when recipient is not the current_participant" do
        describe "when recipient would prefer to receive emails" do
          it "sends an email" do
            allow(recipient)
              .to receive(:contact_preference) { "email" }

            expect_any_instance_of(Notification)
              .to receive(:send_email)

            notification.notify
          end
        end

        describe "when recipient would prefer to receive sms" do
          it "sends an sms" do
            allow(recipient)
              .to receive(:contact_preference) { "sms" }

            expect_any_instance_of(Notification)
              .to receive(:send_sms)

            notification.notify
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
social_networking-0.11.1 spec/models/social_networking/notification_spec.rb
social_networking-0.11.0 spec/models/social_networking/notification_spec.rb
social_networking-0.10.0 spec/models/social_networking/notification_spec.rb
social_networking-0.9.3 spec/models/social_networking/notification_spec.rb