File: extending_objects_spec.rb

package info (click to toggle)
ruby-virtus 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: ruby: 4,378; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (3)
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