rails/rails — pull request #16089 by eileencodes (2014-07-07 23:04:49+00:00)
Title: Refactor reflections from sub classes to delegates

This change is the beginning of a larger refactoring to move reflections from sub classes to delegates. Instead of forcing all associations be an `AssociationReflection` and checking the type on the `@macro` instance var we can now have named reflections; `HasManyReflection`, `HasOneReflection`, `BelongsToReflection`, and `HasAndBelongsToManyReflection`. :sweat_smile:

The refactoring also removes the `@collection` instance variable by explicitly setting `collection?` to `false` by default and then setting it to `true` in both HM and HABTM.

Methods shared between `ThroughReflection`, `AssociationReflection`, and `MacroReflection` have been moved to a new `ReflectionMethods` class.

Reflection tests in `activerecord/test/cases/reflection_test.rb` had to be somewhat changed and rewritten since we no longer accept unknown macro types, HABTM isn't used internally, and we now construct the Reflections a little differently.

This does not remove the `@macro` instance var just yet but we are working towards that.

cc/ @tenderlove

(p.s. I can squash just don't like to do it before review :smile_cat:)