From 2fa92937d2558410f3d2c4949faa74889f2fe7e5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 25 Jun 2017 15:57:05 +0200 Subject: [PATCH] Fix all Style/BracesAroundHashParameters rubocop issues and remove them from rubocop_todo list --- .rubocop_todo.yml | 16 ---------------- .../admin/poll/polls_controller.rb | 2 +- .../spending_proposals_controller.rb | 2 +- app/models/concerns/searchable.rb | 19 +++++++++---------- app/models/officing/residence.rb | 11 +++++------ app/models/verification/residence.rb | 10 +++++----- lib/manager_authenticator.rb | 2 +- ...grate_spending_proposals_to_investments.rb | 2 +- spec/controllers/graphql_controller_spec.rb | 6 +++--- .../management/users_controller_spec.rb | 2 +- .../features/admin/budget_investments_spec.rb | 2 +- .../features/admin/spending_proposals_spec.rb | 2 +- spec/lib/manager_authenticator_spec.rb | 10 +++++----- spec/models/officing/residence_spec.rb | 8 ++++---- spec/models/residence_spec.rb | 14 +++++++------- spec/models/user_spec.rb | 4 ++-- 16 files changed, 47 insertions(+), 65 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 54a3f650f..076069d66 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -165,22 +165,6 @@ Layout/AlignParameters: - 'spec/models/user_spec.rb' - 'spec/rails_helper.rb' -# Offense count: 19 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'app/controllers/valuation/spending_proposals_controller.rb' - - 'app/models/concerns/searchable.rb' - - 'app/models/verification/residence.rb' - - 'lib/manager_authenticator.rb' - - 'spec/controllers/management/users_controller_spec.rb' - - 'spec/features/admin/spending_proposals_spec.rb' - - 'spec/lib/manager_authenticator_spec.rb' - - 'spec/models/residence_spec.rb' - - 'spec/models/user_spec.rb' - # Offense count: 57 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 6046ffb48..cad91f218 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -60,7 +60,7 @@ class Admin::Poll::PollsController < Admin::BaseController end def search_questions - @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}).order(title: :asc) + @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search(search: @search).order(title: :asc) respond_to do |format| format.js end diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index 623c9ac46..1273b80b6 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -58,7 +58,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController end def params_for_current_valuator - params.merge({valuator_id: current_user.valuator.id}) + params.merge(valuator_id: current_user.valuator.id) end def restrict_access_to_assigned_items diff --git a/app/models/concerns/searchable.rb b/app/models/concerns/searchable.rb index 147a37fbc..7de037ca1 100644 --- a/app/models/concerns/searchable.rb +++ b/app/models/concerns/searchable.rb @@ -5,15 +5,14 @@ module Searchable include PgSearch include SearchCache - pg_search_scope :pg_search, { - against: :ignored, # not used since using a tsvector_column - using: { - tsearch: { tsvector_column: 'tsv', dictionary: "spanish", prefix: true } - }, - ignoring: :accents, - ranked_by: '(:tsearch)', - order_within_rank: (self.column_names.include?('cached_votes_up') ? "#{self.table_name}.cached_votes_up DESC" : nil) - } + pg_search_scope :pg_search, + against: :ignored, # not used since using a tsvector_column + using: { + tsearch: { tsvector_column: 'tsv', dictionary: "spanish", prefix: true } + }, + ignoring: :accents, + ranked_by: '(:tsearch)', + order_within_rank: (self.column_names.include?('cached_votes_up') ? "#{self.table_name}.cached_votes_up DESC" : nil) end -end \ No newline at end of file +end diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index 63250d041..b0fc56078 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -43,14 +43,13 @@ class Officing::Residence end def store_failed_census_call - FailedCensusCall.create({ + FailedCensusCall.create( user: user, document_number: document_number, - document_type: document_type, - year_of_birth: year_of_birth, - poll_officer: officer - }) - + document_type: document_type, + year_of_birth: year_of_birth, + poll_officer: officer + ) end def user_exists? diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 00f729d2c..7fa7f74b4 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -47,13 +47,13 @@ class Verification::Residence end def store_failed_attempt - FailedCensusCall.create({ + FailedCensusCall.create( user: user, document_number: document_number, - document_type: document_type, - date_of_birth: date_of_birth, - postal_code: postal_code - }) + document_type: document_type, + date_of_birth: date_of_birth, + postal_code: postal_code + ) end def geozone diff --git a/lib/manager_authenticator.rb b/lib/manager_authenticator.rb index 11928e737..8f9a1f55a 100644 --- a/lib/manager_authenticator.rb +++ b/lib/manager_authenticator.rb @@ -25,7 +25,7 @@ class ManagerAuthenticator parsed_response = parser.parse((response[:get_applications_user_list_response][:get_applications_user_list_return])) aplication_value = parsed_response["APLICACIONES"]["APLICACION"] # aplication_value from UWEB can be an array of hashes or a hash - aplication_value.include?({"CLAVE_APLICACION" => application_key}) || aplication_value["CLAVE_APLICACION"] == application_key + aplication_value.include?("CLAVE_APLICACION" => application_key) || aplication_value["CLAVE_APLICACION"] == application_key rescue false end diff --git a/lib/migrate_spending_proposals_to_investments.rb b/lib/migrate_spending_proposals_to_investments.rb index 9ef2f096d..6df75d3f7 100644 --- a/lib/migrate_spending_proposals_to_investments.rb +++ b/lib/migrate_spending_proposals_to_investments.rb @@ -50,7 +50,7 @@ class MigrateSpendingProposalsToInvestments votes = ActsAsVotable::Vote.where(votable_type: 'SpendingProposal', votable_id: sp.id) - votes.each {|v| investment.vote_by({voter: v.voter, vote: 'yes'}) } + votes.each {|v| investment.vote_by(voter: v.voter, vote: 'yes') } # Spending proposals are not commentable in Consul so we can not test this # diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index 1b8c64793..0f15da038 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -71,19 +71,19 @@ describe GraphqlController, type: :request do let(:query_string) { "{ proposal(id: #{proposal.id}) { title } }" } specify "when absent" do - get '/graphql', { query: query_string } + get '/graphql', query: query_string expect(response).to have_http_status(:ok) end specify "when specified as the 'null' string" do - get '/graphql', { query: query_string, variables: 'null' } + get '/graphql', query: query_string, variables: 'null' expect(response).to have_http_status(:ok) end specify "when specified as an empty string" do - get '/graphql', { query: query_string, variables: '' } + get '/graphql', query: query_string, variables: '' expect(response).to have_http_status(:ok) end diff --git a/spec/controllers/management/users_controller_spec.rb b/spec/controllers/management/users_controller_spec.rb index e57ff7b15..8fb41128a 100644 --- a/spec/controllers/management/users_controller_spec.rb +++ b/spec/controllers/management/users_controller_spec.rb @@ -10,7 +10,7 @@ describe Management::UsersController do get :logout - expect(session[:manager]).to eq({user_key: "31415926", date: "20151031135905", login: "JJB033"}) + expect(session[:manager]).to eq(user_key: "31415926", date: "20151031135905", login: "JJB033") expect(session[:document_type]).to be_nil expect(session[:document_number]).to be_nil expect(response).to be_redirect diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index c50a05f32..727cc3d6c 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -47,7 +47,7 @@ feature 'Admin budget investments' do budget_investment1.valuators << valuator1 budget_investment2.valuator_ids = [valuator1.id, valuator2.id] - budget_investment3.update({administrator_id: admin.id}) + budget_investment3.update(administrator_id: admin.id) visit admin_budget_budget_investments_path(budget_id: @budget.id) diff --git a/spec/features/admin/spending_proposals_spec.rb b/spec/features/admin/spending_proposals_spec.rb index 239454902..91eb6716b 100644 --- a/spec/features/admin/spending_proposals_spec.rb +++ b/spec/features/admin/spending_proposals_spec.rb @@ -43,7 +43,7 @@ feature 'Admin spending proposals' do spending_proposal1.valuators << valuator1 spending_proposal2.valuator_ids = [valuator1.id, valuator2.id] - spending_proposal3.update({administrator_id: admin.id}) + spending_proposal3.update(administrator_id: admin.id) visit admin_spending_proposals_path diff --git a/spec/lib/manager_authenticator_spec.rb b/spec/lib/manager_authenticator_spec.rb index 256303fdd..c53a26f5e 100644 --- a/spec/lib/manager_authenticator_spec.rb +++ b/spec/lib/manager_authenticator_spec.rb @@ -3,24 +3,24 @@ require 'rails_helper' describe ManagerAuthenticator do describe 'initialization params' do it 'should cause auth to return false if blank login' do - authenticator = ManagerAuthenticator.new({login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905"}) + authenticator = ManagerAuthenticator.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905") expect(authenticator.auth).to be false end it 'should cause auth to return false if blank user_key' do - authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905"}) + authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905") expect(authenticator.auth).to be false end it 'should cause auth to return false if blank date' do - authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "31415926", fecha_conexion: ""}) + authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "") expect(authenticator.auth).to be false end end describe '#auth' do before(:all) do - @authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905"}) + @authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") end it 'should return false if not manager_exists' do @@ -47,7 +47,7 @@ describe ManagerAuthenticator do describe 'SOAP' do before(:all) do - @authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905"}) + @authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") end it 'should call the verification user method' do diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index dee63b85a..c39711e30 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -44,12 +44,12 @@ describe Officing::Residence do describe "new" do it "should upcase document number" do - residence = Officing::Residence.new({document_number: "x1234567z"}) + residence = Officing::Residence.new(document_number: "x1234567z") expect(residence.document_number).to eq("X1234567Z") end it "should remove all characters except numbers and letters" do - residence = Officing::Residence.new({document_number: " 12.345.678 - B"}) + residence = Officing::Residence.new(document_number: " 12.345.678 - B") expect(residence.document_number).to eq("12345678B") end end @@ -108,13 +108,13 @@ describe Officing::Residence do residence.save expect(FailedCensusCall.count).to eq(1) - expect(FailedCensusCall.first).to have_attributes({ + expect(FailedCensusCall.first).to have_attributes( user_id: residence.user.id, poll_officer_id: residence.officer.id, document_number: "12345678Z", document_type: "1", year_of_birth: Time.current.year - }) + ) end end diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index d518c41af..072782508 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -13,19 +13,19 @@ describe Verification::Residence do describe "dates" do it "should be valid with a valid date of birth" do - residence = Verification::Residence.new({"date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980"}) + residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980") expect(residence.errors[:date_of_birth].size).to eq(0) end it "should not be valid without a date of birth" do - residence = Verification::Residence.new({"date_of_birth(3i)" => "", "date_of_birth(2i)" => "", "date_of_birth(1i)" => ""}) + residence = Verification::Residence.new("date_of_birth(3i)" => "", "date_of_birth(2i)" => "", "date_of_birth(1i)" => "") expect(residence).to_not be_valid expect(residence.errors[:date_of_birth]).to include("can't be blank") end end it "should validate user has allowed age" do - residence = Verification::Residence.new({"date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "#{5.years.ago.year}"}) + residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "#{5.years.ago.year}") expect(residence).to_not be_valid expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate") end @@ -50,12 +50,12 @@ describe Verification::Residence do describe "new" do it "should upcase document number" do - residence = Verification::Residence.new({document_number: "x1234567z"}) + residence = Verification::Residence.new(document_number: "x1234567z") expect(residence.document_number).to eq("X1234567Z") end it "should remove all characters except numbers and letters" do - residence = Verification::Residence.new({document_number: " 12.345.678 - B"}) + residence = Verification::Residence.new(document_number: " 12.345.678 - B") expect(residence.document_number).to eq("12345678B") end end @@ -99,13 +99,13 @@ describe Verification::Residence do residence.save expect(FailedCensusCall.count).to eq(1) - expect(FailedCensusCall.first).to have_attributes({ + expect(FailedCensusCall.first).to have_attributes( user_id: residence.user.id, document_number: "12345678Z", document_type: "1", date_of_birth: Date.new(1980, 12, 31), postal_code: "28001" - }) + ) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0ea321423..2e92e5c96 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -434,13 +434,13 @@ describe User do describe "document_number" do it "should upcase document number" do - user = User.new({document_number: "x1234567z"}) + user = User.new(document_number: "x1234567z") user.valid? expect(user.document_number).to eq("X1234567Z") end it "should remove all characters except numbers and letters" do - user = User.new({document_number: " 12.345.678 - B"}) + user = User.new(document_number: " 12.345.678 - B") user.valid? expect(user.document_number).to eq("12345678B") end