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
50 lines
1.9 KiB
Ruby
50 lines
1.9 KiB
Ruby
module Users
|
|
# @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.
|
|
class Setting < ApplicationRecord
|
|
self.table_name_prefix = "users_"
|
|
|
|
HEX_COLOR_REGEXP = /\A#?(?:\h{6}|\h{3})\z/
|
|
|
|
belongs_to :user, touch: true
|
|
scope :with_feed, -> { where.not(feed_url: [nil, ""]) }
|
|
|
|
enum editor_version: { v2: 0, v1: 1 }, _suffix: :editor
|
|
enum config_font: { default: 0, comic_sans: 1, monospace: 2, open_dyslexic: 3, sans_serif: 4, serif: 5 },
|
|
_suffix: :font
|
|
enum inbox_type: { private: 0, open: 1 }, _suffix: :inbox
|
|
enum config_navbar: { default: 0, static: 1 }, _suffix: :navbar
|
|
# NOTE: We previously had a set of 5 themes with values from 0 to 4.
|
|
enum config_theme: { light_theme: 0, dark_theme: 2 }
|
|
enum config_homepage_feed: { default: 0, latest: 1, top_week: 2, top_month: 3, top_year: 4, top_infinity: 5 },
|
|
_suffix: :feed
|
|
|
|
validates :brand_color1,
|
|
:brand_color2,
|
|
format: { with: HEX_COLOR_REGEXP, message: "is not a valid hex color" },
|
|
allow_nil: true
|
|
validates :experience_level, numericality: { less_than_or_equal_to: 10 }, allow_blank: true
|
|
validates :feed_referential_link, inclusion: { in: [true, false] }
|
|
validates :feed_url, length: { maximum: 500 }, allow_nil: true
|
|
validates :inbox_guidelines, length: { maximum: 250 }, allow_nil: true
|
|
|
|
validate :validate_feed_url, if: :feed_url_changed?
|
|
|
|
def resolved_font_name
|
|
config_font.gsub("default", Settings::UserExperience.default_font)
|
|
end
|
|
|
|
private
|
|
|
|
def validate_feed_url
|
|
return if feed_url.blank?
|
|
|
|
valid = Feeds::ValidateUrl.call(feed_url)
|
|
|
|
errors.add(:feed_url, "is not a valid RSS/Atom feed") unless valid
|
|
rescue StandardError => e
|
|
errors.add(:feed_url, e.message)
|
|
end
|
|
end
|
|
end
|