Commit Graph

18 Commits

Author SHA1 Message Date
John DeWyze 38db235515
Add `without_scopes` to enum matcher. (#1453)
Rails 6 added the `_scopes: false` option when defining enums. This will
prevent rails from creating class scopes for each of the values.

Previously, shoulda-matchers checked for the presence of singleton
methods as a way to check that the corresponding enum methods have been
defined. In rails 6, if someone were using `_scopes: false` the matcher
will fail.

Instead, we should check on the presence of the instance methods that
are generated: `#{value}!` and `#{value}?` as the default checker for
the enum values generating methods.

We can then check on the scopes/singleton methods generated when using
the new `without_scopes` matcher.
2022-01-31 20:26:50 -03:00
Bruno Castro c969f1d52f
feat: support alias in matcher define_enum (#1419) 2021-03-04 15:46:23 -07:00
Kapil Sachdev b7e02184d9 fix(rubocop): Fix Layout/LineLength
- bump rubocop to v1.0
- Fix Layout/MultilineAssignmentLayout and other remaining offences
- Exculde appraisal generated gemfiles in rubocop
- Replace NON_NUMERIC_VALUE constant with instance method against 
failing test case in  rails <= 5.1 and postgres adapter.
This is a defect in rails where a frozen string is modified in 
https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb#L25
2020-11-03 10:05:25 -07:00
Kapil Sachdev ee1008de7a fix(rubocop): Fix Layout related offenses [ci skip]
- Layout/EmptyLines
- Layout/EmptyLineAfterGuardClause
- Layout/TrailingEmptyLines
- Layout/EmptyLinesAroundBlockBody
- Layout/EmptyLinesAroundModuleBody
- Layout/EmptyLineAfterMagicComment
- Layout/SpaceInsidePercentLiteralDelimiters
- Layout/SpaceAroundEqualsInParameterDefault
- Layout/SpaceInsideArrayLiteralBrackets
- Layout/LeadingCommentSpace
- Layout/SpaceBeforeComment
- Layout/SpaceAroundOperators
- Layout/SpaceInsideRangeLiteral
- Layout/SpaceInsideReferenceBrackets
- Layout/SpaceInLambdaLiteral
- Layout/SpaceAfterComma
- Layout/SpaceInsideHashLiteralBraces
- Layout/TrailingWhitespace
- Layout/ArgumentAlignment
- Layout/HashAlignment
- Layout/DotPosition
- Layout/IndentationWidth
- Layout/EndAlignment
- Layout/MultilineOperationIndentation
- Layout/IndentationConsistency
- Layout/ClosingHeredocIndentation
- Layout/MultilineMethodCallBrace- Layout
- Layout/ClosingParenthesisIndentation
2020-11-03 10:05:25 -07:00
kutomore c47e6db739 Adding comment on define_enum_for_matcher.rb
[ci skip]
2019-06-09 13:54:18 -06:00
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 f55e38cf76 Update documentation for define_enum_for
[ci skip]
2018-01-23 23:12:42 -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
Jeroen Visser e6bc6d99e9 Correct typo in docs
A leftover `end` was left from the boilerplate.
2016-09-11 12:06:22 -06:00
Elliot Winkler afa6a7b666 Update RSpec test style across docs
Instead of using

    describe Foo do
      # ...
    end

use

    RSpec.describe Foo, type: :model do
      # ...
    end

instead. This is not exactly official, as the former style still works,
but the latter style is highly suggested in RSpec documentation and the
like, so this is what people are used to.

[ci skip]
2016-06-15 18:02:07 -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
Elliot Winkler 142366ef16 Refer to Minitest in docs over Test::Unit
Minitest has been used instead of Test::Unit for quite some time now,
let's get with the times.

[ci skip]
2015-09-30 13:18:23 -06: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 f26ce1922f Add documentation, news for define_enum_for 2014-08-28 10:55:52 -06:00
Mauro George eaa970e3c6 Create the define_enum_for matcher 2014-08-26 14:44:27 -06:00