Shopify/identity_cache — pull request #55 by dylanahsmith (2013-06-05 22:59:20+00:00)
Title: Remove normalized association from association cache for marshaling.

@camilo for review
cc @boourns & @hornairs

## Problem

has_many associations use a CollectionProxy to act as a lazy loaded array so that it can be used as an array or can be used to build a query. E.g. `record.associated_records # => Array` or `record.associated_records.count # => 2`. This collection proxy will delegate all methods to either the association or to a new scope, including respond_to?.

A normalized has_may association will have the association stored in the association cache, since we cache the associated ids. However, the association will not be loaded, since we don't retrieve the associated records.

When marshal dumping a record with normalized has_many associations, the marshal code will call `respond_to?` on the collection proxy, which will load the association to delegate `respond_to?` to it. This can also corrupt the marshal dump since it will set a new instance variable while dumping the association, so will get interpreted as being outside the objects instance variables.

This was causing the failure when the tests were run in travis, which are reproducible using the same ruby version without performance patches.

## Solution

We don't need the normalized association stored in the cache. We already cache the ids separately from the association in an instance variable, since the association doesn't cache the associated ids. So I removed the cached association from the association cache after using the association.