Commit Graph

12 Commits

Author SHA1 Message Date
Elliot Winkler 47f47d0d7a Improve failure message for enum matcher
When the enum matcher fails, the message it generates is not as clear as
it could be, particularly around showing the expected enum values versus
the actual ones. This commit expands the failure message to be more
helpful (and ensures that the description of the matcher is kept
compact).
2019-06-09 02:16:18 -06:00
Elliot Winkler 147ac482e8 Add with_prefix and with_suffix to define_enum_for
In Rails 5, the `enum` macro received two new options: `_prefix` and
`_suffix`. These options change the names of the methods that are
generated from the given enum values. This commit adds qualifiers to the
`define_enum_for` matcher so that they can be tested.
2018-01-28 00:47:56 -06:00
Elliot Winkler d8681fa721 Improve failure messages for define_enum_for
If a subtest fails, explain why. We're going to be adding another
subtest later, and so without this extra information, users will most
definitely be confused.
2018-01-28 00:47:44 -06:00
Elliot Winkler a05ad14fbc Deprecate `with` on `define_enum_for` in favor of `with_values`
We'll need to introduce some other `with_*` qualifiers and it won't look
right to have one qualifier called `with` and other qualifiers called
`with_something_else`.
2018-01-28 00:28:40 -06:00
Elliot Winkler b1e11fb69a Remove active_record_supports_enum? helper
The `enum` macro was introduced in Rails 4.1, which shoulda-matchers no
longer supports, so we can always assume that enum is available.
2018-01-28 00:28:39 -06:00
Elliot Winkler 6bd3fcf24a Restyle spec file for define_enum_for
* Break up long test names into contexts
* Make tests more isolated by reducing "global" scope (always use
  keyword argument to specify attribute name instead of a "global"
  method)
* Simplify how failure messages are tested by removing interpolation in
  favor of explicitness
2018-01-28 00:28:22 -06:00
Emil Sågfors 5650aae35d Allow specifying a non-integer column type for define_enum_for 2018-01-23 23:03:10 -06:00
Geoff Harcourt 68dd70a23d Validate enum column is an integer in `define_enum_for`
If your ActiveRecord model stores its `enum` data in a non-integer
column, ActiveRecord will save the data without error. However, when you
access the attribute on the record after saving, AR will look for the
string to what it expects to be a list of numbers and return `nil`
rather than the mapped value.

This change adds a third criterion to the `define_enum_for` matcher,
verifying that the underlying database column has a `sql_type` of
`"integer"`.

Fix #827.
2016-01-10 21:40:15 -07:00
Guilherme Franco 714129b82f Fix enum attribute name verification
Fix `define_enum_for` so that it actually tests that the attribute is
present in the list of defined enums, as you could fool it by merely
defining a class method that was the pluralized version of the attribute
name. In the same vein, passing a pluralized version of the attribute
name to `define_enum_for` would erroneously pass, and now it fails.
2015-02-12 18:04:51 -07:00
Elliot Winkler d86fe2d1c0 Fix test suite to properly tag example groups
When running unit tests we need to ensure that we are simulating how
other people will use the matchers as best we can. This means, for
instance, tagging any example groups that test controller matchers as
controller example groups.
2014-12-25 00:44:53 -05:00
Elliot Winkler f922613386 Reorganize unit tests, part II
* Change 'spec' Rake task to 'spec:unit'
* Require unit_spec_helper.rb in unit tests, not spec_helper.rb
* Re-namespace files in spec/support/unit under UnitTests
* Files in spec/support/unit/helpers no longer automatically add
  themselves to RSpec - this happens in unit_spec_helper.rb
* Extract RecordWithDifferentErrorAttributeBuilder and
  RecordValidatingConfirmationBuilder to separate files
2014-11-05 09:53:20 -07:00
Elliot Winkler bbdf8a807e Reorganize unit tests, part I
* Move spec/shoulda to spec/unit_tests/shoulda
* Move spec/support/*.rb to spec/support/unit_tests/{helpers,matchers}
* Move spec_helper.rb to unit_spec_helper.rb
2014-11-04 14:43:59 -07:00