Skip to content

Tiny confusing behavior when creating a new instance from another instance #234

@marcus-allabrf

Description

@marcus-allabrf

This is a little bit confusing:

invoice1 = Fortnox::API::Model::Invoice.new(customer_number: 1)
invoice2 = invoice1.update(customer_number: '1')

puts invoice1 == invoice2 # true
puts invoice1.object_id == invoice2.object_id # true

invoice1 = Fortnox::API::Model::Invoice.new(customer_number: 1)
invoice2 = invoice1.update(customer_number: 1)

puts invoice1 == invoice2 # true
puts invoice1.object_id == invoice2.object_id # false (!)

I guess this is because how the update method works:

  def update(hash)
    old_attributes = to_hash
    new_attributes = old_attributes.merge(hash)

Here, customer_number has been converted to a String in old_attributes via it's type (Types::Sized::String[1024]) but customer_number in hash has the raw value (Integer).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions