Apply Rails/DynamicFindBy rubocop rule
We were already using `find_by` most of the time. Since there are false positives related to our `find_by_slug_or_id!` and `find_by_manger_login` methods, which cannot be replaced with `find_by`, I'm adding it indicating the "refactor" severity.
This commit is contained in:
@@ -156,6 +156,10 @@ Rails/ApplicationRecord:
|
||||
Rails/Date:
|
||||
Enabled: true
|
||||
|
||||
Rails/DynamicFindBy:
|
||||
Enabled: true
|
||||
Severity: refactor
|
||||
|
||||
Rails/FindBy:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class Budget
|
||||
scope :published, -> { enabled.where.not(kind: "drafting") }
|
||||
|
||||
PHASE_KINDS.each do |phase|
|
||||
define_singleton_method(phase) { find_by_kind(phase) }
|
||||
define_singleton_method(phase) { find_by(kind: phase) }
|
||||
end
|
||||
|
||||
def next_enabled_phase
|
||||
|
||||
@@ -5,11 +5,11 @@ module Sluggable
|
||||
before_validation :generate_slug, if: :generate_slug?
|
||||
|
||||
def self.find_by_slug_or_id(slug_or_id)
|
||||
find_by_slug(slug_or_id) || find_by_id(slug_or_id)
|
||||
find_by(slug: slug_or_id) || find_by(id: slug_or_id)
|
||||
end
|
||||
|
||||
def self.find_by_slug_or_id!(slug_or_id)
|
||||
find_by_slug(slug_or_id) || find(slug_or_id)
|
||||
find_by(slug: slug_or_id) || find(slug_or_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ module ActionView
|
||||
def t(key, options = {})
|
||||
current_locale = options[:locale].presence || I18n.locale
|
||||
|
||||
i18_content = I18nContent.find_by_key(key)
|
||||
i18_content = I18nContent.find_by(key: key)
|
||||
translation = I18nContentTranslation.where(i18n_content_id: i18_content&.id,
|
||||
locale: current_locale).first&.value
|
||||
translation.presence || translate(key, options)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("accessibility").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "accessibility").nil?
|
||||
page = SiteCustomization::Page.new(slug: "accessibility", status: "published")
|
||||
page.title = I18n.t("pages.accessibility.title")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("conditions").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "conditions").nil?
|
||||
page = SiteCustomization::Page.new(slug: "conditions", status: "published")
|
||||
page.print_content_flag = true
|
||||
page.title = I18n.t("pages.conditions.title")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("faq").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "faq").nil?
|
||||
page = SiteCustomization::Page.new(slug: "faq", status: "published")
|
||||
page.title = I18n.t("pages.help.faq.page.title")
|
||||
page.content = "<p>#{I18n.t("pages.help.faq.page.description")}</p>"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("privacy").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "privacy").nil?
|
||||
page = SiteCustomization::Page.new(slug: "privacy", status: "published")
|
||||
page.print_content_flag = true
|
||||
page.title = I18n.t("pages.privacy.title")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("welcome_level_three_verified").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "welcome_level_three_verified").nil?
|
||||
page = SiteCustomization::Page.new(slug: "welcome_level_three_verified", status: "published")
|
||||
page.title = I18n.t("welcome.welcome.title")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("welcome_level_two_verified").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "welcome_level_two_verified").nil?
|
||||
page = SiteCustomization::Page.new(slug: "welcome_level_two_verified", status: "published")
|
||||
page.title = I18n.t("welcome.welcome.title")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if SiteCustomization::Page.find_by_slug("welcome_not_verified").nil?
|
||||
if SiteCustomization::Page.find_by(slug: "welcome_not_verified").nil?
|
||||
page = SiteCustomization::Page.new(slug: "welcome_not_verified", status: "published")
|
||||
page.title = I18n.t("welcome.welcome.title")
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ describe "Admin custom pages" do
|
||||
|
||||
expect(SiteCustomization::Page.count).to be 7
|
||||
slugs.each do |slug|
|
||||
expect(SiteCustomization::Page.find_by_slug(slug).status).to eq "published"
|
||||
expect(SiteCustomization::Page.find_by(slug: slug).status).to eq "published"
|
||||
end
|
||||
|
||||
expect(all("[id^='site_customization_page_']").count).to be 7
|
||||
|
||||
Reference in New Issue
Block a user