guid_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ldap::Guid do
  4. let(:string) { 'f742b361-32c6-4a92-baaa-eaae7df657ee' }
  5. let(:hex) { "a\xB3B\xF7\xC62\x92J\xBA\xAA\xEA\xAE}\xF6W\xEE".b }
  6. describe '.valid?' do
  7. it 'responds to .valid?' do
  8. expect(described_class).to respond_to(:valid?)
  9. end
  10. it 'detects valid uid string' do
  11. expect(described_class.valid?(string)).to be true
  12. end
  13. it 'detects invalid uid string' do
  14. invalid = 'AC2342'
  15. expect(described_class.valid?(invalid)).to be false
  16. end
  17. end
  18. describe '.hex' do
  19. it 'responds to .hex' do
  20. expect(described_class).to respond_to(:hex)
  21. end
  22. it 'tunnels to instance method' do
  23. instance = double
  24. allow(instance).to receive(:hex)
  25. allow(described_class).to receive(:new).with(string).and_return(instance)
  26. described_class.hex(string)
  27. expect(instance).to have_received(:hex)
  28. end
  29. end
  30. describe '.string' do
  31. it 'responds to .string' do
  32. expect(described_class).to respond_to(:string)
  33. end
  34. it 'tunnels to instance method' do
  35. instance = double
  36. allow(instance).to receive(:string)
  37. allow(described_class).to receive(:new).with(hex).and_return(instance)
  38. described_class.string(hex)
  39. expect(instance).to have_received(:string)
  40. end
  41. end
  42. describe '#string' do
  43. let(:instance) { described_class.new(hex) }
  44. it 'responds to #string' do
  45. expect(instance).to respond_to(:string)
  46. end
  47. it 'converts to string' do
  48. expect(instance.string).to eq(string)
  49. end
  50. end
  51. describe '#hex' do
  52. let(:instance) { described_class.new(string) }
  53. it 'responds to #hex' do
  54. expect(instance).to respond_to(:hex)
  55. end
  56. it 'converts to hex' do
  57. expect(instance.hex).to eq(hex)
  58. end
  59. end
  60. end