Merge pull request #1922 from consul/rubocop

Rubocop 🤖  Cleanup
This commit is contained in:
BertoCQ
2017-09-26 10:19:47 +02:00
committed by GitHub
26 changed files with 95 additions and 156 deletions

View File

@@ -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.
@@ -480,12 +474,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
@@ -527,20 +515,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
# 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:
@@ -572,25 +546,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: 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.
@@ -625,15 +580,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_
@@ -668,11 +614,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.

View File

@@ -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']

View File

@@ -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(

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -24,7 +24,7 @@ module Graphqlable
end
def graphql_type_description
(model_name.human).to_s
model_name.human.to_s
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
@@ -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

View File

@@ -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

View File

@@ -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