Sha256: 2dccf48492f89567f34acfc4c777847c14a425d95b0b1a1fde4145e61c17b237

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Authorizy::Config, '#current_user' do
  subject(:config) { described_class.new }

  context 'when uses default value' do
    context 'when context responds to current_user' do
      let!(:context) { OpenStruct.new(current_user: 'user') }

      it 'is called' do
        expect(subject.current_user.call(context)).to eq('user')
      end
    end

    context 'when context does not respond to current_user' do
      let!(:context) { 'context' }

      it 'returns nil' do
        expect(subject.current_user.call(context)).to be(nil)
      end
    end
  end

  context 'when uses custom value' do
    it 'executes what you want' do
      config.current_user = -> (context) { context[:value] }

      expect(config.current_user.call({ value: 'value' })).to eq('value')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authorizy-0.1.0 spec/authorizy/config/current_user_spec.rb