Sha256: d7f2210740af1ba6fafa83a93cbe2eed60c386adb160cfd8e3caea9eda94f041

Contents?: true

Size: 1.29 KB

Versions: 40

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

describe Spotlight::InviteUsersService do
  subject { described_class.call(resource: resource) }

  let(:resource) do
    FactoryBot.create(:exhibit, roles: [FactoryBot.create(:role, user: user)])
  end

  context 'when the user was not created by an invite' do
    let(:user) { FactoryBot.create(:user) }

    it 'does not send an invite' do
      expect do
        subject
      end.to change { Devise::Mailer.deliveries.count }.by(0)
      expect(user.reload.invitation_sent_at).to be_nil
    end
  end

  context 'when the user has already received an invite' do
    let!(:user) do
      User.invite!(email: 'a-user-that-does-not-exist@example.com', skip_invitation: true).tap do |u|
        u.invitation_sent_at = Time.zone.now
      end
    end

    it 'does not send an invite' do
      expect do
        subject
      end.to change { Devise::Mailer.deliveries.count }.by(0)
    end
  end

  context 'when the user was created by but not yet received an invite' do
    let(:user) do
      User.invite!(email: 'a-user-that-does-not-exist@example.com', skip_invitation: true)
    end

    it 'sends an invite' do
      expect do
        subject
      end.to change { Devise::Mailer.deliveries.count }.by(1)
      expect(user.reload.invitation_sent_at).to be_present
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
blacklight-spotlight-3.4.0 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.3.0 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.2.0 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.1.0 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.3 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.2 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.1 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.rc6 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.rc5 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.rc4 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.rc3 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.rc2 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.rc1 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.alpha.10 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.alpha.9 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.alpha.8 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.alpha.7 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.alpha.6 spec/services/spotlight/invite_users_service_spec.rb
blacklight-spotlight-3.0.0.alpha.5 spec/services/spotlight/invite_users_service_spec.rb