debian-mirror-gitlab/spec/models/concerns/token_authenticatable_strategies/base_spec.rb

42 lines
1.3 KiB
Ruby
Raw Normal View History

2019-05-18 00:54:41 +05:30
# frozen_string_literal: true
2019-02-15 15:39:39 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe TokenAuthenticatableStrategies::Base do
2019-02-15 15:39:39 +05:30
let(:instance) { double(:instance) }
let(:field) { double(:field) }
describe '.fabricate' do
context 'when digest stragegy is specified' do
it 'fabricates digest strategy object' do
strategy = described_class.fabricate(instance, field, digest: true)
expect(strategy).to be_a TokenAuthenticatableStrategies::Digest
end
end
context 'when encrypted strategy is specified' do
it 'fabricates encrypted strategy object' do
2019-05-18 00:54:41 +05:30
strategy = described_class.fabricate(instance, field, encrypted: :required)
2019-02-15 15:39:39 +05:30
expect(strategy).to be_a TokenAuthenticatableStrategies::Encrypted
end
end
context 'when no strategy is specified' do
it 'fabricates insecure strategy object' do
2019-05-18 00:54:41 +05:30
strategy = described_class.fabricate(instance, field, something: :required)
2019-02-15 15:39:39 +05:30
expect(strategy).to be_a TokenAuthenticatableStrategies::Insecure
end
end
context 'when incompatible options are provided' do
it 'raises an error' do
2019-05-18 00:54:41 +05:30
expect { described_class.fabricate(instance, field, digest: true, encrypted: :required) }
2019-02-15 15:39:39 +05:30
.to raise_error ArgumentError
end
end
end
end