This project is archived and is in readonly mode.

#5139 ✓stale
David Chelimsky

Remove !new_record? requirement from ActiveRecord::Base#==

Reported by David Chelimsky | July 17th, 2010 @ 02:36 PM

class Thing < ActiveRecord::Base; end

assert_equal Thing.new, Thing.new

# fails with 
#   <#<Thing id: nil, created_at: nil, updated_at: nil>> expected but was
#   <#<Thing id: nil, created_at: nil, updated_at: nil>>.

This fails because AR::Base includes !comparison_object.new_record? in its definition of ==(comparison_object): http://github.com/rails/rails/blob/c6e20586372743ce200449bf0ac21aed...

This often leads to confusion when trying to test things that involve new records. I brought this up with Jeremy a year or two ago and if memory serves he agreed that removing that requirement would make testing easier but that there were reasons not to do so.

One was the notion of entity, and the idea that an identity-less object is not an entity (although, ironically, if you remove the "id" from "identity", you're left with "entity" :) )

The more pragmatic argument was that if new records were considered equivalent (assuming the other attributes were equal), it would be hard to know how this would impact code in the wild.

I'm bringing this up now in the hopes that we can have a brief discussion of this again before Rails 3 is released. This is the perfect opportunity to take the risk, as all eyes are on upgrade process and documentation.

Thoughts?

Comments and changes to this ticket

  • David Chelimsky

    David Chelimsky July 17th, 2010 @ 02:37 PM

    • Assigned user set to “Jeremy Kemper”
  • David Chelimsky

    David Chelimsky July 17th, 2010 @ 02:37 PM

    • Assigned user changed from “Jeremy Kemper” to “Yehuda Katz (wycats)”
  • David Chelimsky

    David Chelimsky July 17th, 2010 @ 02:37 PM

    • Assigned user changed from “Yehuda Katz (wycats)” to “José Valim”
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:35 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:35 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages