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 8665d4e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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][])
* [#101](https://github.com/rubocop-hq/rubocop-rails/pull/101): Mark `Rails/SaveBang` 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][])

## 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 8665d4e

Please sign in to comment.