From 00cdd2eb5e83addd28ee4c84c0faa4dec5eda831 Mon Sep 17 00:00:00 2001 From: Pascal Zumkehr Date: Tue, 31 Oct 2023 22:45:17 +0100 Subject: [PATCH] Fix rubocop issues --- .rubocop.yml | 7 +++++++ app/controllers/crud_controller.rb | 10 +++++----- app/controllers/dry_crud/generic_model.rb | 2 -- app/controllers/dry_crud/render_callbacks.rb | 6 +++--- app/helpers/actions_helper.rb | 6 +++--- app/helpers/dry_crud/form/builder.rb | 2 +- app/helpers/dry_crud/table/actions.rb | 2 +- .../test/support/crud_test_models_controller.rb | 2 +- test/templates/test/.rubocop.yml | 3 +++ 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8637f523..29cdb992 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -73,6 +73,13 @@ Layout/EmptyLinesAroundBlockBody: Exclude: - '**/*_spec.rb' +Rails/ActionControllerTestCase: + Enabled: false + +Rails/I18nLocaleTexts: + Exclude: + - '**/test/support/*.rb' + Rails/HelperInstanceVariable: Enabled: false diff --git a/app/controllers/crud_controller.rb b/app/controllers/crud_controller.rb index f9dd9d61..8138dfbf 100644 --- a/app/controllers/crud_controller.rb +++ b/app/controllers/crud_controller.rb @@ -40,6 +40,11 @@ def new assign_attributes if params[model_identifier] end + # GET /entries/1/edit + # + # Display a form to edit an exisiting entry of this model. + def edit; end + # POST /entries # POST /entries.json # @@ -63,11 +68,6 @@ def create(**options, &block) end end - # GET /entries/1/edit - # - # Display a form to edit an exisiting entry of this model. - def edit; end - # PUT /entries/1 # PUT /entries/1.json # diff --git a/app/controllers/dry_crud/generic_model.rb b/app/controllers/dry_crud/generic_model.rb index ea5f789b..f415720f 100644 --- a/app/controllers/dry_crud/generic_model.rb +++ b/app/controllers/dry_crud/generic_model.rb @@ -13,8 +13,6 @@ module GenericModel included do helper_method :model_class, :models_label, :path_args - private - delegate :model_class, :models_label, :model_identifier, to: 'self.class' end diff --git a/app/controllers/dry_crud/render_callbacks.rb b/app/controllers/dry_crud/render_callbacks.rb index 7f6e93db..36464783 100644 --- a/app/controllers/dry_crud/render_callbacks.rb +++ b/app/controllers/dry_crud/render_callbacks.rb @@ -15,13 +15,13 @@ module Prepends # Helper method to run +before_render+ callbacks and render the action. # If a callback renders or redirects, the action is not rendered. - def render(*args, &block) - options = _normalize_render(*args, &block) + def render(...) + options = _normalize_render(...) callback = "render_#{options[:template]}" run_callbacks(callback) if respond_to?(:"_#{callback}_callbacks", true) - super(*args, &block) unless performed? + super(...) unless performed? end private diff --git a/app/helpers/actions_helper.rb b/app/helpers/actions_helper.rb index ca0a37e5..163d55e6 100644 --- a/app/helpers/actions_helper.rb +++ b/app/helpers/actions_helper.rb @@ -30,7 +30,7 @@ def show_action_link(path = nil) # Uses the current +entry+ if no path is given. def edit_action_link(path = nil) path ||= path_args(entry) - path = path.is_a?(String) ? path : edit_polymorphic_path(path) + path = edit_polymorphic_path(path) unless path.is_a?(String) action_link(ti('link.edit'), 'pencil', path) end @@ -47,7 +47,7 @@ def destroy_action_link(path = nil) # Uses the current +model_class+ if no path is given. def index_action_link(path = nil, url_options = { returning: true }) path ||= path_args(model_class) - path = path.is_a?(String) ? path : polymorphic_path(path, url_options) + path = polymorphic_path(path, url_options) unless path.is_a?(String) action_link(ti('link.list'), 'list', path) end @@ -55,7 +55,7 @@ def index_action_link(path = nil, url_options = { returning: true }) # Uses the current +model_class+ if no path is given. def add_action_link(path = nil, url_options = {}) path ||= path_args(model_class) - path = path.is_a?(String) ? path : new_polymorphic_path(path, url_options) + path = new_polymorphic_path(path, url_options) unless path.is_a?(String) action_link(ti('link.add'), 'plus', path) end diff --git a/app/helpers/dry_crud/form/builder.rb b/app/helpers/dry_crud/form/builder.rb index 8f59d63b..eeb9a2d0 100644 --- a/app/helpers/dry_crud/form/builder.rb +++ b/app/helpers/dry_crud/form/builder.rb @@ -267,7 +267,7 @@ def respond_to_missing?(name, include_private = false) def labeled_field_method?(name) prefix = 'labeled_' if name.to_s.start_with?(prefix) - field_method = name.to_s[prefix.size..-1] + field_method = name.to_s[prefix.size..] field_method if respond_to?(field_method) end end diff --git a/app/helpers/dry_crud/table/actions.rb b/app/helpers/dry_crud/table/actions.rb index 8e4cad3a..3902202c 100644 --- a/app/helpers/dry_crud/table/actions.rb +++ b/app/helpers/dry_crud/table/actions.rb @@ -44,7 +44,7 @@ def edit_action_col(**html_options, &block) action_col do |entry| path = action_path(entry, &block) if path - path = path.is_a?(String) ? path : edit_polymorphic_path(path) + path = edit_polymorphic_path(path) unless path.is_a?(String) table_action_link('pencil', path, **html_options.clone) end end diff --git a/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb b/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb index 67c00d41..f7917f65 100644 --- a/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb +++ b/lib/generators/dry_crud/templates/test/support/crud_test_models_controller.rb @@ -92,7 +92,7 @@ def set_companions # handle the called callbacks def method_missing(sym, *_args) if sym.to_s.starts_with?(HANDLE_PREFIX) - called_callback(sym.to_s[HANDLE_PREFIX.size..-1].to_sym) + called_callback(sym.to_s[HANDLE_PREFIX.size..].to_sym) else super end diff --git a/test/templates/test/.rubocop.yml b/test/templates/test/.rubocop.yml index ca24881d..782caf9a 100644 --- a/test/templates/test/.rubocop.yml +++ b/test/templates/test/.rubocop.yml @@ -37,6 +37,9 @@ Layout/ParameterAlignment: Layout/SpaceBeforeFirstArg: Enabled: false +Rails/ActionControllerTestCase: + Enabled: false + Rails/OutputSafety: Enabled: false