From 5129fc83a889b1371a3b5a52f5228468f6f80e64 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 25 Sep 2017 22:47:03 +0200 Subject: [PATCH] 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