17
17
'metadata' => {
18
18
'type' => 'user' ,
19
19
'color' => 'cyan'
20
- } }
20
+ } ,
21
+ 'nested_fields' => {
22
+ 'type' => 'nested_fields_content' ,
23
+ 'field_1' => {
24
+ 'type' => 'field_content' ,
25
+ 'name' => 'Nested Field'
26
+ }
27
+ }
28
+ }
21
29
end
22
30
23
31
let ( :object_hash ) do
35
43
metadata : {
36
44
type : 'user' ,
37
45
color : 'cyan'
46
+ } ,
47
+ nested_fields : {
48
+ type : 'nested_fields_content' ,
49
+ field_1 : {
50
+ type : 'field_content' ,
51
+ name : 'Nested Field'
52
+ }
38
53
}
39
54
}
40
55
end
97
112
it 'an initialized ApiResource is equal to one generated from a response' do
98
113
class ConcreteApiResource ; include Intercom ::Traits ::ApiResource ; end
99
114
initialized_api_resource = ConcreteApiResource . new ( object_json )
100
- except ( object_json , 'type' ) . keys . each do |attribute |
115
+ except ( object_json , 'type' , 'nested_fields' ) . keys . each do |attribute |
101
116
assert_equal initialized_api_resource . send ( attribute ) , api_resource . send ( attribute )
102
117
end
103
118
end
@@ -107,12 +122,28 @@ class ConcreteApiResource; include Intercom::Traits::ApiResource; end
107
122
108
123
api_resource . from_hash ( object_hash )
109
124
initialized_api_resource = ConcreteApiResource . new ( object_hash )
110
-
111
- except ( object_json , 'type' ) . keys . each do |attribute |
125
+ except ( object_json , 'type' , 'nested_fields' ) . keys . each do |attribute |
112
126
assert_equal initialized_api_resource . send ( attribute ) , api_resource . send ( attribute )
113
127
end
114
128
end
115
129
130
+ it 'correctly generates submittable hash when no updates' do
131
+ assert_equal api_resource . to_submittable_hash , { }
132
+ end
133
+
134
+ it 'correctly generates submittable hash when there are updates' do
135
+ api_resource . name = 'SuperSuite updated'
136
+ api_resource . nested_fields . field_1 . name = 'Updated Name'
137
+ assert_equal api_resource . to_submittable_hash , {
138
+ 'name' => 'SuperSuite updated' ,
139
+ 'nested_fields' => {
140
+ 'field_1' => {
141
+ 'name' => 'Updated Name'
142
+ }
143
+ }
144
+ }
145
+ end
146
+
116
147
def except ( h , *keys )
117
148
keys . each { |key | h . delete ( key ) }
118
149
h
0 commit comments