112
112
it 'an initialized ApiResource is equal to one generated from a response' do
113
113
class ConcreteApiResource ; include Intercom ::Traits ::ApiResource ; end
114
114
initialized_api_resource = ConcreteApiResource . new ( object_json )
115
- except ( object_json , 'type' , 'nested_fields' ) . keys . each do |attribute |
115
+ except ( object_json , 'type' ) . keys . each do |attribute |
116
116
assert_equal initialized_api_resource . send ( attribute ) , api_resource . send ( attribute )
117
117
end
118
118
end
@@ -122,11 +122,33 @@ class ConcreteApiResource; include Intercom::Traits::ApiResource; end
122
122
123
123
api_resource . from_hash ( object_hash )
124
124
initialized_api_resource = ConcreteApiResource . new ( object_hash )
125
- except ( object_json , 'type' , 'nested_fields' ) . keys . each do |attribute |
125
+ except ( object_json , 'type' ) . keys . each do |attribute |
126
126
assert_equal initialized_api_resource . send ( attribute ) , api_resource . send ( attribute )
127
127
end
128
128
end
129
129
130
+ describe 'correctly equates two resources' do
131
+ class DummyResource ; include Intercom ::Traits ::ApiResource ; end
132
+
133
+ specify 'if each resource has the same class and same value' do
134
+ api_resource1 = DummyResource . new ( object_json )
135
+ api_resource2 = DummyResource . new ( object_json )
136
+ assert_equal ( api_resource1 == api_resource2 ) , true
137
+ end
138
+
139
+ specify 'if each resource has the same class and different value' do
140
+ object2_json = object_json . merge ( 'id' => 'bbbbbb' )
141
+ api_resource1 = DummyResource . new ( object_json )
142
+ api_resource2 = DummyResource . new ( object2_json )
143
+ assert_equal ( api_resource1 == api_resource2 ) , false
144
+ end
145
+
146
+ specify 'if each resource has a different class' do
147
+ dummy_resource = DummyResource . new ( object_json )
148
+ assert_equal ( dummy_resource == api_resource ) , false
149
+ end
150
+ end
151
+
130
152
it 'correctly generates submittable hash when no updates' do
131
153
assert_equal api_resource . to_submittable_hash , { }
132
154
end
0 commit comments