Commit Graph

14 Commits

Author SHA1 Message Date
Jacob Morris 0695c8647b Check correct columns are present in join table
The `have_and_belong_to_many` matcher could give a false positive if the
join table is present but does not contain the correct columns. Check to
see if the columns exist in the join table and provide a meaningful
failure message if one or more of the columns are not present.
2014-07-21 00:08:42 -06:00
Elliot Winkler c22d7c89e0 Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
PikachuEXE 31a0913d7f + Add inverse of matcher for active record association 2014-04-04 11:15:55 -06:00
Luciano Sousa 803c06b0b0 Association matchers now support :source option 2013-12-01 15:12:49 -05:00
Elliot Winkler c6e1f86fa6 Fix converting association options to a Relation
Under Rails 3 when using an association matcher in conjunction with a
submatcher such as #order, we have to take the options on the
association (:conditions, :order, etc.) and convert them to an
ActiveRecord::Relation object. This happens in ModelReflector.

Unfortunately, converting an :includes option was broken. This is in
part due to ModelReflector not having proper tests, but also, the method
that does the conversion to Relation is rather complex and could be
broken up so it can be tested better. In fact I noticed that there's a
lot of stuff in ModelReflector that does stuff around a Reflection
object, so it would be better to define a ModelReflection class that
simply decorates a Reflection. That's what I've done and also added
proper tests.
2013-11-01 09:41:32 -06:00
Elliot Winkler 55f45d9549 Refactor AssociationMatcher to use new OptionVerifier
When using an association matcher you may have qualifiers on that
matcher which let you make assertions on options passed to the
association method that you are testing. For instance, has_many has a
:dependent option and so in order to test this you say something like

    it { should have_many(:people).dependent(:destroy) }

In order to test such an option we have to compare the option you passed
with what the actual value of that option is. This is usually obtained
by looking at the reflection object of the association in question,
although it can be obtained by other means too.

Anyway, the code that does this comparison isn't terrible, but there are
two problems with it. First, it involves typecasting both expected and
actual values. For instance, this:

    has_many :people, dependent: :destroy
    it { should have_many(:people).dependent(:destroy) }

should be equivalent to:

    has_many :people, dependent: :destroy
    it { should have_many(:people).dependent('destroy') }

should be equivalent to:

    has_many :people, dependent: 'destroy'
    it { should have_many(:people).dependent(:destroy) }

Second, we are a little screwed if the method of obtaining the actual
value of the option changes depending on which Rails version you're
using.

So, OptionVerifier attempts to address both of these issues. It's a
little crazy, but it works.

I also moved some methods from AssociationMatcher to ModelReflector
where they really belong.
2013-08-16 16:00:17 -06:00
Fabio Rehm 3f7c440851 Add support for counter_cache option in belongs_to associations 2013-06-21 10:53:30 -04:00
Melissa Xie 964dcfe655 Extract submatchers from AssociationMatcher
Refactored AssociationMatcher so that `#order`, `#through`, and `#dependent`
would be their own submatchers. This reduces some of the clutter in the main class,
especially as we continue expanding it. In addition, a few related tests were
modified so that they would check failure messages also.
2013-06-14 13:44:37 -04:00
Melissa Xie c4413a4aca Remove 'query_the_database' matcher
* See issue #252
2013-04-03 13:08:27 -04:00
Brendan Loudermilk ee7422280d Adds accept_nested_attributes_for matcher
Currently supports the options "allow_destroy", "limit", and
"update_only"
2012-04-13 10:38:38 -04:00
Matthew Daubert 00a9a68fb1 Added QueryTheDatabaseMatcher
This matcher allows you to spec the number of database calls made by a
method.
2012-03-23 09:23:32 -04:00
Tom Milewski a3fa2f9bac Adds the serialize matcher to ActiveRecord matchers. 2011-11-15 17:11:41 -05:00
Markus Schwed 2a54fdb28d Seperate ActiveRecord and ActiveModel related matchers 2011-05-06 15:56:36 +02:00
Joe Ferris 56b0a0439e Move into the Matchers namespace 2010-12-15 17:34:19 -05:00