@@ -25,30 +25,36 @@ class Person
2525
2626describe ShallowAttributes do
2727 describe 'with custom types' do
28- it 'allows embedded values' do
29- person = Person . new ( address : {
28+ let ( :person ) do
29+ Person . new ( address : {
3030 street : 'Street 1/2' , city : {
3131 name : 'NYC'
3232 }
3333 } )
34+ end
3435
35- person . address . zipcode . must_equal "111111"
36- person . address . street . must_equal "Street 1/2"
36+ it 'allows embedded values' do
37+ person . address . zipcode . must_equal '111111'
38+ person . address . street . must_equal 'Street 1/2'
3739 person . address . city . size . must_equal 9000
38- person . address . city . name . must_equal " NYC"
40+ person . address . city . name . must_equal ' NYC'
3941 end
4042
4143 it 'returns normal hash' do
42- person = Person . new ( address : {
43- street : 'Street 1/2' , city : {
44- name : 'NYC'
45- }
46- } )
47-
48- person . address . zipcode . must_equal "111111"
49- person . address . street . must_equal "Street 1/2"
44+ person . address . zipcode . must_equal '111111'
45+ person . address . street . must_equal 'Street 1/2'
5046 person . address . city . size . must_equal 9000
51- person . address . city . name . must_equal "NYC"
47+ person . address . city . name . must_equal 'NYC'
48+ end
49+
50+ it 'builds the custom types with the correct class' do
51+ person . address . must_be_instance_of Address
52+ person . address . city . must_be_instance_of City
53+ end
54+
55+ it 'does not change the attribute type after call the method #attributes' do
56+ person . attributes
57+ person . address . must_be_instance_of Address
5258 end
5359
5460 describe 'when one of attribute is array' do
@@ -89,6 +95,16 @@ class Person
8995 person . addresses [ 1 ] . city . name . must_equal 'Spb'
9096 end
9197
98+ it 'builds the custom types with the correct class' do
99+ person . addresses [ 0 ] . must_be_instance_of Address
100+ person . addresses [ 0 ] . city . must_be_instance_of City
101+ end
102+
103+ it 'does not change the attribute type after call the method #attributes' do
104+ person . attributes
105+ person . addresses [ 0 ] . must_be_instance_of Address
106+ end
107+
92108 describe '#attributes' do
93109 it 'returns attributes hash' do
94110 hash = person . attributes
0 commit comments