Sha256: 4117fca5e0385598fb133eaf7f94007fac8992252ef26bcb8d3b0e14391432b6

Contents?: true

Size: 909 Bytes

Versions: 7

Compression:

Stored size: 909 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Macros::Auth::SignIn do
  include Warden::Test::Mock

  subject(:sign_in_step) { described_class.new }

  let(:user) { mock_model('User') }
  let(:scope) { :user }
  let(:ctx) { { model: user, warden: warden } }

  before do
    fake_class = Class.new
    dm = stub_const('Devise::Mapping', fake_class, transfer_nested_constants: true)
    allow(dm).to receive(:find_scope!).with(user).and_return(scope)
  end

  context 'user not signed in' do
    it 'expects to sign in' do
      sign_in_step.call(ctx, model: user, warden: warden)

      expect(ctx[:current_user]).to eql user
    end
  end

  context 'user already signed in' do
    before do
      warden.set_user(user, scope: scope)
    end

    it 'expects to keep user signed in' do
      sign_in_step.call(ctx, model: user, warden: warden)

      expect(ctx[:current_user]).to eql user
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ff-tbl-macros-2.0.2 spec/lib/auth/sign_in_spec.rb
ff-tbl-macros-2.0.1 spec/lib/auth/sign_in_spec.rb
ff-tbl-macros-2.0.0 spec/lib/auth/sign_in_spec.rb
ff-tbl-macros-1.0.2 spec/lib/auth/sign_in_spec.rb
ff-tbl-macros-1.0.1 spec/lib/auth/sign_in_spec.rb
ff-tbl-macros-1.0.0 spec/lib/auth/sign_in_spec.rb
ff-tbl-macros-0.1.8 spec/lib/auth/sign_in_spec.rb