entity_test.rb
1.09 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "test_helper"
class EntityTest < ActiveSupport::TestCase
def setup
@hash = {:name => 'Carlos', :age => 25,
:brothers => [{:name => 'Saulo', :age => 22}, {:name => 'Isis', :age => 26}]}
@person = Person.create('Carlos', 25)
@person.brothers = [Person.create('Saulo', 22), Person.create('Isis', 26)]
@clone = @person.clone
end
should 'be equal to clone' do
assert_equal @person, @clone
end
should 'be different when field is different' do
@clone.name = 'Other'
assert @person != @clone
end
should 'not throw exception when comparing with incompatible object' do
assert @person != @hash
end
should 'create from hash' do
assert_equal @person, Person.from_hash(@hash)
end
should 'convert to hash' do
assert_equal @hash, @person.to_hash
end
class Person < Kalibro::Entities::Entity
attr_accessor :name, :age, :brothers
def self.create(name, age)
person = Person.new
person.name = name
person.age = age
person
end
def brothers=(value)
@brothers = to_entity_array(value, Person)
end
end
end