Shopify/identity_cache — pull request #120 by dylanahsmith (2014-02-18 21:26:56+00:00)
Title: Fix cache key to not change when adding a non-embedded association.

@fbogsany & @arthurnn for review
cc @jahfer, @byroot

## Problem

The IdentityCache::ClassMethods.rails_cache_key_prefix is meant to change when columns for a cached model or its embedded associations change. This should allow us to add embedded associations and not use cache keys without those embedded associations. However, we were treating non-embedded has_many associations as if they were embedded when generating the cache key prefix, so we would use the same cache key after changing a non-embedded cached association to an embedded cached association. This would result in the following error from using the old cached data:

```
NameError: `@' is not allowed as an instance variable name
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:109:in `instance_variable_set'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:109:in `block in record_from_coder'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:109:in `each'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:109:in `record_from_coder'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:38:in `block in fetch_by_id'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:164:in `require_if_necessary'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:35:in `fetch_by_id'
/Users/dylansmith/src/identity_cache/lib/identity_cache/query_api.rb:52:in `fetch'
```

## Solution

Fix the cache prefix so that it uses the right list of associations as embedded associations.

A regression test was added which was used to generate the above exception without the fix.