From 4e0d88739d9597bee8fe2433b5a109bc6d9dcb81 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 00:34:57 +0200 Subject: [PATCH 1/5] Fix Rails/Blank rubocop issue --- .rubocop_todo.yml | 7 ------- app/controllers/management/base_controller.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 142b66d7f..08a780ac1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -365,13 +365,6 @@ Performance/RedundantMatch: - 'app/controllers/valuation/spending_proposals_controller.rb' - 'app/helpers/embed_videos_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. -Rails/Blank: - Exclude: - - 'app/controllers/management/base_controller.rb' - # Offense count: 1 # Cop supports --auto-correct. Rails/Delegate: diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index f7a9c2214..66aee5a01 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -9,7 +9,7 @@ class Management::BaseController < ActionController::Base private def verify_manager - raise ActionController::RoutingError.new('Not Found') unless current_manager.present? + raise ActionController::RoutingError.new('Not Found') if current_manager.blank? end def current_manager From beb4bc119c638f046681e2c6cd7b40dac940fc5e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 00:37:03 +0200 Subject: [PATCH 2/5] Fix Rails/Delegate rubocop issue --- .rubocop_todo.yml | 6 ------ app/models/poll/question.rb | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 08a780ac1..c99c38d18 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -365,12 +365,6 @@ Performance/RedundantMatch: - 'app/controllers/valuation/spending_proposals_controller.rb' - 'app/helpers/embed_videos_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Rails/Delegate: - Exclude: - - 'app/models/poll/question.rb' - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: Whitelist. diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index b67650a8d..28dd8ed4a 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -58,9 +58,7 @@ class Poll::Question < ActiveRecord::Base end end - def answerable_by?(user) - poll.answerable_by?(user) - end + delegate :answerable_by?, to: :poll def self.answerable_by(user) return none if user.nil? || user.unverified? From 023825b4c91f5bc173190d6c0cfbd2a6559497a7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 00:38:50 +0200 Subject: [PATCH 3/5] Fix Rails/Present rubocop issue --- .rubocop_todo.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c99c38d18..6ceaa4cbb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -436,13 +436,6 @@ Rails/OutputSafety: - 'app/helpers/users_helper.rb' - 'app/helpers/valuation_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. -Rails/Present: - Exclude: - - 'app/controllers/management/document_verifications_controller.rb' - # Offense count: 70 # Configuration parameters: Blacklist. # Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters From 3a54713ed042b31db304347b9bce86c9e3e118c2 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 23:04:27 +0200 Subject: [PATCH 4/5] Fix all Rails/DynamicFindBy rubocop issues --- .rubocop_todo.yml | 10 ---------- app/controllers/users/confirmations_controller.rb | 4 ++-- app/controllers/users/registrations_controller.rb | 2 +- spec/features/management/users_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6ceaa4cbb..3ae8bebec 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -365,16 +365,6 @@ Performance/RedundantMatch: - 'app/controllers/valuation/spending_proposals_controller.rb' - 'app/helpers/embed_videos_helper.rb' -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: Whitelist. -# Whitelist: find_by_sql -Rails/DynamicFindBy: - Exclude: - - 'app/controllers/users/confirmations_controller.rb' - - 'app/controllers/users/registrations_controller.rb' - - 'spec/features/management/users_spec.rb' - # Offense count: 2 Rails/FilePath: Exclude: diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 04a028232..9b7ebd41b 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -3,7 +3,7 @@ class Users::ConfirmationsController < Devise::ConfirmationsController # new action, PATCH does not exist in the default Devise::ConfirmationsController # PATCH /resource/confirmation def update - self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) + self.resource = resource_class.find_by(confirmation_token: params[:confirmation_token]) if resource.encrypted_password.blank? resource.assign_attributes(resource_params) @@ -27,7 +27,7 @@ class Users::ConfirmationsController < Devise::ConfirmationsController def show # In the default implementation, this already confirms the resource: # self.resource = self.resource = resource_class.confirm_by_token(params[:confirmation_token]) - self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) + self.resource = resource_class.find_by(confirmation_token: params[:confirmation_token]) yield resource if block_given? diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 2b25a5126..17262cd96 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -48,7 +48,7 @@ class Users::RegistrationsController < Devise::RegistrationsController end def check_username - if User.find_by_username params[:username] + if User.find_by username: params[:username] render json: {available: false, message: t("devise_views.users.registrations.new.username_is_not_available")} else render json: {available: true, message: t("devise_views.users.registrations.new.username_is_available")} diff --git a/spec/features/management/users_spec.rb b/spec/features/management/users_spec.rb index cdb0ec879..f50728bfc 100644 --- a/spec/features/management/users_spec.rb +++ b/spec/features/management/users_spec.rb @@ -24,7 +24,7 @@ feature 'Users' do expect(page).to have_content "We have sent an email" expect(page).to_not have_content "Autogenerated password is" - user = User.find_by_email('pepe@gmail.com') + user = User.find_by(email: 'pepe@gmail.com') expect(user).to be_level_three_verified expect(user).to be_residence_verified @@ -64,7 +64,7 @@ feature 'Users' do expect(page).to_not have_content "We have sent an email" expect(page).to have_content "Autogenerated password is" - user = User.find_by_username('Kelly Sue') + user = User.find_by(username: 'Kelly Sue') expect(user).to be_level_three_verified expect(user).to be_residence_verified From 5a358bce177e1e6d99587a6b300a00575b07dd6f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 23:08:02 +0200 Subject: [PATCH 5/5] Fix all Rails/FilePath rubocop issues --- .rubocop_todo.yml | 6 ------ app/controllers/sandbox_controller.rb | 2 +- spec/spec_helper.rb | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3ae8bebec..ecb3f190f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -365,12 +365,6 @@ Performance/RedundantMatch: - 'app/controllers/valuation/spending_proposals_controller.rb' - 'app/helpers/embed_videos_helper.rb' -# Offense count: 2 -Rails/FilePath: - Exclude: - - 'app/controllers/sandbox_controller.rb' - - 'spec/spec_helper.rb' - # Offense count: 16 # Cop supports --auto-correct. # Configuration parameters: Include. diff --git a/app/controllers/sandbox_controller.rb b/app/controllers/sandbox_controller.rb index b1a143f54..6c6fa2d71 100644 --- a/app/controllers/sandbox_controller.rb +++ b/app/controllers/sandbox_controller.rb @@ -6,7 +6,7 @@ class SandboxController < ApplicationController helper_method(:namespace) def index - @templates = Dir.glob(Rails.root.join('app/views/sandbox/*.html.erb').to_s).map do |filename| + @templates = Dir.glob(Rails.root.join('app', 'views', 'sandbox', '*.html.erb').to_s).map do |filename| filename = File.basename(filename, File.extname(filename)) filename unless filename.starts_with?('_') || filename == 'index.html' end.compact diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7ef336a4d..bb985848a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,7 +39,7 @@ RSpec.configure do |config| config.before(:each) do |example| DatabaseCleaner.strategy = :transaction I18n.locale = :en - load "#{Rails.root}/db/seeds.rb" + load Rails.root.join('db', 'seeds.rb').to_s end config.before(:each, type: :feature) do