diff --git a/app/presenters/cancellation_presenter.rb b/app/presenters/cancellation_presenter.rb index 8172dacb267..163a2767590 100644 --- a/app/presenters/cancellation_presenter.rb +++ b/app/presenters/cancellation_presenter.rb @@ -1,7 +1,7 @@ class CancellationPresenter include Rails.application.routes.url_helpers - attr_reader :referer + attr_reader :referer, :url_options def initialize(referer:, url_options:) @referer = referer @@ -12,10 +12,6 @@ def go_back_path referer_path || authentication_methods_setup_path end - def url_options - @url_options - end - private def referer_path diff --git a/app/presenters/idv/gpo_presenter.rb b/app/presenters/idv/gpo_presenter.rb index 9acad309b7b..7e793764d44 100644 --- a/app/presenters/idv/gpo_presenter.rb +++ b/app/presenters/idv/gpo_presenter.rb @@ -2,7 +2,7 @@ module Idv class GpoPresenter include Rails.application.routes.url_helpers - attr_reader :current_user + attr_reader :current_user, :url_options def initialize(current_user, url_options) @current_user = current_user @@ -37,10 +37,6 @@ def letter_already_sent? gpo_mail_service.any_mail_sent? end - def url_options - @url_options - end - private def gpo_mail_service diff --git a/app/presenters/navigation_presenter.rb b/app/presenters/navigation_presenter.rb index 80539314dd9..8403c2c32aa 100644 --- a/app/presenters/navigation_presenter.rb +++ b/app/presenters/navigation_presenter.rb @@ -3,7 +3,7 @@ class NavigationPresenter NavItem = Struct.new(:title, :href, :children) - attr_reader :user + attr_reader :user, :url_options def initialize(user:, url_options:) @user = user @@ -58,10 +58,6 @@ def navigation_items ] end - def url_options - @url_options - end - def backup_codes_path if TwoFactorAuthentication::BackupCodePolicy.new(user).configured? backup_code_regenerate_path diff --git a/app/presenters/piv_cac_authentication_login_presenter.rb b/app/presenters/piv_cac_authentication_login_presenter.rb index 5a4a13f972c..4df6326718e 100644 --- a/app/presenters/piv_cac_authentication_login_presenter.rb +++ b/app/presenters/piv_cac_authentication_login_presenter.rb @@ -2,7 +2,7 @@ class PivCacAuthenticationLoginPresenter include Rails.application.routes.url_helpers include ActionView::Helpers::TranslationHelper - attr_reader :form + attr_reader :form, :url_options def initialize(form, url_options) @form = form @@ -28,8 +28,4 @@ def heading def info t('instructions.mfa.piv_cac.sign_in', app_name: APP_NAME) end - - def url_options - @url_options - end end diff --git a/lib/linters/url_options_linter.rb b/lib/linters/url_options_linter.rb index 0c293f960c3..3d57edfce40 100644 --- a/lib/linters/url_options_linter.rb +++ b/lib/linters/url_options_linter.rb @@ -20,6 +20,8 @@ module IdentityIdp # class MyViewModelClass # include Rails.application.routes.url_helpers # + # attr_reader :url_options + # # def initialize(url_options) # @url_options = url_options # end @@ -27,10 +29,6 @@ module IdentityIdp # def my_method # account_path # end - # - # def url_options - # @url_options - # end # end # class UrlOptionsLinter < RuboCop::Cop::Cop @@ -59,8 +57,17 @@ def defines_url_options?(node) return true if descendant.method?(:url_options) end + node.parent.each_descendant(:send) do |descendant| + return true if url_options_attr_method?(descendant) + end + false end + + def url_options_attr_method?(descendant) + return false unless descendant.method_name.match?(/^attr_(reader|accessor)$/) + descendant.arguments.any? { |arg| arg.value == :url_options } + end end end end diff --git a/spec/lib/linters/url_options_linter_spec.rb b/spec/lib/linters/url_options_linter_spec.rb index 8d2ba7f3a96..b7d4980bd19 100644 --- a/spec/lib/linters/url_options_linter_spec.rb +++ b/spec/lib/linters/url_options_linter_spec.rb @@ -33,4 +33,22 @@ def url_options end RUBY end + + it 'registers no offense when including Rails url_helpers and defining attr_reader' do + expect_no_offenses(<<~RUBY) + class MyViewModelClass + include Rails.application.routes.url_helpers + attr_reader :url_options + end + RUBY + end + + it 'registers no offense when including Rails url_helpers and defining attr_accessor' do + expect_no_offenses(<<~RUBY) + class MyViewModelClass + include Rails.application.routes.url_helpers + attr_accessor :url_options + end + RUBY + end end