Sha256: 38cdd2d9459bac5e60f16dcafe40a1374429c5f68a5fa7c1f625b2bdcfab3c9f

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

require "spec_helper"
require "shamu/entities"


describe Shamu::Entities::Entity do
  let( :klass ) do
    Class.new( Shamu::Entities::Entity ) do
      model :user
      attribute :name, on: :user
      attribute :email, on: :user
    end
  end

  describe "#to_attributes" do
    let( :user )     { OpenStruct.new( name: "Heisenberg", email: "blue@rock.com" ) }
    let( :instance ) { klass.new( user: user ) }

    it "does not include model attributes" do
      expect( instance.to_attributes ).not_to have_key :user
    end
  end

  {
    "SetEntity"                     => "Set",
    "Set"                           => "Set",
    "Domain::SetEntity"             => "Domain::Set",
    "Domain::SubDomain::SetEntity"  => "Domain::SubDomain::Set",
    "Domain::SubDomain::SetsEntity" => "Domain::SubDomain::Set",
  }.each do |full_name, expected|

    it "maps #{ full_name } to #{ expected }" do
      klass = Class.new( Shamu::Entities::Entity )
      klass.define_singleton_method :name do
        full_name
      end

      expect( klass.model_name.name ).to eq expected
    end
  end

  describe ".null_entity" do
    it "defines a NullEntity class" do
      expect( klass.null_entity ).to be < Shamu::Entities::NullEntity
    end

    it "overrides attributes with default values" do
      klass.null_entity do
        attribute :name do
          "Unknown"
        end
      end

      expect( klass.null_entity.new.name ).to eq "Unknown"
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shamu-0.0.18 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.17 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.15 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.14 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.13 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.11 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.9 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.8 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.7 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.5 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.4 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.3 spec/lib/shamu/entities/entity_spec.rb
shamu-0.0.2 spec/lib/shamu/entities/entity_spec.rb