-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tiny confusing behavior when creating a new instance from another instance #234
Comments
The object equality in You could even change a property on one of them, then change it back to the same value and they would be considered equal again. This is by design, so that part is ok 🙂 The second case you point out, where one has been coerced into a string while the other is still an integer, is also expected behavior. The raw input is whatever you give We could fix this by checking the final new instance that we create ( |
@d-Pixie Thanks for the clarification! 👍 Yes, it was more of an observation. 😄 My main point was just that the behavior is not obvious if you don't read the code carefully. And if you don't, that might give you unexpected results when you later use the returned instance from For example, this might surprise someone (in the first example, we compare invoice1 = Fortnox::API::Model::Invoice.new(customer_number: 1, due_date: '2023-01-01')
invoice2 = Fortnox::API::Repository::Invoice.new.save(invoice1)
invoice3 = invoice2.update(due_date: '2023-01-01')
puts invoice3.saved? # false
invoice1 = Fortnox::API::Model::Invoice.new(customer_number: 1, city: 'Stockholm')
invoice2 = Fortnox::API::Repository::Invoice.new.save(invoice1)
invoice3 = invoice2.update(city: 'Stockholm')
puts invoice3.saved? # true |
This is a little bit confusing:
I guess this is because how the update method works:
Here,
customer_number
has been converted to aString
inold_attributes
via it's type (Types::Sized::String[1024]
) butcustomer_number
inhash
has the raw value (Integer
).The text was updated successfully, but these errors were encountered: