1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
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
|