From 22822aa1738935e4d6d6bea0c461d2bf95e562c1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:44:58 +0200 Subject: [PATCH 1/8] Fix Style/RedundantParentheses rubocop issues --- .rubocop_todo.yml | 5 --- app/controllers/admin/settings_controller.rb | 2 +- .../legislation/annotations_controller.rb | 2 +- app/helpers/proposals_helper.rb | 4 +-- app/models/concerns/graphqlable.rb | 2 +- spec/features/admin/organizations_spec.rb | 14 ++++---- spec/features/budgets/investments_spec.rb | 6 ++-- spec/features/campaigns_spec.rb | 2 +- spec/features/debates_spec.rb | 4 +-- .../features/management/managed_users_spec.rb | 32 +++++++++---------- spec/features/management/proposals_spec.rb | 12 +++---- spec/features/management/users_spec.rb | 4 +-- spec/features/proposals_spec.rb | 4 +-- spec/models/budget/investment_spec.rb | 2 +- spec/models/debate_spec.rb | 4 +-- spec/models/residence_spec.rb | 2 +- 16 files changed, 48 insertions(+), 53 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 56f040259..7fe5ee343 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -668,11 +668,6 @@ Style/RedundantBegin: - 'app/controllers/graphql_controller.rb' - 'app/models/legislation/annotation.rb' -# Offense count: 55 -# Cop supports --auto-correct. -Style/RedundantParentheses: - Enabled: false - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 63ec8cf52..70541a3a0 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,7 +1,7 @@ class Admin::SettingsController < Admin::BaseController def index - all_settings = (Setting.all).group_by { |s| s.type } + all_settings = Setting.all.group_by { |s| s.type } @settings = all_settings['common'] @feature_flags = all_settings['feature'] @banner_styles = all_settings['banner-style'] diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index 352fce266..ebbe05b12 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -30,7 +30,7 @@ class Legislation::AnnotationsController < ApplicationController def create if !@process.allegations_phase.open? || @draft_version.final_version? - render(json: {}, status: :not_found) && (return) + render(json: {}, status: :not_found) && return end existing_annotation = @draft_version.annotations.where( diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index d40f7950c..64936302e 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -12,8 +12,8 @@ module ProposalsHelper percentage = (proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success) case percentage when 0 then "0%" - when 0..(0.1) then "0.1%" - when (0.1)..100 then number_to_percentage(percentage, strip_insignificant_zeros: true, precision: 1) + when 0..0.1 then "0.1%" + when 0.1..100 then number_to_percentage(percentage, strip_insignificant_zeros: true, precision: 1) else "100%" end end diff --git a/app/models/concerns/graphqlable.rb b/app/models/concerns/graphqlable.rb index 228810579..c8b47cece 100644 --- a/app/models/concerns/graphqlable.rb +++ b/app/models/concerns/graphqlable.rb @@ -24,7 +24,7 @@ module Graphqlable end def graphql_type_description - (model_name.human).to_s + model_name.human.to_s end end diff --git a/spec/features/admin/organizations_spec.rb b/spec/features/admin/organizations_spec.rb index 814aa9df2..58375f569 100644 --- a/spec/features/admin/organizations_spec.rb +++ b/spec/features/admin/organizations_spec.rb @@ -95,7 +95,7 @@ feature 'Admin::Organizations' do click_on 'Verify' end expect(current_path).to eq(admin_organizations_path) - expect(page).to have_content ('Verified') + expect(page).to have_content 'Verified' expect(organization.reload.verified?).to eq(true) end @@ -108,18 +108,18 @@ feature 'Admin::Organizations' do click_on "Verified" within("#organization_#{organization.id}") do - expect(page).to have_content ('Verified') + expect(page).to have_content 'Verified' expect(page).to_not have_link('Verify') expect(page).to have_link('Reject') click_on 'Reject' end expect(current_path).to eq(admin_organizations_path) - expect(page).to_not have_content (organization.name) + expect(page).to_not have_content organization.name click_on 'Rejected' - expect(page).to have_content ('Rejected') - expect(page).to have_content (organization.name) + expect(page).to have_content 'Rejected' + expect(page).to have_content organization.name expect(organization.reload.rejected?).to eq(true) end @@ -137,10 +137,10 @@ feature 'Admin::Organizations' do click_on 'Verify' end expect(current_path).to eq(admin_organizations_path) - expect(page).to_not have_content (organization.name) + expect(page).to_not have_content organization.name click_on('Verified') - expect(page).to have_content (organization.name) + expect(page).to have_content organization.name expect(organization.reload.verified?).to eq(true) end diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 820ebb520..afc564496 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -264,7 +264,7 @@ feature 'Budget Investments' do fill_in "budget_investment_title", with: "search" within("div#js-suggest") do - expect(page).to have_content ("You are seeing 5 of 6 investments containing the term 'search'") + expect(page).to have_content "You are seeing 5 of 6 investments containing the term 'search'" end end @@ -279,7 +279,7 @@ feature 'Budget Investments' do fill_in "budget_investment_title", with: "item" within('div#js-suggest') do - expect(page).to_not have_content ('You are seeing') + expect(page).to_not have_content 'You are seeing' end end @@ -294,7 +294,7 @@ feature 'Budget Investments' do fill_in "budget_investment_title", with: "search" within('div#js-suggest') do - expect(page).to_not have_content ('You are seeing') + expect(page).to_not have_content 'You are seeing' end end end diff --git a/spec/features/campaigns_spec.rb b/spec/features/campaigns_spec.rb index 6dba2ff09..6e9897a6f 100644 --- a/spec/features/campaigns_spec.rb +++ b/spec/features/campaigns_spec.rb @@ -27,7 +27,7 @@ feature 'Email campaigns' do visit admin_stats_path expect(page).to have_content "#{@campaign1.name} (1)" - expect(page).to_not have_content (@campaign2.name).to_s + expect(page).to_not have_content @campaign2.name.to_s end end \ No newline at end of file diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 749c7a373..a50363489 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -879,7 +879,7 @@ feature 'Debates' do check "debate_terms_of_service" within('div#js-suggest') do - expect(page).to have_content ("You are seeing 5 of 6 debates containing the term 'debate'") + expect(page).to have_content "You are seeing 5 of 6 debates containing the term 'debate'" end end @@ -895,7 +895,7 @@ feature 'Debates' do check "debate_terms_of_service" within('div#js-suggest') do - expect(page).to_not have_content ('You are seeing') + expect(page).to_not have_content 'You are seeing' end end end diff --git a/spec/features/management/managed_users_spec.rb b/spec/features/management/managed_users_spec.rb index ef3c539d9..68b9777a3 100644 --- a/spec/features/management/managed_users_spec.rb +++ b/spec/features/management/managed_users_spec.rb @@ -24,9 +24,9 @@ feature 'Managed User' do within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.email).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.email.to_s + expect(page).to have_content user.document_number.to_s end end @@ -45,9 +45,9 @@ feature 'Managed User' do within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.email).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.email.to_s + expect(page).to have_content user.document_number.to_s end end @@ -78,9 +78,9 @@ feature 'Managed User' do within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.email).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.email.to_s + expect(page).to have_content user.document_number.to_s end end @@ -106,9 +106,9 @@ feature 'Managed User' do user = User.last within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.email).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.email.to_s + expect(page).to have_content user.document_number.to_s end end @@ -134,8 +134,8 @@ feature 'Managed User' do user = User.last within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.document_number.to_s end end end @@ -151,14 +151,14 @@ feature 'Managed User' do within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s + expect(page).to have_content user.username.to_s click_link "Change user" end expect(page).to have_content "User session signed out successfully." expect(page).to_not have_content "Identified as" - expect(page).to_not have_content (user.username).to_s + expect(page).to_not have_content user.username.to_s expect(current_path).to eq(management_root_path) end diff --git a/spec/features/management/proposals_spec.rb b/spec/features/management/proposals_spec.rb index 349a4f904..ed24de172 100644 --- a/spec/features/management/proposals_spec.rb +++ b/spec/features/management/proposals_spec.rb @@ -16,9 +16,9 @@ feature 'Proposals' do within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.email).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.email.to_s + expect(page).to have_content user.document_number.to_s end fill_in 'proposal_title', with: 'Help refugees' @@ -119,9 +119,9 @@ feature 'Proposals' do within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content (user.username).to_s - expect(page).to have_content (user.email).to_s - expect(page).to have_content (user.document_number).to_s + expect(page).to have_content user.username.to_s + expect(page).to have_content user.email.to_s + expect(page).to have_content user.document_number.to_s end within(".proposals-list") do diff --git a/spec/features/management/users_spec.rb b/spec/features/management/users_spec.rb index f50728bfc..8060f33cb 100644 --- a/spec/features/management/users_spec.rb +++ b/spec/features/management/users_spec.rb @@ -29,7 +29,7 @@ feature 'Users' do expect(user).to be_level_three_verified expect(user).to be_residence_verified expect(user).to_not be_confirmed - expect(user.date_of_birth).to have_content (Date.new(1980, 12, 31)) + expect(user.date_of_birth).to have_content Date.new(1980, 12, 31) sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] visit user_confirmation_path(confirmation_token: sent_token) @@ -69,7 +69,7 @@ feature 'Users' do expect(user).to be_level_three_verified expect(user).to be_residence_verified expect(user).to be_confirmed - expect(user.date_of_birth).to have_content (Date.new(1980, 12, 31)) + expect(user.date_of_birth).to have_content Date.new(1980, 12, 31) end scenario 'Delete a level 2 user account from document verification page', :js do diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index d297a294b..1fa57890e 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1390,7 +1390,7 @@ feature 'Proposals' do check "proposal_terms_of_service" within('div#js-suggest') do - expect(page).to have_content ("You are seeing 5 of 6 proposals containing the term 'search'") + expect(page).to have_content "You are seeing 5 of 6 proposals containing the term 'search'" end end @@ -1406,7 +1406,7 @@ feature 'Proposals' do check "proposal_terms_of_service" within('div#js-suggest') do - expect(page).to_not have_content ('You are seeing') + expect(page).to_not have_content 'You are seeing' end end end diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index c363f3bdc..35ebd85d8 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -103,7 +103,7 @@ describe Budget::Investment do let(:investment) { create(:budget_investment) } it "returns the proposal id" do - expect(investment.code).to include((investment.id).to_s) + expect(investment.code).to include(investment.id.to_s) end it "returns the administrator id when assigned" do diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 8d24f9945..5ab801cd0 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -687,12 +687,12 @@ describe Debate do describe "#last_week" do it "should return debates created this week" do debate = create(:debate) - expect(Debate.last_week.all).to include (debate) + expect(Debate.last_week.all).to include debate end it "should not show debates created more than a week ago" do debate = create(:debate, created_at: 8.days.ago) - expect(Debate.last_week.all).to_not include (debate) + expect(Debate.last_week.all).to_not include debate end end diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index 9ba93b2c7..2dd6760a0 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -27,7 +27,7 @@ describe Verification::Residence do 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).to_s) + "date_of_birth(1i)" => 5.years.ago.year.to_s) expect(residence).to_not be_valid expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate") end From c5059f7292d52d653d5cd1874f885685aa9640f3 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:46:09 +0200 Subject: [PATCH 2/8] Fix Style/ParenthesesAroundCondition rubocop issues --- .rubocop_todo.yml | 9 --------- app/models/debate.rb | 2 +- app/models/proposal.rb | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7fe5ee343..1b2b7411e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -625,15 +625,6 @@ Style/ParallelAssignment: - 'lib/active_model/dates.rb' - 'spec/support/common_actions.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowSafeAssignment. -Style/ParenthesesAroundCondition: - Exclude: - - 'app/controllers/proposals_controller.rb' - - 'app/models/debate.rb' - - 'app/models/proposal.rb' - # Offense count: 11 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ diff --git a/app/models/debate.rb b/app/models/debate.rb index 9d74597b8..96c723db2 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -88,7 +88,7 @@ class Debate < ActiveRecord::Base def register_vote(user, vote_value) if votable_by?(user) - Debate.increment_counter(:cached_anonymous_votes_total, id) if (user.unverified? && !user.voted_for?(self)) + Debate.increment_counter(:cached_anonymous_votes_total, id) if user.unverified? && !user.voted_for?(self) vote_by(voter: user, vote: vote_value) end end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index f9eeecc6f..bce8b9af2 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -88,7 +88,7 @@ class Proposal < ActiveRecord::Base def self.search_by_code(terms) matched_code = match_code(terms) results = where(id: matched_code[1]) if matched_code - return results if (results.present? && results.first.code == terms) + return results if results.present? && results.first.code == terms end def self.match_code(terms) From 5129fc83a889b1371a3b5a52f5228468f6f80e64 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:47:03 +0200 Subject: [PATCH 3/8] Use next to go for next iteration instead than surrounding if --- .rubocop_todo.yml | 8 ------ .../officing/results_controller.rb | 25 +++++++++---------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b2b7411e..2cc988a87 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -583,14 +583,6 @@ Style/NestedParenthesizedCalls: - 'spec/helpers/settings_helper_spec.rb' - 'spec/helpers/verification_helper_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Exclude: - - 'app/controllers/officing/results_controller.rb' - # Offense count: 54 # Cop supports --auto-correct. # Configuration parameters: Strict. diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 65a6deac5..3ad7a91ea 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -52,20 +52,19 @@ class Officing::ResultsController < Officing::BaseController go_back_to_new if question.blank? results.each_pair do |answer_index, count| - if count.present? - answer = question.valid_answers[answer_index.to_i] - go_back_to_new if question.blank? + next unless count.present? + answer = question.valid_answers[answer_index.to_i] + go_back_to_new if question.blank? - partial_result = ::Poll::PartialResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, - date: results_params[:date], - question_id: question_id, - answer: answer) - partial_result.officer_assignment_id = @officer_assignment.id - partial_result.amount = count.to_i - partial_result.author = current_user - partial_result.origin = 'booth' - @results << partial_result - end + partial_result = ::Poll::PartialResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, + date: results_params[:date], + question_id: question_id, + answer: answer) + partial_result.officer_assignment_id = @officer_assignment.id + partial_result.amount = count.to_i + partial_result.author = current_user + partial_result.origin = 'booth' + @results << partial_result end end From ca35c8b85cabad730b48e72a070dce2fb2d2f7c9 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:47:59 +0200 Subject: [PATCH 4/8] Fix Style/NestedParenthesizedCalls rubocop issues --- .rubocop_todo.yml | 11 ----------- spec/features/debates_spec.rb | 2 +- spec/features/emails_spec.rb | 12 ++++++------ spec/features/valuation/budget_investments_spec.rb | 12 ++++++------ spec/helpers/settings_helper_spec.rb | 8 ++++---- spec/helpers/verification_helper_spec.rb | 12 ++++++------ 6 files changed, 23 insertions(+), 34 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2cc988a87..91d320dc5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -572,17 +572,6 @@ Style/MutableConstant: - 'lib/tag_sanitizer.rb' - 'lib/wysiwyg_sanitizer.rb' -# Offense count: 29 -# Cop supports --auto-correct. -Style/NestedParenthesizedCalls: - Exclude: - - 'spec/features/debates_spec.rb' - - 'spec/features/emails_spec.rb' - - 'spec/features/valuation/budget_investments_spec.rb' - - 'spec/features/valuation/spending_proposals_spec.rb' - - 'spec/helpers/settings_helper_spec.rb' - - 'spec/helpers/verification_helper_spec.rb' - # Offense count: 54 # Cop supports --auto-correct. # Configuration parameters: Strict. diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index a50363489..61210df6e 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -66,7 +66,7 @@ feature 'Debates' do first(:link, debate.title).click link_text = find_link('Go back')[:href] - expect(link_text).to include(debates_path order: :hot_score, page: 1) + expect(link_text).to include(debates_path(order: :hot_score, page: 1)) end context "Show" do diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index af7674101..21fdf8a64 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -335,9 +335,9 @@ feature 'Emails' do reset_mailer budget.email_selected - expect(find_email investment1.author.email).to be - expect(find_email investment2.author.email).to be - expect(find_email investment3.author.email).to_not be + expect(find_email(investment1.author.email)).to be + expect(find_email(investment2.author.email)).to be + expect(find_email(investment3.author.email)).to_not be email = open_last_email investment = investment2 @@ -358,9 +358,9 @@ feature 'Emails' do reset_mailer budget.email_unselected - expect(find_email investment1.author.email).to be - expect(find_email investment2.author.email).to be - expect(find_email investment3.author.email).to_not be + expect(find_email(investment1.author.email)).to be + expect(find_email(investment2.author.email)).to be + expect(find_email(investment3.author.email)).to_not be email = open_last_email investment = investment2 diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 3f91d8925..a627d9422 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -271,20 +271,20 @@ feature 'Valuation budget investments' do visit valuation_budget_budget_investment_path(@budget, @investment) click_link 'Edit dossier' - expect(find "#budget_investment_feasibility_undecided").to be_checked + expect(find("#budget_investment_feasibility_undecided")).to be_checked choose 'budget_investment_feasibility_feasible' click_button 'Save changes' visit edit_valuation_budget_budget_investment_path(@budget, @investment) - expect(find "#budget_investment_feasibility_undecided").to_not be_checked - expect(find "#budget_investment_feasibility_feasible").to be_checked + expect(find("#budget_investment_feasibility_undecided")).to_not be_checked + expect(find("#budget_investment_feasibility_feasible")).to be_checked choose 'budget_investment_feasibility_undecided' click_button 'Save changes' visit edit_valuation_budget_budget_investment_path(@budget, @investment) - expect(find "#budget_investment_feasibility_undecided").to be_checked + expect(find("#budget_investment_feasibility_undecided")).to be_checked end scenario 'Feasibility selection makes proper fields visible', :js do @@ -295,7 +295,7 @@ feature 'Valuation budget investments' do visit edit_valuation_budget_budget_investment_path(@budget, @investment) - expect(find "#budget_investment_feasibility_undecided").to be_checked + expect(find("#budget_investment_feasibility_undecided")).to be_checked undecided_fields.each do |field| expect(page).to have_content(field) @@ -325,7 +325,7 @@ feature 'Valuation budget investments' do visit edit_valuation_budget_budget_investment_path(@budget, @investment) - expect(find "#budget_investment_feasibility_unfeasible").to be_checked + expect(find("#budget_investment_feasibility_unfeasible")).to be_checked feasible_fields.each do |field| expect(page).to_not have_content(field) end diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index 0aa9b8541..0db6fed10 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -21,10 +21,10 @@ RSpec.describe SettingsHelper, type: :helper do Setting["feature.f2"] = "" Setting["feature.f3"] = nil - expect(feature? "f1").to eq("active") - expect(feature? "f2").to eq(nil) - expect(feature? "f3").to eq(nil) - expect(feature? "f4").to eq(nil) + expect(feature?("f1")).to eq("active") + expect(feature?("f2")).to eq(nil) + expect(feature?("f3")).to eq(nil) + expect(feature?("f4")).to eq(nil) end end diff --git a/spec/helpers/verification_helper_spec.rb b/spec/helpers/verification_helper_spec.rb index 1673264f7..43df6509f 100644 --- a/spec/helpers/verification_helper_spec.rb +++ b/spec/helpers/verification_helper_spec.rb @@ -4,20 +4,20 @@ describe VerificationHelper do describe "#mask_phone" do it "should mask a phone" do - expect(mask_phone "612345678").to eq("******678") + expect(mask_phone("612345678")).to eq("******678") end end describe "#mask_email" do it "should mask a long email address" do - expect(mask_email "isabel@example.com").to eq("isa***@example.com") - expect(mask_email "antonio.perez@example.com").to eq("ant**********@example.com") + expect(mask_email("isabel@example.com")).to eq("isa***@example.com") + expect(mask_email("antonio.perez@example.com")).to eq("ant**********@example.com") end it "should mask a short email address" do - expect(mask_email "an@example.com").to eq("an@example.com") - expect(mask_email "ana@example.com").to eq("ana@example.com") - expect(mask_email "aina@example.com").to eq("ain*@example.com") + expect(mask_email("an@example.com")).to eq("an@example.com") + expect(mask_email("ana@example.com")).to eq("ana@example.com") + expect(mask_email("aina@example.com")).to eq("ain*@example.com") end end From 71b57ffc6731494ad7eb9cce6674134584e5ce97 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:50:24 +0200 Subject: [PATCH 5/8] Always use parentheses on method definition --- .rubocop_todo.yml | 8 -------- spec/helpers/comments_helper_spec.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 91d320dc5..04bc1dead 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -533,14 +533,6 @@ Style/MethodCallWithoutArgsParentheses: Exclude: - 'app/controllers/management/document_verifications_controller.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline -Style/MethodDefParentheses: - Exclude: - - 'spec/helpers/comments_helper_spec.rb' - # Offense count: 1 Style/MultilineBlockChain: Exclude: diff --git a/spec/helpers/comments_helper_spec.rb b/spec/helpers/comments_helper_spec.rb index b1caabe53..040903c96 100644 --- a/spec/helpers/comments_helper_spec.rb +++ b/spec/helpers/comments_helper_spec.rb @@ -14,7 +14,7 @@ RSpec.describe CommentsHelper, type: :helper do describe '#user_level_class' do - def comment_double as_administrator: false, as_moderator: false, official: false + def comment_double(as_administrator: false, as_moderator: false, official: false) user = double official?: official, official_level: 'Y' double as_administrator?: as_administrator, as_moderator?: as_moderator, user: user end From 91fcea03b133e1a0c8733c478b5b0ad9bed65df0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:51:07 +0200 Subject: [PATCH 6/8] Remove useless parentheses on new() call --- .rubocop_todo.yml | 6 ------ .../management/document_verifications_controller.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 04bc1dead..fffae501c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -527,12 +527,6 @@ Style/Lambda: - 'app/models/vote.rb' - 'lib/graph_ql/api_types_creator.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/MethodCallWithoutArgsParentheses: - Exclude: - - 'app/controllers/management/document_verifications_controller.rb' - # Offense count: 1 Style/MultilineBlockChain: Exclude: diff --git a/app/controllers/management/document_verifications_controller.rb b/app/controllers/management/document_verifications_controller.rb index 687d8ee52..f59c00c8f 100644 --- a/app/controllers/management/document_verifications_controller.rb +++ b/app/controllers/management/document_verifications_controller.rb @@ -4,7 +4,7 @@ class Management::DocumentVerificationsController < Management::BaseController before_action :set_document, only: :check def index - @document_verification = Verification::Management::Document.new() + @document_verification = Verification::Management::Document.new end def check From 43758ba8302d97bf46d614d22349c9ebff99b49c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:52:38 +0200 Subject: [PATCH 7/8] Fix Style/EmptyCaseCondition rubocop issue --- .rubocop_todo.yml | 6 ------ app/models/concerns/verification.rb | 5 ++--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fffae501c..6c84e94c6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -480,12 +480,6 @@ Style/DoubleNegation: Exclude: - 'app/models/flag.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyCaseCondition: - Exclude: - - 'app/models/concerns/verification.rb' - # Offense count: 2 # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS diff --git a/app/models/concerns/verification.rb b/app/models/concerns/verification.rb index a4770117e..b8d23f594 100644 --- a/app/models/concerns/verification.rb +++ b/app/models/concerns/verification.rb @@ -55,10 +55,9 @@ module Verification end def user_type - case - when level_three_verified? + if level_three_verified? :level_3_user - when level_two_verified? + elsif level_two_verified? :level_2_user else :level_1_user From 7e4d9b749bd3e1351c4440a62a3d38d5b390e29e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:53:15 +0200 Subject: [PATCH 8/8] Fix Style/ColonMethodCall rubocop issues --- .rubocop_todo.yml | 6 ------ spec/models/budget/investment_spec.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6c84e94c6..f8d4bb811 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -454,12 +454,6 @@ Style/ClassVars: - 'app/models/organization.rb' - 'app/models/user.rb' -# Offense count: 6 -# Cop supports --auto-correct. -Style/ColonMethodCall: - Exclude: - - 'spec/models/budget/investment_spec.rb' - # Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index 35ebd85d8..df32853ad 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -393,7 +393,7 @@ describe Budget::Investment do investment2 = create(:budget_investment, :feasible, budget: budget) investment3 = create(:budget_investment, :unfeasible, budget: budget) - results = Budget::Investment::apply_filters_and_search(budget, {}, :feasible) + results = Budget::Investment.apply_filters_and_search(budget, {}, :feasible) expect(results).to include investment1 expect(results).to include investment2 @@ -405,7 +405,7 @@ describe Budget::Investment do investment2 = create(:budget_investment, :unfeasible, budget: budget) investment3 = create(:budget_investment, :feasible, budget: budget) - results = Budget::Investment::apply_filters_and_search(budget, {}, :unfeasible) + results = Budget::Investment.apply_filters_and_search(budget, {}, :unfeasible) expect(results).to include investment1 expect(results).to include investment2 @@ -419,7 +419,7 @@ describe Budget::Investment do investment2 = create(:budget_investment, :feasible, :selected, budget: budget) investment3 = create(:budget_investment, :feasible, :unselected, budget: budget) - results = Budget::Investment::apply_filters_and_search(budget, {}, :selected) + results = Budget::Investment.apply_filters_and_search(budget, {}, :selected) expect(results).to include investment1 expect(results).to include investment2 @@ -433,7 +433,7 @@ describe Budget::Investment do investment2 = create(:budget_investment, :feasible, :unselected, budget: budget) investment3 = create(:budget_investment, :feasible, :selected, budget: budget) - results = Budget::Investment::apply_filters_and_search(budget, {}, :unselected) + results = Budget::Investment.apply_filters_and_search(budget, {}, :unselected) expect(results).to include investment1 expect(results).to include investment2 @@ -450,7 +450,7 @@ describe Budget::Investment do investment2 = create(:budget_investment, heading: heading1, budget: budget) investment3 = create(:budget_investment, heading: heading2, budget: budget) - results = Budget::Investment::apply_filters_and_search(budget, heading_id: heading1.id) + results = Budget::Investment.apply_filters_and_search(budget, heading_id: heading1.id) expect(results).to include investment1 expect(results).to include investment2 @@ -462,7 +462,7 @@ describe Budget::Investment do investment2 = create(:budget_investment, title: "improved health", budget: budget) investment3 = create(:budget_investment, title: "finance", budget: budget) - results = Budget::Investment::apply_filters_and_search(budget, search: "health") + results = Budget::Investment.apply_filters_and_search(budget, search: "health") expect(results).to include investment1 expect(results).to include investment2