From 454d140bd0a8bb67287dfb621153fa439add082f Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 23 Jun 2022 17:58:12 -0400 Subject: [PATCH] rubocop-ci-integration * precommit hook --- README.md | 5 +++++ .../admin/digital_products_controller.rb | 4 ++-- .../digital_service_accounts_controller.rb | 4 ++-- app/controllers/admin/forms_controller.rb | 17 +++++++-------- app/models/user.rb | 6 ++---- .../_results.html.erb | 1 - app/views/admin/websites/dendrogram.html.erb | 2 +- pre-commit | 21 +++++++++++++++++++ rubocop_autocorrect.sh | 5 +++++ 9 files changed, 46 insertions(+), 19 deletions(-) create mode 100755 pre-commit create mode 100755 rubocop_autocorrect.sh diff --git a/README.md b/README.md index 5e41266cc..8d85e4c43 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,11 @@ To start/stop after building To run tests (TBD -- this currently does not work with selenium web driver) 1. docker-compose run webapp rspec +## Code linting +- Run the script `./rubocop_autocorrect.sh` to fix standardize layout, style, and code using Rubocop +- copy the file ./pre-commit to your .git/hooks/ folder within the project to ensure changed files adhere to project standards, prior to commit. +- to get a commit through without running that pre-commit hook, use the --no-verify option + ## License See [LICENSE](LICENSE.md) diff --git a/app/controllers/admin/digital_products_controller.rb b/app/controllers/admin/digital_products_controller.rb index 6f1aa8dd4..454e2dcb7 100644 --- a/app/controllers/admin/digital_products_controller.rb +++ b/app/controllers/admin/digital_products_controller.rb @@ -149,8 +149,8 @@ def search @digital_products = DigitalProduct.all @digital_products = @digital_products.where("name ilike '%#{search_text}%'") if search_text && search_text.length >= 3 @digital_products = @digital_products.tagged_with(organization_id, context: 'organizations') if organization_id.present? && organization_id != '' - @digital_products = @digital_products.where('service = ?', params[:service]) if params[:service].present? && params[:service] != 'All' - @digital_products = @digital_products.where('aasm_state = ?', params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All' + @digital_products = @digital_products.where(service: params[:service]) if params[:service].present? && params[:service] != 'All' + @digital_products = @digital_products.where(aasm_state: params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All' @digital_products end diff --git a/app/controllers/admin/digital_service_accounts_controller.rb b/app/controllers/admin/digital_service_accounts_controller.rb index b43f920a4..45e38f124 100644 --- a/app/controllers/admin/digital_service_accounts_controller.rb +++ b/app/controllers/admin/digital_service_accounts_controller.rb @@ -178,8 +178,8 @@ def search @digital_service_accounts = DigitalServiceAccount.all @digital_service_accounts = @digital_service_accounts.where("name ilike '%#{search_text}%'") if search_text && search_text.length >= 3 @digital_service_accounts = @digital_service_accounts.tagged_with(organization_id, context: 'organizations') if organization_id.present? && organization_id != '' - @digital_service_accounts = @digital_service_accounts.where('service = ?', params[:service]) if params[:service].present? && params[:service] != 'All' - @digital_service_accounts = @digital_service_accounts.where('aasm_state = ?', params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All' + @digital_service_accounts = @digital_service_accounts.where(service: params[:service]) if params[:service].present? && params[:service] != 'All' + @digital_service_accounts = @digital_service_accounts.where(aasm_state: params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All' @digital_service_accounts end diff --git a/app/controllers/admin/forms_controller.rb b/app/controllers/admin/forms_controller.rb index b18fd33f9..8657d60b3 100644 --- a/app/controllers/admin/forms_controller.rb +++ b/app/controllers/admin/forms_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'csv' module Admin @@ -200,21 +201,19 @@ def create @form.modal_button_text = t('form.help_improve') @form.success_text_heading = t('success') @form.success_text = t('form.submit_thankyou') - @form.delivery_method = "touchpoints-hosted-only" + @form.delivery_method = 'touchpoints-hosted-only' @form.load_css = true - unless @form.user - @form.user = current_user - end + @form.user = current_user unless @form.user respond_to do |format| if @form.save - Event.log_event(Event.names[:form_created], "Form", @form.uuid,"Form #{@form.name} created at #{DateTime.now}", current_user.id) + Event.log_event(Event.names[:form_created], 'Form', @form.uuid, "Form #{@form.name} created at #{DateTime.now}", current_user.id) UserRole.create!({ - user: current_user, - form: @form, - role: UserRole::Role::FormManager - }) + user: current_user, + form: @form, + role: UserRole::Role::FormManager, + }) format.html { redirect_to questions_admin_form_path(@form), notice: 'Survey was successfully created.' } format.json { render :show, status: :created, location: @form } diff --git a/app/models/user.rb b/app/models/user.rb index 95b28e524..8587e3eb7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -124,14 +124,12 @@ def self.deactivation_pending(expire_days) def self.deactivate_inactive_accounts! # Find all accounts scheduled to be deactivated in 14 days users = User.active.where('(current_sign_in_at ISNULL AND created_at <= ?) OR (current_sign_in_at <= ?)', 90.days.ago, 90.days.ago) - users.each do |user| - user.deactivate! - end + users.each(&:deactivate!) end def self.to_csv active_users = order('email') - return nil unless active_users.present? + return nil if active_users.blank? header_attributes = %w[organization_name email current_sign_in_at] attributes = active_users.map do |u| diff --git a/app/views/admin/digital_service_accounts/_results.html.erb b/app/views/admin/digital_service_accounts/_results.html.erb index b1d462574..8babcd13f 100644 --- a/app/views/admin/digital_service_accounts/_results.html.erb +++ b/app/views/admin/digital_service_accounts/_results.html.erb @@ -25,4 +25,3 @@ <% end %> - diff --git a/app/views/admin/websites/dendrogram.html.erb b/app/views/admin/websites/dendrogram.html.erb index 81d0f9649..344f0db76 100644 --- a/app/views/admin/websites/dendrogram.html.erb +++ b/app/views/admin/websites/dendrogram.html.erb @@ -26,7 +26,7 @@