Sha256: 9fac1ea5f29de26cdd5199c6d0dfe3f450f5f0bdfafca79a37e54cf709b55bf3

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require_relative '../spec_helper'

module Kamerling describe UUIDEntity do
  describe '.from_h' do
    it 'deserialises the object from a Hash' do
      Trivial = Class.new(UUIDEntity) { attribute :question, Symbol }
      Trivial.from_h(question: :answer).question.must_equal :answer
    end
  end

  describe '.new' do
    it 'creates a class with an UUID property defaulting to a random UUID' do
      AttrLess = Class.new UUIDEntity
      AttrLess.new.uuid.must_match(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/)
      AttrLess.new.uuid.wont_equal AttrLess.new.uuid
    end
  end

  describe '#==' do
    it 'reports UUID-based euqality' do
      Actor = Class.new(UUIDEntity) { attribute :name, Symbol }
      Actor.new(name: :laurel).wont_equal Actor.new name: :laurel
      uuid = UUID.new
      Actor.new(name: :laurel, uuid: uuid)
        .must_equal Actor.new name: :hardy, uuid: uuid
    end
  end

  describe '#to_h' do
    it 'serialises the object to a Hash' do
      Hashble = Class.new(UUIDEntity) { attribute :param, Symbol }
      Hashble.new(param: :val).to_h.must_equal param: :val, uuid: any(String)
    end
  end
end end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.2 spec/kamerling/uuid_entity_spec.rb