diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 1581764bf..d11706012 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -26,7 +26,9 @@ module CheckAnswersHelper def condition_not_met(case_log, question_key, question, condition) case question["type"] when "numeric" + # rubocop:disable Security/Eval case_log[question_key].blank? || !eval(case_log[question_key].to_s + condition) + # rubocop:enable Security/Eval when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) else diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 2dee5539f..42cc71154 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -7,7 +7,7 @@ RSpec.describe CheckAnswersHelper do :case_log, :in_progress, household_number_of_other_members: 2, - person_2_relationship: "Partner" + person_2_relationship: "Partner", ) end let(:case_log_with_met_radio_condition) do @@ -83,19 +83,18 @@ RSpec.describe CheckAnswersHelper do context "conditional questions with type that hasn't been implemented yet" do let(:unimplemented_conditional) do - {"question_1"=> - {"header"=>"The actual question?", - "hint_text"=>"", - "type"=>"date", - "check_answer_label"=>"Question Label", - "conditional_for"=>{"question_2"=>["12-12-2021"]}}, - "question_2"=> - {"header"=>"The second actual question?", - "hint_text"=>"", - "type"=>"radio", - "check_answer_label"=>"The second question label", - "answer_options"=>{"0"=>"Yes", "1"=>"No"}} - } + { "question_1" => + { "header" => "The actual question?", + "hint_text" => "", + "type" => "date", + "check_answer_label" => "Question Label", + "conditional_for" => { "question_2" => %w[12-12-2021] } }, + "question_2" => + { "header" => "The second actual question?", + "hint_text" => "", + "type" => "radio", + "check_answer_label" => "The second question label", + "answer_options" => { "0" => "Yes", "1" => "No" } } } end it "raises an error" do