Sha256: 01524efc6798fba7b831aeff2621e6a6bca7f212a9908a7b825ba19c81e7c103

Contents?: true

Size: 1.13 KB

Versions: 16

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe 'embedded values' do
  before do
    module Examples
      class City
        include Virtus

        attribute :name, String
      end

      class Address
        include Virtus

        attribute :street,  String
        attribute :zipcode, String
        attribute :city,    City
      end

      class User
        include Virtus

        attribute :name,    String
        attribute :address, Address
      end
    end
  end

  subject { Examples::User.new(:name => 'the guy',
                               :address => address_attributes) }
  let(:address_attributes) do
      { :street => 'Street 1/2', :zipcode => '12345', :city => { :name => 'NYC' } }
  end

  specify '#attributes returns instances of the embedded values' do
    subject.attributes.should == {
      :name => 'the guy',
      :address => subject.address
    }
  end

  specify 'allows you to pass a hash for the embedded value' do
    user = Examples::User.new
    user.address = address_attributes
    user.address.street.should == 'Street 1/2'
    user.address.zipcode.should == '12345'
    user.address.city.name.should == 'NYC'
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
virtus-1.0.0.beta5 spec/integration/embedded_value_spec.rb
virtus-1.0.0.beta4 spec/integration/embedded_value_spec.rb
virtus-1.0.0.beta3 spec/integration/embedded_value_spec.rb
virtus-0.5.5 spec/integration/embedded_value_spec.rb
virtus-0.5.4 spec/integration/embedded_value_spec.rb
virtus-0.5.3 spec/integration/embedded_value_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/integration/embedded_value_spec.rb
virtus-0.5.2 spec/integration/embedded_value_spec.rb
virtus-0.5.1 spec/integration/embedded_value_spec.rb
virtus-0.5.0 spec/integration/embedded_value_spec.rb
virtus-0.4.2 spec/integration/embedded_value_spec.rb
virtus-0.4.1 spec/integration/embedded_value_spec.rb
virtus-0.4.0 spec/integration/embedded_value_spec.rb
virtus-0.3.0 spec/integration/embedded_value_spec.rb
virtus-0.2.0 spec/integration/embedded_value_spec.rb
virtus-0.1.0 spec/integration/embedded_value_spec.rb