Sha256: 8944cfd75ba33feebb5ee96f50881dd6297e3b02c38efa2e9c75939c7c3c37db

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe Spotlight::ContactEmail, :type => :model do
  let(:exhibit) { FactoryGirl.create(:exhibit) }
  subject { Spotlight::ContactEmail.new(exhibit: exhibit) }

  it { is_expected.not_to be_valid }

  describe "with an invalid email set" do
    before { subject.email = '@-foo' }
    it "should not be valid" do
      expect(subject).to_not be_valid 
      expect(subject.errors[:email]).to eq ['is not valid']
    end
  end

  describe "with a valid email set" do
    before { subject.email = 'foo@example.com' }
    it { is_expected.to be_valid }

    describe "when saved" do
      it "should send a confirmation" do
        expect(subject).to receive(:send_devise_notification)
        subject.save 
      end
    end
    describe "#send_devise_notification" do
      it "should send stuff" do
        expect {
          subject.send(:send_devise_notification, :confirmation_instructions, "Q7PEPdLVxymsQL2_s_Rg", {})
        }.to change { ActionMailer::Base.deliveries.count }.by(1)
      end
    end
  end
  
  describe ".confirmed" do
    it "should scope contacts to only confirmed contacts" do
      a = exhibit.contact_emails.create(:email => 'a@example.com')
      a.confirm!
      b = exhibit.contact_emails.create(:email => 'b@example.com')
      
      expect(Spotlight::ContactEmail.confirmed.to_a).to include a
      expect(Spotlight::ContactEmail.confirmed.to_a).to_not include b
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-spotlight-0.4.1 spec/models/spotlight/contact_email_spec.rb
blacklight-spotlight-0.3.1 spec/models/spotlight/contact_email_spec.rb
blacklight-spotlight-0.3.0 spec/models/spotlight/contact_email_spec.rb
blacklight-spotlight-0.2.0 spec/models/spotlight/contact_email_spec.rb