Skip to content

Commit

Permalink
Add create_or_find_by to save_bang.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeLaurenty authored and Maxime Laurenty committed Aug 8, 2019
1 parent 20de97e commit 2279600
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@
### Changes

* [#98](https://github.com/rubocop-hq/rubocop-rails/pull/98): Mark `Rails/ActiveRecordAliases` as `SafeAutoCorrect` false and disable autocorrect by default. ([@prathamesh-sonpatki][])
* [#102](https://github.com/rubocop-hq/rubocop-rails/pull/102): Include `create_or_find_by` in `Rails/SaveBang` cop. ([@MaximeLaurenty][])
* [#101](https://github.com/rubocop-hq/rubocop-rails/pull/101): Mark `Rails/SaveBang` as `SafeAutoCorrect` false and disable autocorrect by default. ([@prathamesh-sonpatki][])

## 2.2.1 (2019-07-13)

Expand Down Expand Up @@ -59,3 +61,4 @@
[@brunvez]: https://github.com/brunvez
[@santib]: https://github.com/santib
[@prathamesh-sonpatki]: https://github.com/prathamesh-sonpatki
[@MaximeLaurenty]: https://github.com/MaximeLaurenty
1 change: 1 addition & 0 deletions config/default.yml
Expand Up @@ -404,6 +404,7 @@ Rails/SaveBang:
VersionChanged: '0.59'
AllowImplicitReturn: true
AllowedReceivers: []
SafeAutoCorrect: false

Rails/ScopeArgs:
Description: 'Checks the arguments of ActiveRecord scopes.'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/save_bang.rb
Expand Up @@ -108,7 +108,7 @@ class SaveBang < Cop
CREATE_CONDITIONAL_MSG = '`%<current>s` returns a model which is ' \
'always truthy.'

CREATE_PERSIST_METHODS = %i[create
CREATE_PERSIST_METHODS = %i[create create_or_find_by
first_or_create find_or_create_by].freeze
MODIFY_PERSIST_METHODS = %i[save
update update_attributes destroy].freeze
Expand Down
2 changes: 1 addition & 1 deletion manual/cops_rails.md
Expand Up @@ -2064,7 +2064,7 @@ ConvertTry | `false` | Boolean

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Disabled | Yes | Yes | 0.42 | 0.59
Disabled | Yes | Yes (Unsafe) | 0.42 | 0.59

This cop identifies possible cases where Active Record save! or related
should be used instead of save because the model might have failed to
Expand Down

0 comments on commit 2279600

Please sign in to comment.