Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2089

Allow the IdentityMap to get objects by the String representation of Moped::BSON::ObjectId.

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      This pull requests makes Mongoid::IdentityMap.get(Person, person.id.to_s) equivalent to Mongoid::IdentityMap.get(Person, person.id).

      The motivation behind this pull request was that in upgrading to Mongoid 3, not having this broke some of my controller tests that had expectations on an object. Here's a trivial example.

      # Say there's some method we want to ensure gets called when it is edited
      person = FlightPassenger.create
      person.should_receive(:check_name_against_terrorist_database)
      post(:edit, {:flight_passenger => {:id => person.id, :first_name => "Jon"}, :format => :json}
      

      In the controller action, the id would come through as a String. Because the IdentityMap would not be used, the object returned in the action would not have the same memory address as person, so the mock expectation would fail.

            Assignee:
            durran Durran Jordan
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: