I was working on another branch and as part of my commit, Rubocop
removed a validation (but not the spec that asserted the validation).
Below is the "non-updating" rubocop offense on the other branch.
```shell
❯ rubocop ./app/models/notification_subscription.rb
Inspecting 1 file
C
Offenses:
app/models/notification_subscription.rb:13:29: C: [Correctable]
Rails/RedundantPresenceValidationOnBelongsTo: Remove explicit presence
validation for notifiable_id.
validates :notifiable_id, presence: true
^^^^^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense auto-correctable
```
To remediate, I ran:
```shell
> rubocop --only "Rails/RedundantPresenceValidationOnBelongsTo" \
--auto-correct
```
This resolved the `app/models`. Then did some regex magic and removed
the assertions from `spec/models`.
For Forem folks, I wrote a [forem.team post][1] discuss if this is how
we want to proceed.
[1]:https://forem.team/jeremy/rubocop-auto-updating-mayhem-33a6
27 lines
1 KiB
Ruby
27 lines
1 KiB
Ruby
# @note When we destroy the related user, it's using dependent:
|
|
# :delete for the relationship. That means no before/after
|
|
# destroy callbacks will be called on this object.
|
|
#
|
|
# @note When we destroy the related article, it's using dependent:
|
|
# :delete for the relationship. That means no before/after
|
|
# destroy callbacks will be called on this object.
|
|
class NotificationSubscription < ApplicationRecord
|
|
belongs_to :notifiable, polymorphic: true
|
|
belongs_to :user
|
|
|
|
validates :config, presence: true, inclusion: { in: %w[all_comments top_level_comments only_author_comments] }
|
|
validates :notifiable_type, presence: true, inclusion: { in: %w[Comment Article] }
|
|
validates :user_id, uniqueness: { scope: %i[notifiable_type notifiable_id] }
|
|
|
|
class << self
|
|
# @param notifiable [Comment, Article]
|
|
#
|
|
# @see notifiable_type's validation
|
|
def update_notification_subscriptions(notifiable)
|
|
NotificationSubscriptions::UpdateWorker.perform_async(
|
|
notifiable.id,
|
|
notifiable.class.name,
|
|
)
|
|
end
|
|
end
|
|
end
|