Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#5139
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?

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

State: stale
Milestone: none
Assigned to: José Valim José Valim
Importance: none

Activity

  1. David Chelimsky
    David Chelimsky
    • Assigned user set to Jeremy Kemper

    July 17th, 2010 @ 02:37 PM

  2. David Chelimsky
    David Chelimsky
    • Assigned user changed from Jeremy Kemper to Yehuda Katz (wycats)

    July 17th, 2010 @ 02:37 PM

  3. David Chelimsky
    David Chelimsky
    • Assigned user changed from Yehuda Katz (wycats) to José Valim

    July 17th, 2010 @ 02:37 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:35 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:35 PM