Commit c4f4aa0
Shayon Mukherjee
Standardize comparison of attribute as string when input is Hash or JSON
Adding `.to_s` properly follows the convention of not initializing `custom_attributes`
or any other attribute which passes the reserve field `type`. Not having `.to_s`, meant
if ApiResource is initialized by `User` or any other class, with a `Hash`, and
the attribute contains the reserved `type` `Hash` attribute, it would incorrectly
try to initialize the same property.
Ex of how it would fail, if `User` class is initialized with custom_attributes that
contains `type`:
```ruby
Intercom::User.new(email: "[email protected]", custom_attributes: {"type"=>"ping"})
=> Intercom::AttributeNotSetError: 'each' called on Intercom::Ping but it has
not been set an attribute or does not exist as a method
...
```
A workaround would be that all keys were passed as strings, however this PR attempts
at standardizing the comparison of any `attribute` always as string, without
being dependent on input type (`Hash` or `JSON`).
I took additional liberty and applied these changes for `type_field?` and
`typed_property?` check for `metadata` attribute as well. `metadata`, because
as per the specs, it can contain the reserved `type` `Hash` as well.
Happy to tweak/modify/close, if the changes raise any concern :).1 parent d96a580 commit c4f4aa0
File tree
2 files changed
+39
-8
lines changed- lib/intercom/traits
- spec/unit/intercom/traits
2 files changed
+39
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
20 | 40 | | |
21 | 41 | | |
22 | 42 | | |
| |||
76 | 96 | | |
77 | 97 | | |
78 | 98 | | |
79 | | - | |
| 99 | + | |
80 | 100 | | |
81 | 101 | | |
82 | 102 | | |
83 | 103 | | |
84 | 104 | | |
85 | 105 | | |
86 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
87 | 118 | | |
88 | 119 | | |
89 | 120 | | |
90 | 121 | | |
91 | | - | |
| 122 | + | |
92 | 123 | | |
93 | 124 | | |
0 commit comments