drapergem/draper — pull request #384 by tovodeverett (2012-12-13 03:15:31+00:00)
Title: Restore context option.

Restore context option. Collections inherit context by default, but associations can specify either a static context or a lambda. Validation for options in a number of methods.

This is an implementation of the discussion in https://github.com/drapergem/draper/issues/372.

Implementation notes:
* Validation of passed option keys was implemented for a number of methods. I isolated the logic in `Draper.validate_options` and had the files that used that method `require 'draper'`. I'm not sure if this is the best place for it - I looked around for a similar method built into Rails and couldn't find one. I did find a gem that handled this issue, but I didn't want to add another dependency. I decided against writing a test suite for the method itself since each of the individual methods that uses it has their own set of tests for testing that options are validated.
* It appears that the existing code base doesn't prevent the use of `:scope` on a singular association. I'm not sure if we want to change this behavior.
* I had some fun figuring out how to test some of the behavior. When testing that `CollectionDecorator#context=` doesn't enumerate items unnecessarily, I ended up stubbing out `Array#loaded?`. When testing `:scope` in `DecoratedAssociation#decorator_options` I had a lot of trouble trying to figure out how to stub out a fake scope when I realized I could just use `:to_a` as a fake scope that would do nothing. I ended up using `:decorate` for a similar purpose testing the singular association.