1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
Commit graph

26 commits

Author SHA1 Message Date
Kapil Sachdev
97722f67cb fix(rubocop): Satisfy Style/StringLiterals with single_quotes [ci skip] 2020-11-03 10:05:25 -07:00
Pedro Paiva
7d098c92f2 Revert "Use autoloading instead of requiring all files up front"
This reverts commit ce78101362.
2020-08-26 10:52:54 -06:00
Pedro Paiva
ce78101362 Use autoloading instead of requiring all files up front 2020-08-24 21:47:12 -06:00
Stef Schenkelaars
e4a268b5b4 Add have_attached matcher for ActiveStorage (#1102) 2020-07-24 09:34:25 -06:00
Yuriy Orlov
f82329a679 Add have_implicit_order_column matcher
Add a matcher that can test the new [implicit_order_column][1] class
property that is available on ActiveRecord classes in Rails 6.

[1]: https://github.com/rails/rails/pull/34480

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
2020-07-12 00:51:17 -06:00
Pedro Paiva
0b23942feb Add have_rich_text_matcher
The `have_rich_text` matcher tests usage of the `has_rich_text` macro that was added in Rails 6.
2020-01-23 09:29:57 -07:00
Elliot Winkler
00a84c0bfe Update documentation
[ci skip]
2019-02-16 03:01:35 -07:00
Gui Albuk
0d81aa6716 Merge pull request #1058 from thoughtbot/add-optional-and-required
Add required/optional qual's to belongs_to/has_one
2017-10-18 20:26:46 -02:00
Faraz Yashar
bf38660507 Add matcher for has_secure_token 2017-10-15 21:07:58 -04:00
Elliot Winkler
3af3d9f7ab Add required/optional qual's to belongs_to/has_one
Rails 5 made two changes to `belongs_to` associations:

* `required` and `optional` were added as options (which add and remove
  a presence validation on the association, respectively)
* `required` was made the default

In addition, a `required` option was also added to `has_one`.

These new qualifiers allow us to test these options appropriately.

Credit: Shia <rise.shia@gmail.com>
2017-10-06 23:38:47 -05:00
Elliot Winkler
cf76d747ee Move uniqueness validation to ActiveRecord module 2014-12-13 17:53:16 -05:00
Mauro George
eaa970e3c6 Create the define_enum_for matcher 2014-08-26 14:44:27 -06:00
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