2018-01-12 11:53:43 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Ldap::Guid do
|
|
|
|
|
|
|
|
let(:string) { 'f742b361-32c6-4a92-baaa-eaae7df657ee' }
|
|
|
|
let(:hex) { "a\xB3B\xF7\xC62\x92J\xBA\xAA\xEA\xAE}\xF6W\xEE".b }
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.valid?' do
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
it 'responds to .valid?' do
|
|
|
|
expect(described_class).to respond_to(:valid?)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'detects valid uid string' do
|
|
|
|
expect(described_class.valid?(string)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'detects invalid uid string' do
|
|
|
|
invalid = 'AC2342'
|
|
|
|
expect(described_class.valid?(invalid)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.hex' do
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
it 'responds to .hex' do
|
|
|
|
expect(described_class).to respond_to(:hex)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tunnels to instance method' do
|
|
|
|
instance = double()
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(instance).to receive(:hex)
|
|
|
|
allow(described_class).to receive(:new).with(string).and_return(instance)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
described_class.hex(string)
|
2020-10-22 13:57:01 +00:00
|
|
|
|
|
|
|
expect(instance).to have_received(:hex)
|
2018-01-12 11:53:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.string' do
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
it 'responds to .string' do
|
|
|
|
expect(described_class).to respond_to(:string)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tunnels to instance method' do
|
|
|
|
|
|
|
|
instance = double()
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(instance).to receive(:string)
|
|
|
|
allow(described_class).to receive(:new).with(hex).and_return(instance)
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
described_class.string(hex)
|
2020-10-22 13:57:01 +00:00
|
|
|
expect(instance).to have_received(:string)
|
2018-01-12 11:53:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '#string' do
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
let(:instance) { described_class.new(hex) }
|
|
|
|
|
|
|
|
it 'responds to #string' do
|
|
|
|
expect(instance).to respond_to(:string)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'converts to string' do
|
|
|
|
expect(instance.string).to eq(string)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '#hex' do
|
2018-01-12 11:53:43 +00:00
|
|
|
|
|
|
|
let(:instance) { described_class.new(string) }
|
|
|
|
|
|
|
|
it 'responds to #hex' do
|
|
|
|
expect(instance).to respond_to(:hex)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'converts to hex' do
|
|
|
|
expect(instance.hex).to eq(hex)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|