All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gems.virtus-1.0.5.spec.integration.extending_objects_spec.rb Maven / Gradle / Ivy

The newest version!
require 'spec_helper'

describe 'I can extend objects' do
  before do
    module Examples
      class User; end

      class Admin; end
    end
  end

  specify 'defining attributes on an object' do
    attributes = { :name => 'John', :age => 29 }

    admin = Examples::Admin.new
    admin.extend(Virtus)

    admin.attribute :name, String
    admin.attribute :age,  Integer

    admin.name = 'John'
    admin.age  = 29

    expect(admin.name).to eql('John')
    expect(admin.age).to eql(29)

    expect(admin.attributes).to eql(attributes)

    new_attributes   = { :name => 'Jane', :age => 28 }
    admin.attributes = new_attributes

    expect(admin.name).to eql('Jane')
    expect(admin.age).to eql(28)
  end
end




© 2015 - 2024 Weber Informatics LLC | Privacy Policy