RubyMoney/money-rails — pull request #256 by georgemillo (2014-12-19 01:07:21+00:00)
Title: Improvements to `monetize` test matcher.

Improvement over my other PR #255 - see the description there.

Basically, this allows the `monetize` matcher to be used with the ActiveRecord class itself as the subject, as well as an instance of that class.

E.g., assuming the AR class is called `Project` and has a monetized attribute called `price_cents`:

describe Product do
let(:product) { Product.new(price_cents: whatever) }

# This is the old way of doing it.
it { expect(product).to monetize(:price_cents) }

# "Product" as implicit subject. This previously didn't work; the PR makes it work.
it { is_expected.to monetize(:price_cents) }
end

This feels more intuitive to me, and it's how shoulda-matchers does it.

On top of that, these changes mean that, even if you *do* test against an instance of Product, it doesn't matter
what the value of the attribute is at runtime. Previously, the first example above might not pass depending on the specific value of `whatever`... which doesn't make sense because the attribute *is* monetized ("monetize :price_cents" is called within the class definition) so the spec should pass regardless of the specifics of any particular instance.