2010-12-15 22:34:19 +00:00
|
|
|
require 'shoulda/matchers/active_record/association_matcher'
|
2013-06-19 23:52:46 +00:00
|
|
|
require 'shoulda/matchers/active_record/association_matchers/counter_cache_matcher'
|
2013-06-07 14:14:27 +00:00
|
|
|
require 'shoulda/matchers/active_record/association_matchers/order_matcher'
|
|
|
|
require 'shoulda/matchers/active_record/association_matchers/through_matcher'
|
|
|
|
require 'shoulda/matchers/active_record/association_matchers/dependent_matcher'
|
|
|
|
require 'shoulda/matchers/active_record/association_matchers/model_reflector'
|
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 21:38:10 +00:00
|
|
|
require 'shoulda/matchers/active_record/association_matchers/option_verifier'
|
2010-12-15 22:34:19 +00:00
|
|
|
require 'shoulda/matchers/active_record/have_db_column_matcher'
|
|
|
|
require 'shoulda/matchers/active_record/have_db_index_matcher'
|
|
|
|
require 'shoulda/matchers/active_record/have_readonly_attribute_matcher'
|
2011-11-15 22:11:41 +00:00
|
|
|
require 'shoulda/matchers/active_record/serialize_matcher'
|
2012-04-11 18:33:21 +00:00
|
|
|
require 'shoulda/matchers/active_record/accept_nested_attributes_for_matcher'
|
2010-12-15 22:34:19 +00:00
|
|
|
|
|
|
|
module Shoulda
|
|
|
|
module Matchers
|
|
|
|
# = Matchers for your active record models
|
|
|
|
#
|
2011-05-06 11:51:12 +00:00
|
|
|
# These matchers will test the associations for your
|
2010-12-15 22:34:19 +00:00
|
|
|
# ActiveRecord models.
|
|
|
|
#
|
|
|
|
# describe User do
|
|
|
|
# it { should have_one(:profile) }
|
|
|
|
# it { should have_many(:dogs) }
|
|
|
|
# it { should have_many(:messes).through(:dogs) }
|
|
|
|
# it { should belong_to(:lover) }
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
module ActiveRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|