From f822077ffd06d37d28181925669fb797c9f63018 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:16:44 +0100 Subject: [PATCH 01/52] Fail fast if next_node not in permitted_next_nodes TODO: Expand this commit message. Consider moving this commit after all the commits to add the relevant permitted_next_nodes statements --- lib/smart_answer/question/base.rb | 3 +++ test/unit/question_base_test.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/smart_answer/question/base.rb b/lib/smart_answer/question/base.rb index 8d0b6a8abe1..225dc76b499 100644 --- a/lib/smart_answer/question/base.rb +++ b/lib/smart_answer/question/base.rb @@ -44,6 +44,9 @@ def next_node_for(current_state, input) next_node = next_node_from_function_chain(current_state, input) || next_node_from_default_function(current_state, input) responses_and_input = current_state.responses + [input] raise NextNodeUndefined.new("Next node undefined. Node: #{current_state.current_node}. Responses: #{responses_and_input}") unless next_node + unless @permitted_next_nodes.include?(next_node) + raise "Next node (#{next_node}) not in list of permitted next nodes (#{@permitted_next_nodes.join(', ')})" + end next_node end diff --git a/test/unit/question_base_test.rb b/test/unit/question_base_test.rb index 5d1d7d948d3..d956c3a4e5e 100644 --- a/test/unit/question_base_test.rb +++ b/test/unit/question_base_test.rb @@ -3,6 +3,20 @@ require_relative '../test_helper' class QuestionBaseTest < ActiveSupport::TestCase + test "#next_node_for raises an exception when the next node isn't in the list of permitted next nodes" do + q = SmartAnswer::Question::Base.new(flow = nil, :question_name) { + permitted_next_nodes :allowed_next_node_1, :allowed_next_node_2 + next_node { :not_allowed_next_node } + } + state = SmartAnswer::State.new(q.name) + + expected_message = "Next node (not_allowed_next_node) not in list of permitted next nodes (allowed_next_node_1, allowed_next_node_2)" + exception = assert_raises do + q.next_node_for(state, 'response') + end + assert_equal expected_message, exception.message + end + test "State is carried over on a state transition" do q = SmartAnswer::Question::Base.new(nil, :example) { next_node :done From 564cfc645c90e556528533f27f29f8a93fa0fe84 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:18:09 +0100 Subject: [PATCH 02/52] Use permitted_next_nodes in additional-commodity-code --- lib/smart_answer_flows/additional-commodity-code.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/smart_answer_flows/additional-commodity-code.rb b/lib/smart_answer_flows/additional-commodity-code.rb index d5b3a7c82b3..48086b58a59 100644 --- a/lib/smart_answer_flows/additional-commodity-code.rb +++ b/lib/smart_answer_flows/additional-commodity-code.rb @@ -17,6 +17,11 @@ def define save_input_as :starch_glucose_weight + permitted_next_nodes :how_much_sucrose_1?, + :how_much_sucrose_2?, + :how_much_sucrose_3?, + :how_much_sucrose_4? + next_node do |response| case response.to_i when 25 @@ -90,6 +95,13 @@ def define save_input_as :milk_fat_weight + permitted_next_nodes :commodity_code_result, + :how_much_milk_protein_ab?, + :how_much_milk_protein_c?, + :how_much_milk_protein_d?, + :how_much_milk_protein_ef?, + :how_much_milk_protein_gh? + next_node do |response| case response.to_i when 0, 1 From a396dff675554234e9f3dc095991cceeb8e6c506 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:26:33 +0100 Subject: [PATCH 03/52] Update checksum data for additional-commodity-code Updated using: $ rails r script/generate-checksums-for-smart-answer.rb \ additional-commodity-code --- test/data/additional-commodity-code-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/additional-commodity-code-files.yml b/test/data/additional-commodity-code-files.yml index 9942d07f0e6..0c1585160c7 100644 --- a/test/data/additional-commodity-code-files.yml +++ b/test/data/additional-commodity-code-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/additional-commodity-code.rb: a824498493048a251eefac4c2cbc97fb +lib/smart_answer_flows/additional-commodity-code.rb: f2b488037603da26d98d64dae0c17c0a lib/smart_answer_flows/locales/en/additional-commodity-code.yml: 417fd0ca1fc4cfb449d334e8c03c0622 test/data/additional-commodity-code-questions-and-responses.yml: f2149cbfa6ec8c5ead572f0a89542a79 test/data/additional-commodity-code-responses-and-expected-results.yml: 6ca51c22f472dbe159ac81f31006a7b1 From e62601c6e62bbf544ac255c6283dffda6716cd93 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:23:51 +0100 Subject: [PATCH 04/52] Use permitted_next_nodes in minimum-wage --- .../shared_logic/minimum_wage.rb | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/smart_answer_flows/shared_logic/minimum_wage.rb b/lib/smart_answer_flows/shared_logic/minimum_wage.rb index f4edf73523e..d7d0cef2577 100644 --- a/lib/smart_answer_flows/shared_logic/minimum_wage.rb +++ b/lib/smart_answer_flows/shared_logic/minimum_wage.rb @@ -3,6 +3,9 @@ option "current_payment" option "past_payment" + permitted_next_nodes :are_you_an_apprentice?, + :past_payment_date? + next_node do |response| case response when 'current_payment' @@ -27,6 +30,8 @@ option "2009-10-01" option "2008-10-01" + permitted_next_nodes :were_you_an_apprentice? + next_node do |response| calculator.date = Date.parse(response) :were_you_an_apprentice? @@ -40,6 +45,9 @@ option "apprentice_over_19_first_year" option "apprentice_over_19_second_year_onwards" + permitted_next_nodes :how_old_are_you?, + :how_often_do_you_get_paid? + next_node do |response| case response when 'not_an_apprentice', 'apprentice_over_19_second_year_onwards' @@ -58,6 +66,10 @@ option "apprentice_under_19" option "apprentice_over_19" + permitted_next_nodes :how_old_were_you?, + :how_often_did_you_get_paid?, + :does_not_apply_to_historical_apprentices + next_node do |response| case response when "no" @@ -80,6 +92,9 @@ calculator.valid_age?(response) end + permitted_next_nodes :under_school_leaving_age, + :how_often_do_you_get_paid? + next_node do |response| calculator.age = response if calculator.under_school_leaving_age? @@ -96,6 +111,9 @@ calculator.valid_age?(response) end + permitted_next_nodes :under_school_leaving_age_past, + :how_often_did_you_get_paid? + next_node do |response| calculator.age = response if calculator.under_school_leaving_age? @@ -112,6 +130,8 @@ calculator.valid_pay_frequency?(response) end + permitted_next_nodes :how_many_hours_do_you_work? + next_node do |response| calculator.pay_frequency = response :how_many_hours_do_you_work? @@ -124,6 +144,8 @@ calculator.valid_pay_frequency?(response) end + permitted_next_nodes :how_many_hours_did_you_work? + next_node do |response| calculator.pay_frequency = response :how_many_hours_did_you_work? @@ -136,6 +158,8 @@ calculator.valid_hours_worked?(response) end + permitted_next_nodes :how_much_are_you_paid_during_pay_period? + next_node do |response| calculator.basic_hours = response :how_much_are_you_paid_during_pay_period? @@ -148,6 +172,8 @@ calculator.valid_hours_worked?(response) end + permitted_next_nodes :how_much_were_you_paid_during_pay_period? + next_node do |response| calculator.basic_hours = response :how_much_were_you_paid_during_pay_period? @@ -156,6 +182,8 @@ # Q6 money_question :how_much_are_you_paid_during_pay_period? do + permitted_next_nodes :how_many_hours_overtime_do_you_work? + next_node do |response| calculator.basic_pay = Float(response) :how_many_hours_overtime_do_you_work? @@ -164,6 +192,8 @@ # Q6 Past money_question :how_much_were_you_paid_during_pay_period? do + permitted_next_nodes :how_many_hours_overtime_did_you_work? + next_node do |response| calculator.basic_pay = Float(response) :how_many_hours_overtime_did_you_work? @@ -176,6 +206,9 @@ calculator.valid_overtime_hours_worked?(response) end + permitted_next_nodes :what_is_overtime_pay_per_hour?, + :is_provided_with_accommodation? + next_node do |response| calculator.overtime_hours = response if calculator.any_overtime_hours_worked? @@ -192,6 +225,9 @@ calculator.valid_overtime_hours_worked?(response) end + permitted_next_nodes :what_was_overtime_pay_per_hour?, + :was_provided_with_accommodation? + next_node do |response| calculator.overtime_hours = response if calculator.any_overtime_hours_worked? @@ -204,6 +240,8 @@ # Q8 money_question :what_is_overtime_pay_per_hour? do + permitted_next_nodes :is_provided_with_accommodation? + next_node do |response| calculator.overtime_hourly_rate = Float(response) :is_provided_with_accommodation? @@ -212,6 +250,8 @@ # Q8 Past money_question :what_was_overtime_pay_per_hour? do + permitted_next_nodes :was_provided_with_accommodation? + next_node do |response| calculator.overtime_hourly_rate = Float(response) :was_provided_with_accommodation? @@ -224,6 +264,11 @@ option "yes_free" option "yes_charged" + permitted_next_nodes :current_accommodation_usage?, + :current_accommodation_charge?, + :current_payment_above, + :current_payment_below + next_node do |response| case response when "yes_free" @@ -246,6 +291,11 @@ option "yes_free" option "yes_charged" + permitted_next_nodes :past_accommodation_usage?, + :past_accommodation_charge?, + :past_payment_above, + :past_payment_below + next_node do |response| case response when "yes_free" @@ -290,6 +340,9 @@ calculator.valid_accommodation_usage?(response) end + permitted_next_nodes :current_payment_above, + :current_payment_below + next_node do |response| calculator.accommodation_adjustment(accommodation_charge, response) if calculator.minimum_wage_or_above? @@ -306,6 +359,9 @@ calculator.valid_accommodation_usage?(response) end + permitted_next_nodes :past_payment_above, + :past_payment_below + next_node do |response| calculator.accommodation_adjustment(accommodation_charge, response) if calculator.historically_receiving_minimum_wage? From 1e00d389ee27e5c7abe730f57dffb41c7b7df52b Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:24:58 +0100 Subject: [PATCH 05/52] Update checksum data for minimum-wage Updated using: $ rails r script/generate-checksums-for-smart-answer.rb \ am-i-getting-minimum-wage $ rails r script/generate-checksums-for-smart-answer.rb \ minimum-wage-calculator-employers --- test/data/am-i-getting-minimum-wage-files.yml | 2 +- test/data/minimum-wage-calculator-employers-files.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data/am-i-getting-minimum-wage-files.yml b/test/data/am-i-getting-minimum-wage-files.yml index e997fbe159a..67e031bfa37 100644 --- a/test/data/am-i-getting-minimum-wage-files.yml +++ b/test/data/am-i-getting-minimum-wage-files.yml @@ -12,6 +12,6 @@ lib/smart_answer_flows/am-i-getting-minimum-wage/past_payment_below.govspeak.erb lib/smart_answer_flows/am-i-getting-minimum-wage/under_school_leaving_age.govspeak.erb: 44bf68757d1ef90249d19f5d88ad4bc2 lib/smart_answer_flows/am-i-getting-minimum-wage/under_school_leaving_age_past.govspeak.erb: 2182c103915b753894722760c9a56cf3 lib/smart_answer_flows/shared/minimum_wage/_acas_information.govspeak.erb: 0d2f7c4d01e3c928701e7d649663707e -lib/smart_answer_flows/shared_logic/minimum_wage.rb: a92ebb84563f1f6d8f85e0d6ededa868 +lib/smart_answer_flows/shared_logic/minimum_wage.rb: 175697d7f2bb5642f3ee991c620337d4 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 diff --git a/test/data/minimum-wage-calculator-employers-files.yml b/test/data/minimum-wage-calculator-employers-files.yml index 5e4a892c00d..b2f91d7c22c 100644 --- a/test/data/minimum-wage-calculator-employers-files.yml +++ b/test/data/minimum-wage-calculator-employers-files.yml @@ -12,6 +12,6 @@ lib/smart_answer_flows/minimum-wage-calculator-employers/past_payment_below.govs lib/smart_answer_flows/minimum-wage-calculator-employers/under_school_leaving_age.govspeak.erb: 13de5d10bbbb015df597f78c66da1b67 lib/smart_answer_flows/minimum-wage-calculator-employers/under_school_leaving_age_past.govspeak.erb: 9c56f76e04984f07627efbc1f42b2b63 lib/smart_answer_flows/shared/minimum_wage/_acas_information.govspeak.erb: 0d2f7c4d01e3c928701e7d649663707e -lib/smart_answer_flows/shared_logic/minimum_wage.rb: a92ebb84563f1f6d8f85e0d6ededa868 +lib/smart_answer_flows/shared_logic/minimum_wage.rb: 175697d7f2bb5642f3ee991c620337d4 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 From 390dfffc221e620d4201c8e98b87723d26720f83 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:37:53 +0100 Subject: [PATCH 06/52] Use permitted_next_nodes in benefit-cap-calculator --- .../benefit-cap-calculator.rb | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/lib/smart_answer_flows/benefit-cap-calculator.rb b/lib/smart_answer_flows/benefit-cap-calculator.rb index 20901e11e0c..afa285750fa 100644 --- a/lib/smart_answer_flows/benefit-cap-calculator.rb +++ b/lib/smart_answer_flows/benefit-cap-calculator.rb @@ -13,6 +13,9 @@ def define save_input_as :housing_benefit + permitted_next_nodes :working_tax_credit?, + :outcome_not_affected_no_housing_benefit + next_node do |response| if response == 'yes' :working_tax_credit? @@ -27,6 +30,9 @@ def define option :yes option :no + permitted_next_nodes :outcome_not_affected_exemptions, + :receiving_exemption_benefits? + next_node do |response| if response == 'yes' :outcome_not_affected_exemptions @@ -41,6 +47,9 @@ def define option :yes option :no + permitted_next_nodes :outcome_not_affected_exemptions, + :receiving_non_exemption_benefits? + next_node do |response| if response == 'yes' :outcome_not_affected_exemptions @@ -84,6 +93,25 @@ def define 0 end + permitted_next_nodes :outcome_not_affected, + :bereavement_amount?, + :carers_amount?, + :child_benefit_amount?, + :child_tax_amount?, + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do |response| first_value = response.split(",").first if response == "none" @@ -101,6 +129,23 @@ def define total_benefits + response.to_f end + permitted_next_nodes :carers_amount?, + :child_benefit_amount?, + :child_tax_amount?, + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -113,6 +158,22 @@ def define total_benefits + response.to_f end + permitted_next_nodes :child_benefit_amount?, + :child_tax_amount?, + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -125,6 +186,21 @@ def define total_benefits + response.to_f end + permitted_next_nodes :child_tax_amount?, + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -137,6 +213,20 @@ def define total_benefits + response.to_f end + permitted_next_nodes :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -149,6 +239,19 @@ def define total_benefits + response.to_f end + permitted_next_nodes :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -161,6 +264,18 @@ def define total_benefits + response.to_f end + permitted_next_nodes :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -173,6 +288,17 @@ def define total_benefits + response.to_f end + permitted_next_nodes :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -185,6 +311,16 @@ def define total_benefits + response.to_f end + permitted_next_nodes :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -197,6 +333,15 @@ def define total_benefits + response.to_f end + permitted_next_nodes :maternity_amount?, + :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -209,6 +354,14 @@ def define total_benefits + response.to_f end + permitted_next_nodes :sda_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -221,6 +374,13 @@ def define total_benefits + response.to_f end + permitted_next_nodes :widowed_mother_amount?, + :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -233,6 +393,12 @@ def define total_benefits + response.to_f end + permitted_next_nodes :widowed_parent_amount?, + :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -245,6 +411,11 @@ def define total_benefits + response.to_f end + permitted_next_nodes :widow_pension_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -257,6 +428,10 @@ def define total_benefits + response.to_f end + permitted_next_nodes :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -269,6 +444,9 @@ def define total_benefits + response.to_f end + permitted_next_nodes :housing_benefit_amount?, + :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -283,6 +461,8 @@ def define total_benefits + response.to_f end + permitted_next_nodes :single_couple_lone_parent? + next_node do benefit_related_questions.shift end @@ -303,6 +483,9 @@ def define sprintf("%.2f", benefit_cap) end + permitted_next_nodes :outcome_affected_greater_than_cap, + :outcome_not_affected_less_than_cap + next_node do |response| if response == 'single' cap = 350 From aa5b4de3c8ba4fa8422b2ba6de823f19e346df3d Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Mon, 12 Oct 2015 17:38:38 +0100 Subject: [PATCH 07/52] Update checksum data for benefit-cap-calculator Updated using: $ rails r script/generate-checksums-for-smart-answer.rb \ benefit-cap-calculator --- test/data/benefit-cap-calculator-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/benefit-cap-calculator-files.yml b/test/data/benefit-cap-calculator-files.yml index f944e8170b6..9a0489f4175 100644 --- a/test/data/benefit-cap-calculator-files.yml +++ b/test/data/benefit-cap-calculator-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/benefit-cap-calculator.rb: acc7833e5ea23ff3349753991fb6bb1e +lib/smart_answer_flows/benefit-cap-calculator.rb: 547e3bc568869405cd247ed6b66df890 lib/smart_answer_flows/locales/en/benefit-cap-calculator.yml: 841fddf2c76ca5f8856979716488f9b7 test/data/benefit-cap-calculator-questions-and-responses.yml: 460336f2cf1f2acc62729ef5d831f25e test/data/benefit-cap-calculator-responses-and-expected-results.yml: 19c0bc207cde0d94c76b769b0da5d0bd From 9f5bff4dd2707426b95f1eb2b6afa281fc6fc287 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 12:34:53 +0100 Subject: [PATCH 08/52] Pass permitted_next_nodes to next_node --- lib/smart_answer/question/base.rb | 6 +++++- test/unit/question_base_test.rb | 20 +++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/smart_answer/question/base.rb b/lib/smart_answer/question/base.rb index 225dc76b499..a932038e1d4 100644 --- a/lib/smart_answer/question/base.rb +++ b/lib/smart_answer/question/base.rb @@ -15,8 +15,12 @@ def initialize(flow, name, options = {}, &block) super end - def next_node(next_node = nil, &block) + def next_node(next_node = nil, permitted: [], &block) if block_given? + unless permitted.any? + raise "You must specify the permitted next nodes" + end + @permitted_next_nodes += permitted @default_next_node_function = block elsif next_node next_node_if(next_node) diff --git a/test/unit/question_base_test.rb b/test/unit/question_base_test.rb index d956c3a4e5e..92ff1e0f9d1 100644 --- a/test/unit/question_base_test.rb +++ b/test/unit/question_base_test.rb @@ -5,8 +5,8 @@ class QuestionBaseTest < ActiveSupport::TestCase test "#next_node_for raises an exception when the next node isn't in the list of permitted next nodes" do q = SmartAnswer::Question::Base.new(flow = nil, :question_name) { - permitted_next_nodes :allowed_next_node_1, :allowed_next_node_2 - next_node { :not_allowed_next_node } + permitted_next_nodes = [:allowed_next_node_1, :allowed_next_node_2] + next_node(permitted: permitted_next_nodes) { :not_allowed_next_node } } state = SmartAnswer::State.new(q.name) @@ -48,8 +48,8 @@ class QuestionBaseTest < ActiveSupport::TestCase test "Can define next_node by giving a block, provided that next node is declared" do q = SmartAnswer::Question::Base.new(nil, :example) { - next_node { :done_done } - permitted_next_nodes(:done_done) + permitted_next_nodes = [:done_done] + next_node(permitted: permitted_next_nodes) { :done_done } } initial_state = SmartAnswer::State.new(q.name) new_state = q.transition(initial_state, :anything) @@ -58,10 +58,10 @@ class QuestionBaseTest < ActiveSupport::TestCase test "next_node block can refer to state" do q = SmartAnswer::Question::Base.new(nil, :example) { - next_node do + permitted_next_nodes = [:was_red, :wasnt_red] + next_node(permitted: permitted_next_nodes) do colour == 'red' ? :was_red : :wasnt_red end - permitted_next_nodes(:was_red, :wasnt_red) } initial_state = SmartAnswer::State.new(q.name) initial_state.colour = 'red' @@ -72,11 +72,10 @@ class QuestionBaseTest < ActiveSupport::TestCase test "next_node block is passed input" do input_was = nil q = SmartAnswer::Question::Base.new(nil, :example) { - next_node(:done) do |input| + next_node(permitted: [:done]) do |input| input_was = input :done end - permitted_next_nodes(:done) } initial_state = SmartAnswer::State.new(q.name) new_state = q.transition(initial_state, 'something') @@ -207,8 +206,7 @@ class QuestionBaseTest < ActiveSupport::TestCase test "next_node block used as fallback" do q = SmartAnswer::Question::Base.new(nil, :example) { next_node_if(:skipped) { false } - next_node { :next } - permitted_next_nodes(:next) + next_node(permitted: [:next]) { :next } } initial_state = SmartAnswer::State.new(q.name) assert_equal :next, q.next_node_for(initial_state, :red) @@ -217,7 +215,7 @@ class QuestionBaseTest < ActiveSupport::TestCase test "conditional next_node used if triggered ignoring fallback" do q = SmartAnswer::Question::Base.new(nil, :example) { next_node_if(:next) { true } - next_node { :ignored } + next_node(permitted: [:ignored]) { :ignored } } initial_state = SmartAnswer::State.new(q.name) assert_equal :next, q.next_node_for(initial_state, :red) From 3b494c330539acb6c7e66c9f03b23a30a5ae68ce Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 12:35:05 +0100 Subject: [PATCH 09/52] Use permitted option in additional-commodity-code --- lib/smart_answer_flows/additional-commodity-code.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/smart_answer_flows/additional-commodity-code.rb b/lib/smart_answer_flows/additional-commodity-code.rb index 48086b58a59..fafe22c7698 100644 --- a/lib/smart_answer_flows/additional-commodity-code.rb +++ b/lib/smart_answer_flows/additional-commodity-code.rb @@ -17,12 +17,14 @@ def define save_input_as :starch_glucose_weight - permitted_next_nodes :how_much_sucrose_1?, + permitted_next_nodes = [ + :how_much_sucrose_1?, :how_much_sucrose_2?, :how_much_sucrose_3?, :how_much_sucrose_4? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response.to_i when 25 :how_much_sucrose_2? @@ -95,14 +97,16 @@ def define save_input_as :milk_fat_weight - permitted_next_nodes :commodity_code_result, + permitted_next_nodes = [ + :commodity_code_result, :how_much_milk_protein_ab?, :how_much_milk_protein_c?, :how_much_milk_protein_d?, :how_much_milk_protein_ef?, :how_much_milk_protein_gh? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response.to_i when 0, 1 :how_much_milk_protein_ab? From 4eafdd59978a0a7b2d10d35d11c4164fdc7899dc Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 14:21:05 +0100 Subject: [PATCH 10/52] Update checksum data for additional-commodity-code --- test/data/additional-commodity-code-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/additional-commodity-code-files.yml b/test/data/additional-commodity-code-files.yml index 0c1585160c7..42553ca5929 100644 --- a/test/data/additional-commodity-code-files.yml +++ b/test/data/additional-commodity-code-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/additional-commodity-code.rb: f2b488037603da26d98d64dae0c17c0a +lib/smart_answer_flows/additional-commodity-code.rb: 3408534464ca7ba7317bb02f73497f2e lib/smart_answer_flows/locales/en/additional-commodity-code.yml: 417fd0ca1fc4cfb449d334e8c03c0622 test/data/additional-commodity-code-questions-and-responses.yml: f2149cbfa6ec8c5ead572f0a89542a79 test/data/additional-commodity-code-responses-and-expected-results.yml: 6ca51c22f472dbe159ac81f31006a7b1 From b8df92dd67a35f2e71c6e9dadb69489bd54960d6 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 14:26:04 +0100 Subject: [PATCH 11/52] Use permitted option in minimum-wage --- .../shared_logic/minimum_wage.rb | 102 +++++++++++------- 1 file changed, 62 insertions(+), 40 deletions(-) diff --git a/lib/smart_answer_flows/shared_logic/minimum_wage.rb b/lib/smart_answer_flows/shared_logic/minimum_wage.rb index d7d0cef2577..bcb863a12e3 100644 --- a/lib/smart_answer_flows/shared_logic/minimum_wage.rb +++ b/lib/smart_answer_flows/shared_logic/minimum_wage.rb @@ -3,10 +3,12 @@ option "current_payment" option "past_payment" - permitted_next_nodes :are_you_an_apprentice?, + permitted_next_nodes =[ + :are_you_an_apprentice?, :past_payment_date? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response when 'current_payment' :are_you_an_apprentice? @@ -30,9 +32,9 @@ option "2009-10-01" option "2008-10-01" - permitted_next_nodes :were_you_an_apprentice? + permitted_next_nodes = [:were_you_an_apprentice?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.date = Date.parse(response) :were_you_an_apprentice? end @@ -45,10 +47,12 @@ option "apprentice_over_19_first_year" option "apprentice_over_19_second_year_onwards" - permitted_next_nodes :how_old_are_you?, + permitted_next_nodes = [ + :how_old_are_you?, :how_often_do_you_get_paid? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response when 'not_an_apprentice', 'apprentice_over_19_second_year_onwards' calculator.is_apprentice = false @@ -66,11 +70,13 @@ option "apprentice_under_19" option "apprentice_over_19" - permitted_next_nodes :how_old_were_you?, + permitted_next_nodes = [ + :how_old_were_you?, :how_often_did_you_get_paid?, :does_not_apply_to_historical_apprentices + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response when "no" calculator.is_apprentice = false @@ -92,10 +98,12 @@ calculator.valid_age?(response) end - permitted_next_nodes :under_school_leaving_age, + permitted_next_nodes = [ + :under_school_leaving_age, :how_often_do_you_get_paid? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.age = response if calculator.under_school_leaving_age? :under_school_leaving_age @@ -111,10 +119,12 @@ calculator.valid_age?(response) end - permitted_next_nodes :under_school_leaving_age_past, + permitted_next_nodes = [ + :under_school_leaving_age_past, :how_often_did_you_get_paid? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.age = response if calculator.under_school_leaving_age? :under_school_leaving_age_past @@ -130,9 +140,9 @@ calculator.valid_pay_frequency?(response) end - permitted_next_nodes :how_many_hours_do_you_work? + permitted_next_nodes = [:how_many_hours_do_you_work?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.pay_frequency = response :how_many_hours_do_you_work? end @@ -144,9 +154,9 @@ calculator.valid_pay_frequency?(response) end - permitted_next_nodes :how_many_hours_did_you_work? + permitted_next_nodes = [:how_many_hours_did_you_work?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.pay_frequency = response :how_many_hours_did_you_work? end @@ -158,9 +168,9 @@ calculator.valid_hours_worked?(response) end - permitted_next_nodes :how_much_are_you_paid_during_pay_period? + permitted_next_nodes = [:how_much_are_you_paid_during_pay_period?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_hours = response :how_much_are_you_paid_during_pay_period? end @@ -172,9 +182,9 @@ calculator.valid_hours_worked?(response) end - permitted_next_nodes :how_much_were_you_paid_during_pay_period? + permitted_next_nodes = [:how_much_were_you_paid_during_pay_period?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_hours = response :how_much_were_you_paid_during_pay_period? end @@ -182,9 +192,9 @@ # Q6 money_question :how_much_are_you_paid_during_pay_period? do - permitted_next_nodes :how_many_hours_overtime_do_you_work? + permitted_next_nodes = [:how_many_hours_overtime_do_you_work?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_pay = Float(response) :how_many_hours_overtime_do_you_work? end @@ -192,9 +202,9 @@ # Q6 Past money_question :how_much_were_you_paid_during_pay_period? do - permitted_next_nodes :how_many_hours_overtime_did_you_work? + permitted_next_nodes = [:how_many_hours_overtime_did_you_work?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_pay = Float(response) :how_many_hours_overtime_did_you_work? end @@ -206,10 +216,12 @@ calculator.valid_overtime_hours_worked?(response) end - permitted_next_nodes :what_is_overtime_pay_per_hour?, + permitted_next_nodes =[ + :what_is_overtime_pay_per_hour?, :is_provided_with_accommodation? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hours = response if calculator.any_overtime_hours_worked? :what_is_overtime_pay_per_hour? @@ -225,10 +237,12 @@ calculator.valid_overtime_hours_worked?(response) end - permitted_next_nodes :what_was_overtime_pay_per_hour?, + permitted_next_nodes = [ + :what_was_overtime_pay_per_hour?, :was_provided_with_accommodation? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hours = response if calculator.any_overtime_hours_worked? :what_was_overtime_pay_per_hour? @@ -240,9 +254,9 @@ # Q8 money_question :what_is_overtime_pay_per_hour? do - permitted_next_nodes :is_provided_with_accommodation? + permitted_next_nodes = [:is_provided_with_accommodation?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hourly_rate = Float(response) :is_provided_with_accommodation? end @@ -250,9 +264,9 @@ # Q8 Past money_question :what_was_overtime_pay_per_hour? do - permitted_next_nodes :was_provided_with_accommodation? + permitted_next_nodes = [:was_provided_with_accommodation?] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hourly_rate = Float(response) :was_provided_with_accommodation? end @@ -264,12 +278,14 @@ option "yes_free" option "yes_charged" - permitted_next_nodes :current_accommodation_usage?, + permitted_next_nodes = [ + :current_accommodation_usage?, :current_accommodation_charge?, :current_payment_above, :current_payment_below + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response when "yes_free" :current_accommodation_usage? @@ -291,12 +307,14 @@ option "yes_free" option "yes_charged" - permitted_next_nodes :past_accommodation_usage?, + permitted_next_nodes = [ + :past_accommodation_usage?, :past_accommodation_charge?, :past_payment_above, :past_payment_below + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| case response when "yes_free" :past_accommodation_usage? @@ -340,10 +358,12 @@ calculator.valid_accommodation_usage?(response) end - permitted_next_nodes :current_payment_above, + permitted_next_nodes = [ + :current_payment_above, :current_payment_below + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.accommodation_adjustment(accommodation_charge, response) if calculator.minimum_wage_or_above? :current_payment_above @@ -359,10 +379,12 @@ calculator.valid_accommodation_usage?(response) end - permitted_next_nodes :past_payment_above, + permitted_next_nodes = [ + :past_payment_above, :past_payment_below + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| calculator.accommodation_adjustment(accommodation_charge, response) if calculator.historically_receiving_minimum_wage? :past_payment_above From 70c2e889c866f02e18c1bd2b6d268296afb0441a Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 14:28:15 +0100 Subject: [PATCH 12/52] Update checksum data for minimum-wage Updated using: $ rails r script/generate-checksums-for-smart-answer.rb \ am-i-getting-minimum-wage $ rails r script/generate-checksums-for-smart-answer.rb \ minimum-wage-calculator-employers --- test/data/am-i-getting-minimum-wage-files.yml | 2 +- test/data/minimum-wage-calculator-employers-files.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data/am-i-getting-minimum-wage-files.yml b/test/data/am-i-getting-minimum-wage-files.yml index 67e031bfa37..8a9b90ac81c 100644 --- a/test/data/am-i-getting-minimum-wage-files.yml +++ b/test/data/am-i-getting-minimum-wage-files.yml @@ -12,6 +12,6 @@ lib/smart_answer_flows/am-i-getting-minimum-wage/past_payment_below.govspeak.erb lib/smart_answer_flows/am-i-getting-minimum-wage/under_school_leaving_age.govspeak.erb: 44bf68757d1ef90249d19f5d88ad4bc2 lib/smart_answer_flows/am-i-getting-minimum-wage/under_school_leaving_age_past.govspeak.erb: 2182c103915b753894722760c9a56cf3 lib/smart_answer_flows/shared/minimum_wage/_acas_information.govspeak.erb: 0d2f7c4d01e3c928701e7d649663707e -lib/smart_answer_flows/shared_logic/minimum_wage.rb: 175697d7f2bb5642f3ee991c620337d4 +lib/smart_answer_flows/shared_logic/minimum_wage.rb: 8c9f7af1c7fc9e333e15aa014d3aa129 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 diff --git a/test/data/minimum-wage-calculator-employers-files.yml b/test/data/minimum-wage-calculator-employers-files.yml index b2f91d7c22c..1cdfcebbc28 100644 --- a/test/data/minimum-wage-calculator-employers-files.yml +++ b/test/data/minimum-wage-calculator-employers-files.yml @@ -12,6 +12,6 @@ lib/smart_answer_flows/minimum-wage-calculator-employers/past_payment_below.govs lib/smart_answer_flows/minimum-wage-calculator-employers/under_school_leaving_age.govspeak.erb: 13de5d10bbbb015df597f78c66da1b67 lib/smart_answer_flows/minimum-wage-calculator-employers/under_school_leaving_age_past.govspeak.erb: 9c56f76e04984f07627efbc1f42b2b63 lib/smart_answer_flows/shared/minimum_wage/_acas_information.govspeak.erb: 0d2f7c4d01e3c928701e7d649663707e -lib/smart_answer_flows/shared_logic/minimum_wage.rb: 175697d7f2bb5642f3ee991c620337d4 +lib/smart_answer_flows/shared_logic/minimum_wage.rb: 8c9f7af1c7fc9e333e15aa014d3aa129 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 From 22e521e7fe45e31a8819d56bacd5bdbe96ce8bd5 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 14:32:32 +0100 Subject: [PATCH 13/52] Use permitted option in benefit-cap-calculator --- .../benefit-cap-calculator.rb | 124 ++++++++++++------ 1 file changed, 82 insertions(+), 42 deletions(-) diff --git a/lib/smart_answer_flows/benefit-cap-calculator.rb b/lib/smart_answer_flows/benefit-cap-calculator.rb index afa285750fa..09777bef860 100644 --- a/lib/smart_answer_flows/benefit-cap-calculator.rb +++ b/lib/smart_answer_flows/benefit-cap-calculator.rb @@ -13,10 +13,12 @@ def define save_input_as :housing_benefit - permitted_next_nodes :working_tax_credit?, + permitted_next_nodes = [ + :working_tax_credit?, :outcome_not_affected_no_housing_benefit + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' :working_tax_credit? else @@ -30,10 +32,12 @@ def define option :yes option :no - permitted_next_nodes :outcome_not_affected_exemptions, + permitted_next_nodes = [ + :outcome_not_affected_exemptions, :receiving_exemption_benefits? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' :outcome_not_affected_exemptions else @@ -47,10 +51,12 @@ def define option :yes option :no - permitted_next_nodes :outcome_not_affected_exemptions, + permitted_next_nodes = [ + :outcome_not_affected_exemptions, :receiving_non_exemption_benefits? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' :outcome_not_affected_exemptions else @@ -93,7 +99,8 @@ def define 0 end - permitted_next_nodes :outcome_not_affected, + permitted_next_nodes = [ + :outcome_not_affected, :bereavement_amount?, :carers_amount?, :child_benefit_amount?, @@ -111,8 +118,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| first_value = response.split(",").first if response == "none" :outcome_not_affected @@ -129,7 +137,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :carers_amount?, + permitted_next_nodes = [ + :carers_amount?, :child_benefit_amount?, :child_tax_amount?, :esa_amount?, @@ -145,8 +154,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -158,7 +168,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :child_benefit_amount?, + permitted_next_nodes = [ + :child_benefit_amount?, :child_tax_amount?, :esa_amount?, :guardian_amount?, @@ -173,8 +184,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -186,7 +198,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :child_tax_amount?, + permitted_next_nodes = [ + :child_tax_amount?, :esa_amount?, :guardian_amount?, :incapacity_amount?, @@ -200,8 +213,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -213,7 +227,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :esa_amount?, + permitted_next_nodes = [ + :esa_amount?, :guardian_amount?, :incapacity_amount?, :income_support_amount?, @@ -226,8 +241,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -239,7 +255,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :guardian_amount?, + permitted_next_nodes = [ + :guardian_amount?, :incapacity_amount?, :income_support_amount?, :jsa_amount?, @@ -251,8 +268,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -264,7 +282,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :incapacity_amount?, + permitted_next_nodes = [ + :incapacity_amount?, :income_support_amount?, :jsa_amount?, :maternity_amount?, @@ -275,8 +294,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -288,7 +308,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :income_support_amount?, + permitted_next_nodes = [ + :income_support_amount?, :jsa_amount?, :maternity_amount?, :sda_amount?, @@ -298,8 +319,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -311,7 +333,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :jsa_amount?, + permitted_next_nodes = [ + :jsa_amount?, :maternity_amount?, :sda_amount?, :widowed_mother_amount?, @@ -320,8 +343,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -333,7 +357,8 @@ def define total_benefits + response.to_f end - permitted_next_nodes :maternity_amount?, + permitted_next_nodes = [ + :maternity_amount?, :sda_amount?, :widowed_mother_amount?, :widowed_parent_amount?, @@ -341,8 +366,9 @@ def define :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -354,15 +380,17 @@ def define total_benefits + response.to_f end - permitted_next_nodes :sda_amount?, + permitted_next_nodes = [ + :sda_amount?, :widowed_mother_amount?, :widowed_parent_amount?, :widow_pension_amount?, :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -374,14 +402,16 @@ def define total_benefits + response.to_f end - permitted_next_nodes :widowed_mother_amount?, + permitted_next_nodes = [ + :widowed_mother_amount?, :widowed_parent_amount?, :widow_pension_amount?, :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -393,13 +423,15 @@ def define total_benefits + response.to_f end - permitted_next_nodes :widowed_parent_amount?, + permitted_next_nodes = [ + :widowed_parent_amount?, :widow_pension_amount?, :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -411,12 +443,14 @@ def define total_benefits + response.to_f end - permitted_next_nodes :widow_pension_amount?, + permitted_next_nodes = [ + :widow_pension_amount?, :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -428,11 +462,13 @@ def define total_benefits + response.to_f end - permitted_next_nodes :widows_aged_amount?, + permitted_next_nodes = [ + :widows_aged_amount?, :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -444,10 +480,12 @@ def define total_benefits + response.to_f end - permitted_next_nodes :housing_benefit_amount?, + permitted_next_nodes = [ + :housing_benefit_amount?, :single_couple_lone_parent? + ] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -461,9 +499,9 @@ def define total_benefits + response.to_f end - permitted_next_nodes :single_couple_lone_parent? + permitted_next_nodes = [:single_couple_lone_parent?] - next_node do + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -483,10 +521,12 @@ def define sprintf("%.2f", benefit_cap) end - permitted_next_nodes :outcome_affected_greater_than_cap, + permitted_next_nodes = [ + :outcome_affected_greater_than_cap, :outcome_not_affected_less_than_cap + ] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| if response == 'single' cap = 350 else From 5beb0c0cfe74a646b307470251929ebcbb011603 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 14:33:09 +0100 Subject: [PATCH 14/52] Update checksum data for benefit-cap-calculator --- test/data/benefit-cap-calculator-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/benefit-cap-calculator-files.yml b/test/data/benefit-cap-calculator-files.yml index 9a0489f4175..a2dc58550bc 100644 --- a/test/data/benefit-cap-calculator-files.yml +++ b/test/data/benefit-cap-calculator-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/benefit-cap-calculator.rb: 547e3bc568869405cd247ed6b66df890 +lib/smart_answer_flows/benefit-cap-calculator.rb: 9b58eff4067ee2550ec1277b3da8b2af lib/smart_answer_flows/locales/en/benefit-cap-calculator.yml: 841fddf2c76ca5f8856979716488f9b7 test/data/benefit-cap-calculator-questions-and-responses.yml: 460336f2cf1f2acc62729ef5d831f25e test/data/benefit-cap-calculator-responses-and-expected-results.yml: 19c0bc207cde0d94c76b769b0da5d0bd From 2fdeaa2264b65c4ade908ba7916665f928cce784 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 14:35:50 +0100 Subject: [PATCH 15/52] Use permitted option in redundancy-pay --- .../shared_logic/redundancy_pay.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/smart_answer_flows/shared_logic/redundancy_pay.rb b/lib/smart_answer_flows/shared_logic/redundancy_pay.rb index 45ea87300fc..e0dd2964421 100644 --- a/lib/smart_answer_flows/shared_logic/redundancy_pay.rb +++ b/lib/smart_answer_flows/shared_logic/redundancy_pay.rb @@ -49,7 +49,11 @@ raise InvalidResponse if ye.to_i > years_available ye end - next_node do |response| + permitted_next_nodes = [ + :done_no_statutory, + :weekly_pay_before_tax? + ] + next_node(permitted: permitted_next_nodes) do |response| if response.floor < 2 :done_no_statutory else @@ -79,7 +83,11 @@ calculator.number_of_weeks_entitlement end - next_node do |response| + permitted_next_nodes = [ + :done_no_statutory, + :done + ] + next_node(permitted: permitted_next_nodes) do |response| if years_employed < 2 :done_no_statutory else From e36cd4255f2fb4a126f0aae5d6359fb8ab0314f4 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:05:14 +0100 Subject: [PATCH 16/52] Use permitted option in calculate-married-couples-allowance --- .../calculate-married-couples-allowance.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/smart_answer_flows/calculate-married-couples-allowance.rb b/lib/smart_answer_flows/calculate-married-couples-allowance.rb index 5bb8c10d81e..bdb5c82dc29 100644 --- a/lib/smart_answer_flows/calculate-married-couples-allowance.rb +++ b/lib/smart_answer_flows/calculate-married-couples-allowance.rb @@ -60,7 +60,11 @@ def define validate { |response| response > 0 } - next_node do |response| + permitted_next_nodes = [ + :paying_into_a_pension?, + :husband_done + ] + next_node(permitted: permitted_next_nodes) do |response| limit = (is_before_april_changes ? 26100.0 : 27000.0) if response.to_f >= limit :paying_into_a_pension? @@ -75,7 +79,11 @@ def define validate { |response| response > 0 } - next_node do |response| + permitted_next_nodes = [ + :paying_into_a_pension?, + :highest_earner_done + ] + next_node(permitted: permitted_next_nodes) do |response| limit = (is_before_april_changes ? 26100.0 : 27000.0) if response.to_f >= limit :paying_into_a_pension? @@ -107,7 +115,11 @@ def define calculator.calculate_adjusted_net_income(income.to_f, (gross_pension_contributions.to_f || 0), (net_pension_contributions.to_f || 0), response) end - next_node do |response| + permitted_next_nodes = [ + :husband_done, + :highest_earner_done + ] + next_node(permitted: permitted_next_nodes) do |response| if income_measure == "husband" :husband_done else From fd15f5ac52dd7a2756c48051a8b599b0c2c1e0d5 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:06:11 +0100 Subject: [PATCH 17/52] Update checksum data for calculate-married-couples-allowance Updated using: rails r script/generate-checksums-for-smart-answer.rb \ calculate-married-couples-allowance --- test/data/calculate-married-couples-allowance-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/calculate-married-couples-allowance-files.yml b/test/data/calculate-married-couples-allowance-files.yml index 53105009310..fbe589f0b70 100644 --- a/test/data/calculate-married-couples-allowance-files.yml +++ b/test/data/calculate-married-couples-allowance-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/calculate-married-couples-allowance.rb: 3d7bce5378b53ef23680c2f84c2a3459 +lib/smart_answer_flows/calculate-married-couples-allowance.rb: 2d6577b929490a2d44be463be7abd031 lib/smart_answer_flows/locales/en/calculate-married-couples-allowance.yml: 4d69826e7196274c5e4f87001c441262 test/data/calculate-married-couples-allowance-questions-and-responses.yml: 1bbef5f2f30d470433bbb63f029881cd test/data/calculate-married-couples-allowance-responses-and-expected-results.yml: 3bb53e4211718b8b1b7dacfaa52f3f49 From abea785c224e865b28e4d2929e487533e3ca612f Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:07:51 +0100 Subject: [PATCH 18/52] Use permitted option in calculate-state-pension --- lib/smart_answer_flows/calculate-state-pension.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/smart_answer_flows/calculate-state-pension.rb b/lib/smart_answer_flows/calculate-state-pension.rb index 470350655a5..a326de2a254 100644 --- a/lib/smart_answer_flows/calculate-state-pension.rb +++ b/lib/smart_answer_flows/calculate-state-pension.rb @@ -20,7 +20,11 @@ def define SmartAnswer::Calculators::RatesQuery.new('state_pension').rates.weekly_rate end - next_node do |response| + permitted_next_nodes = [ + :dob_bus_pass?, + :gender? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == 'bus_pass' :dob_bus_pass? else From b189bbbb92f85e5847f85d36765efda3fff9134f Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:08:16 +0100 Subject: [PATCH 19/52] Update checksums for calculate-state-pension --- test/data/calculate-state-pension-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/calculate-state-pension-files.yml b/test/data/calculate-state-pension-files.yml index 792d31095f5..dae8fe0895e 100644 --- a/test/data/calculate-state-pension-files.yml +++ b/test/data/calculate-state-pension-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/calculate-state-pension.rb: a67c7e878b421309f2ed1e56de34c73a +lib/smart_answer_flows/calculate-state-pension.rb: e8b8b7363972770943c39dd3bfeb2158 lib/smart_answer_flows/locales/en/calculate-state-pension.yml: 80767794dcf1a1557b7d141cc66338bf test/data/calculate-state-pension-questions-and-responses.yml: 8fe4d28d6b90ff1030ed15470d5b458f test/data/calculate-state-pension-responses-and-expected-results.yml: 61e8ccba31841f6616cf8b26f3da6ff9 From 9fc65add6314bd3d01835758ee64f4768582e104 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:11:30 +0100 Subject: [PATCH 20/52] Use permitted option in calculate-your-holiday-entitlement --- .../calculate-your-holiday-entitlement.rb | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/smart_answer_flows/calculate-your-holiday-entitlement.rb b/lib/smart_answer_flows/calculate-your-holiday-entitlement.rb index 8e673e4a683..0bd585de397 100644 --- a/lib/smart_answer_flows/calculate-your-holiday-entitlement.rb +++ b/lib/smart_answer_flows/calculate-your-holiday-entitlement.rb @@ -25,7 +25,13 @@ def define option "starting-and-leaving" save_input_as :holiday_period - next_node do |response| + permitted_next_nodes = [ + :what_is_your_starting_date?, + :what_is_your_leaving_date?, + :how_many_days_per_week?, + :how_many_hours_per_week? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "starting", "starting-and-leaving" :what_is_your_starting_date? @@ -52,7 +58,12 @@ def define from { Date.civil(1.year.ago.year, 1, 1) } to { Date.civil(1.year.since(Date.today).year, 12, 31) } save_input_as :start_date - next_node do + + permitted_next_nodes = [ + :what_is_your_leaving_date?, + :when_does_your_leave_year_start? + ] + next_node(permitted: permitted_next_nodes) do if holiday_period == "starting-and-leaving" :what_is_your_leaving_date? else @@ -67,7 +78,13 @@ def define to { Date.civil(1.year.since(Date.today).year, 12, 31) } save_input_as :leaving_date - next_node do + permitted_next_nodes = [ + :how_many_days_per_week?, + :how_many_hours_per_week?, + :shift_worker_hours_per_shift?, + :when_does_your_leave_year_start? + ] + next_node(permitted: permitted_next_nodes) do if holiday_period == "starting-and-leaving" case calculation_basis when "days-worked-per-week" @@ -88,7 +105,13 @@ def define from { Date.civil(1.year.ago.year, 1, 1) } to { Date.civil(1.year.since(Date.today).year, 12, 31) } save_input_as :leave_year_start_date - next_node do + + permitted_next_nodes = [ + :how_many_days_per_week?, + :how_many_hours_per_week?, + :shift_worker_hours_per_shift? + ] + next_node(permitted: permitted_next_nodes) do case calculation_basis when "days-worked-per-week" :how_many_days_per_week? From 77f0711784eb2c7cdfdc12d40722995f133e33ca Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:11:55 +0100 Subject: [PATCH 21/52] Update checksum data for calculate-your-holiday-entitlement --- test/data/calculate-your-holiday-entitlement-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/calculate-your-holiday-entitlement-files.yml b/test/data/calculate-your-holiday-entitlement-files.yml index 0cfdf99ff91..47bb4eb416c 100644 --- a/test/data/calculate-your-holiday-entitlement-files.yml +++ b/test/data/calculate-your-holiday-entitlement-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/calculate-your-holiday-entitlement.rb: 6eec1440f4fc73734fb4d5a40861fbea +lib/smart_answer_flows/calculate-your-holiday-entitlement.rb: 2285f098692e763af45dc824079b12a5 lib/smart_answer_flows/locales/en/calculate-your-holiday-entitlement.yml: 077bcd2fa3dbbb37d18e6a176fa18d8b test/data/calculate-your-holiday-entitlement-questions-and-responses.yml: a5d687911e6173e74f2b70af6a5ff7bd test/data/calculate-your-holiday-entitlement-responses-and-expected-results.yml: b7d4735ae33ef0dceeeb97c12019db84 From fc37c58451dcb906614dcd610c837bef3aa6e21a Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:13:36 +0100 Subject: [PATCH 22/52] Use permitted option in check-uk-visa --- lib/smart_answer_flows/check-uk-visa.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/smart_answer_flows/check-uk-visa.rb b/lib/smart_answer_flows/check-uk-visa.rb index 32b3783d4c9..b88a786f35c 100644 --- a/lib/smart_answer_flows/check-uk-visa.rb +++ b/lib/smart_answer_flows/check-uk-visa.rb @@ -24,7 +24,12 @@ def define country_select :what_passport_do_you_have?, additional_countries: additional_countries, exclude_countries: exclude_countries do save_input_as :passport_country - next_node do |response| + permitted_next_nodes = [ + :israeli_document_type?, + :outcome_no_visa_needed, + :purpose_of_visit? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == 'israel' :israeli_document_type? elsif country_group_eea.include?(response) @@ -40,7 +45,8 @@ def define option :"full-passport" option :"provisional-passport" - next_node do |response| + permitted_next_nodes = [:purpose_of_visit?] + next_node(permitted: permitted_next_nodes) do |response| self.passport_country = 'israel-provisional-passport' if response == 'provisional-passport' :purpose_of_visit? end From dc40b2fdb806a409389f0f01a1a99bfd89b8b280 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:13:57 +0100 Subject: [PATCH 23/52] Update checksum data for check-uk-visa --- test/data/check-uk-visa-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/check-uk-visa-files.yml b/test/data/check-uk-visa-files.yml index b4ff7902cbb..deb052852ad 100644 --- a/test/data/check-uk-visa-files.yml +++ b/test/data/check-uk-visa-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/check-uk-visa.rb: 65e37027d0c5c4541dc7d8d60f54b741 +lib/smart_answer_flows/check-uk-visa.rb: 31e8f3fd00c2c3dd84cfbedc62893d27 lib/smart_answer_flows/locales/en/check-uk-visa.yml: a8c595b226b52e2c9b5d7b32723fbdb2 test/data/check-uk-visa-questions-and-responses.yml: b77c21b505c201c2014e17e13d52b5a0 test/data/check-uk-visa-responses-and-expected-results.yml: 603a0b14f2a49a20d01cc4b959fb90b7 From 0419fb036fa6cd9184840fde1432a9eefba11594 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:15:38 +0100 Subject: [PATCH 24/52] Use permitted option in childcare-costs-for-tax-credits --- .../childcare-costs-for-tax-credits.rb | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/smart_answer_flows/childcare-costs-for-tax-credits.rb b/lib/smart_answer_flows/childcare-costs-for-tax-credits.rb index f1b9d477020..1d4fec59bf5 100644 --- a/lib/smart_answer_flows/childcare-costs-for-tax-credits.rb +++ b/lib/smart_answer_flows/childcare-costs-for-tax-credits.rb @@ -66,7 +66,11 @@ def define SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response) end - next_node do |response| + permitted_next_nodes = [ + :no_longer_paying, + :old_weekly_amount_1? + ] + next_node(permitted: permitted_next_nodes) do |response| amount = Money.new(response) amount == 0 ? :no_longer_paying : :old_weekly_amount_1? end @@ -77,7 +81,12 @@ def define calculate :weekly_cost do |response| SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost(response) end - next_node do |response| + + permitted_next_nodes = [ + :no_longer_paying, + :old_weekly_amount_1? + ] + next_node(permitted: permitted_next_nodes) do |response| amount = Money.new(response) amount == 0 ? :no_longer_paying : :old_weekly_amount_1? end @@ -146,7 +155,12 @@ def define calculate :new_weekly_costs do |response| Float(response).ceil end - next_node do |response| + + permitted_next_nodes = [ + :no_longer_paying, + :old_weekly_amount_2? + ] + next_node(permitted: permitted_next_nodes) do |response| amount = Money.new(response) amount == 0 ? :no_longer_paying : :old_weekly_amount_2? end @@ -177,7 +191,11 @@ def define SmartAnswer::Calculators::ChildcareCostCalculator.weekly_cost_from_monthly(response) end - next_node do |response| + permitted_next_nodes = [ + :no_longer_paying, + :old_weekly_amount_3? + ] + next_node(permitted: permitted_next_nodes) do |response| amount = Money.new(response) amount == 0 ? :no_longer_paying : :old_weekly_amount_3? end From d33ad5393a514313e552aabca897cb1777e0b9e0 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:16:04 +0100 Subject: [PATCH 25/52] Update checksum data for childcare-costs-for-tax-credits --- test/data/childcare-costs-for-tax-credits-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/childcare-costs-for-tax-credits-files.yml b/test/data/childcare-costs-for-tax-credits-files.yml index b8c567144ce..bc4db873005 100644 --- a/test/data/childcare-costs-for-tax-credits-files.yml +++ b/test/data/childcare-costs-for-tax-credits-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/childcare-costs-for-tax-credits.rb: 2c5d3e00ecce939574dfa9663bf478f8 +lib/smart_answer_flows/childcare-costs-for-tax-credits.rb: b51523114c809685a8b01e8daf0fa7e6 lib/smart_answer_flows/locales/en/childcare-costs-for-tax-credits.yml: d55246739a411a6e0142b32c47e905b5 test/data/childcare-costs-for-tax-credits-questions-and-responses.yml: 136aea3591662aa753c3c630546e68ad test/data/childcare-costs-for-tax-credits-responses-and-expected-results.yml: 7d90f3446d1e2c9551d7d363fbc4d639 From df6f4705095f939c40456a759e80816e98efa4df Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:18:50 +0100 Subject: [PATCH 26/52] Use permitted option in estimate-self-assessment-penalties --- .../estimate-self-assessment-penalties.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/smart_answer_flows/estimate-self-assessment-penalties.rb b/lib/smart_answer_flows/estimate-self-assessment-penalties.rb index 7dd2191a503..26bc741de40 100644 --- a/lib/smart_answer_flows/estimate-self-assessment-penalties.rb +++ b/lib/smart_answer_flows/estimate-self-assessment-penalties.rb @@ -73,7 +73,8 @@ def define filing_date.strftime("%e %B %Y") end - next_node do |response| + permitted_next_nodes = [:when_paid?] + next_node(permitted: permitted_next_nodes) do |response| if response < start_of_next_tax_year raise SmartAnswer::InvalidResponse else @@ -88,7 +89,11 @@ def define save_input_as :payment_date - next_node do |response| + permitted_next_nodes = [ + :filed_and_paid_on_time, + :how_much_tax? + ] + next_node(permitted: permitted_next_nodes) do |response| if filing_date > response raise SmartAnswer::InvalidResponse else From a7edc2c632f2bed4e0fe576e9e31f4b62bacb8aa Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:19:23 +0100 Subject: [PATCH 27/52] Update checksum data for estimate-self-assessment-penalties --- test/data/estimate-self-assessment-penalties-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/estimate-self-assessment-penalties-files.yml b/test/data/estimate-self-assessment-penalties-files.yml index 352249b8c71..2acac60cea3 100644 --- a/test/data/estimate-self-assessment-penalties-files.yml +++ b/test/data/estimate-self-assessment-penalties-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/estimate-self-assessment-penalties.rb: c097850300a0c888c26552870b32cb66 +lib/smart_answer_flows/estimate-self-assessment-penalties.rb: 86a215cfbee1a7af475243bc10e7c1fa lib/smart_answer_flows/locales/en/estimate-self-assessment-penalties.yml: 97c0cf1ea0ce03f9012ff60ec5a02559 test/data/estimate-self-assessment-penalties-questions-and-responses.yml: 186d93854ea5dc9321408e14dcc8d61f test/data/estimate-self-assessment-penalties-responses-and-expected-results.yml: 07a0cd26b8c5e4b1fff6dfe51c20142e From b21acd083256a5153274fecbbf8103b1d5d455d4 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:20:13 +0100 Subject: [PATCH 28/52] Use permitted option in help-if-you-are-arrested-abroad --- lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb b/lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb index 40b5ec9938f..e80bfe6d887 100644 --- a/lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb +++ b/lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb @@ -77,7 +77,12 @@ def define links end - next_node do |response| + permitted_next_nodes = [ + :answer_two_iran, + :answer_three_syria, + :answer_one_generic + ] + next_node(permitted: permitted_next_nodes) do |response| if response == "iran" :answer_two_iran elsif response == "syria" From 5fe26bd961c52b2d67a63fd4ef391db0d365af20 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:20:43 +0100 Subject: [PATCH 29/52] Update checksum data for help-if-you-are-arrested-abroad --- test/data/help-if-you-are-arrested-abroad-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/help-if-you-are-arrested-abroad-files.yml b/test/data/help-if-you-are-arrested-abroad-files.yml index 2eb57c2a965..acefa861858 100644 --- a/test/data/help-if-you-are-arrested-abroad-files.yml +++ b/test/data/help-if-you-are-arrested-abroad-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb: 0d1e142d0929429219421fcab1260616 +lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb: cc7831e704176ed0a3545425c6e08f2e lib/smart_answer_flows/locales/en/help-if-you-are-arrested-abroad.yml: 8dbb908db1cb70bdf47c166d127a3703 test/data/help-if-you-are-arrested-abroad-questions-and-responses.yml: c007b0dd259d1c09ccc2dd3163fa1e56 test/data/help-if-you-are-arrested-abroad-responses-and-expected-results.yml: 26a4d487258c3984a6cd73da22c2d8e6 From d63012ef710678b44950e9b7138c04d707ffaaab Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:26:25 +0100 Subject: [PATCH 30/52] Use permitted option in landlord-immigration-check --- .../landlord-immigration-check.rb | 91 ++++++++++++++++--- 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/lib/smart_answer_flows/landlord-immigration-check.rb b/lib/smart_answer_flows/landlord-immigration-check.rb index c20a7b988b8..24e92851a51 100644 --- a/lib/smart_answer_flows/landlord-immigration-check.rb +++ b/lib/smart_answer_flows/landlord-immigration-check.rb @@ -7,7 +7,11 @@ def define satisfies_need "102373" postcode_question :property? do - next_node do |response| + permitted_next_nodes = [ + :main_home?, + :outcome_check_not_needed + ] + next_node(permitted: permitted_next_nodes) do |response| if Calculators::LandlordImmigrationCheckCalculator.valid_postcode(response) :main_home? else @@ -20,7 +24,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :tenant_over_18?, + :property_type? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :tenant_over_18? @@ -34,7 +42,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :has_uk_passport?, + :outcome_check_not_needed_when_under_18 + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :has_uk_passport? @@ -54,7 +66,17 @@ def define option "student_accommodation" option "7_year_lease_property" - next_node do |response| + permitted_next_nodes = [ + :outcome_check_not_needed_if_holiday_or_under_3_months, + :outcome_check_not_needed, + :outcome_check_not_needed_when_care_home, + :outcome_check_not_needed_when_hostel_refuge, + :outcome_check_not_needed_when_mobile_home, + :outcome_check_not_needed_when_employee_home, + :outcome_check_may_be_needed_when_student, + :outcome_check_needed_if_break_clause + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "holiday_accommodation" :outcome_check_not_needed_if_holiday_or_under_3_months @@ -80,7 +102,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent, + :right_to_abode? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent @@ -94,7 +120,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent, + :has_certificate? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent @@ -108,7 +138,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent, + :tenant_country? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent @@ -123,7 +157,12 @@ def define option "non_eea_but_with_eu_eea_switzerland_family_member" option "somewhere_else" - next_node do |response| + permitted_next_nodes = [ + :has_documents?, + :has_residence_card_or_eu_eea_swiss_family_member?, + :has_other_documents? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "eu_eea_switzerland" :has_documents? @@ -139,7 +178,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent, + :has_other_documents? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent @@ -153,7 +196,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent, + :time_limited_to_remain? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent @@ -167,7 +214,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent_for_12_months, + :immigration_application? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent_for_12_months @@ -181,7 +232,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent_but_check_will_be_needed_again, + :has_residence_card_or_eu_eea_swiss_family_member? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent_but_check_will_be_needed_again @@ -195,7 +250,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent_for_12_months, + :outcome_can_not_rent + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent_for_12_months @@ -209,7 +268,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :outcome_can_rent, + :has_asylum_card? + ] + next_node(permitted: permitted_next_nodes) do |response| case response when "yes" :outcome_can_rent From b0805e0f94d0debe7f99d17ef5ee6a4aa1a7f3e1 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:26:54 +0100 Subject: [PATCH 31/52] Update checksum data for landlord-immigration-check --- test/data/landlord-immigration-check-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/landlord-immigration-check-files.yml b/test/data/landlord-immigration-check-files.yml index 5dd2879403e..9fbd9602fe9 100644 --- a/test/data/landlord-immigration-check-files.yml +++ b/test/data/landlord-immigration-check-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/landlord-immigration-check.rb: f87297c9c751e8cd5410155fe864712a +lib/smart_answer_flows/landlord-immigration-check.rb: 2eaabee434804a3f31b17a275a84f368 lib/smart_answer_flows/locales/en/landlord-immigration-check.yml: 590064bf90819fb8cc0484d7c46d0261 test/data/landlord-immigration-check-questions-and-responses.yml: 7259b20b404af56667915a12e43d6da0 test/data/landlord-immigration-check-responses-and-expected-results.yml: 329e7752e670f0ee92bc1c671ba478a7 From 5e46745a809ef0ebd0a29ec1f4a10f5cd555b9d5 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:33:11 +0100 Subject: [PATCH 32/52] Use permitted option in part-year-profit-tax-credits --- .../part-year-profit-tax-credits.rb | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/smart_answer_flows/part-year-profit-tax-credits.rb b/lib/smart_answer_flows/part-year-profit-tax-credits.rb index 12a64e4ea34..2227794aa41 100644 --- a/lib/smart_answer_flows/part-year-profit-tax-credits.rb +++ b/lib/smart_answer_flows/part-year-profit-tax-credits.rb @@ -15,7 +15,8 @@ def define Calculators::PartYearProfitTaxCreditsCalculator.new end - next_node do |response| + permitted_next_nodes = [:what_date_do_your_accounts_go_up_to?] + next_node(permitted: permitted_next_nodes) do |response| calculator.tax_credits_award_ends_on = response :what_date_do_your_accounts_go_up_to? end @@ -24,7 +25,8 @@ def define date_question :what_date_do_your_accounts_go_up_to? do default_year { 0 } - next_node do |response| + permitted_next_nodes = [:have_you_stopped_trading?] + next_node(permitted: permitted_next_nodes) do |response| calculator.accounts_end_month_and_day = response :have_you_stopped_trading? end @@ -34,7 +36,11 @@ def define option "yes" option "no" - next_node do |response| + permitted_next_nodes = [ + :did_you_start_trading_before_the_relevant_accounting_year?, + :do_your_accounts_cover_a_12_month_period? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' calculator.stopped_trading = true :did_you_start_trading_before_the_relevant_accounting_year? @@ -51,7 +57,11 @@ def define precalculate(:accounting_year_begins_on) { calculator.accounting_year.begins_on } - next_node do |response| + permitted_next_nodes = [ + :when_did_you_stop_trading?, + :when_did_you_start_trading? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == "yes" :when_did_you_stop_trading? elsif response == "no" @@ -71,7 +81,8 @@ def define calculator.valid_stopped_trading_date?(response) end - next_node do |response| + permitted_next_nodes = [:what_is_your_taxable_profit?] + next_node(permitted: permitted_next_nodes) do |response| calculator.stopped_trading_on = response :what_is_your_taxable_profit? end @@ -83,7 +94,11 @@ def define precalculate(:accounting_year_ends_on) { calculator.accounting_year.ends_on } - next_node do |response| + permitted_next_nodes = [ + :what_is_your_taxable_profit?, + :when_did_you_start_trading? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == "yes" :what_is_your_taxable_profit? else @@ -102,7 +117,11 @@ def define calculator.valid_start_trading_date?(response) end - next_node do |response| + permitted_next_nodes = [ + :when_did_you_stop_trading?, + :what_is_your_taxable_profit? + ] + next_node(permitted: permitted_next_nodes) do |response| calculator.started_trading_on = response if calculator.stopped_trading :when_did_you_stop_trading? @@ -116,7 +135,8 @@ def define precalculate(:basis_period_begins_on) { calculator.basis_period.begins_on } precalculate(:basis_period_ends_on) { calculator.basis_period.ends_on } - next_node do |response| + permitted_next_nodes = [:result] + next_node(permitted: permitted_next_nodes) do |response| calculator.taxable_profit = response :result end From 10ced66bd00581ef413fd1facbe7e0f2a7703430 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:42:34 +0100 Subject: [PATCH 33/52] Use permitted option in pip-checker --- lib/smart_answer_flows/pip-checker.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/smart_answer_flows/pip-checker.rb b/lib/smart_answer_flows/pip-checker.rb index 088f93ec7e8..5539e5fd904 100644 --- a/lib/smart_answer_flows/pip-checker.rb +++ b/lib/smart_answer_flows/pip-checker.rb @@ -25,7 +25,15 @@ def define date_question :what_is_your_dob? do date_of_birth_defaults - next_node do |response| + permitted_next_nodes = [ + :result_1, + :result_2, + :result_3, + :result_5, + :result_6, + :result_7 + ] + next_node(permitted: permitted_next_nodes) do |response| calculator.dob = response if getting_dla if calculator.in_group_65? From 596008bf7e026b11d7ef9b62b6a4fb036ca2e922 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 15:42:57 +0100 Subject: [PATCH 34/52] Update checksum data for pip-checker --- test/data/pip-checker-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/pip-checker-files.yml b/test/data/pip-checker-files.yml index 141d6f15c53..789b23bcbe1 100644 --- a/test/data/pip-checker-files.yml +++ b/test/data/pip-checker-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/pip-checker.rb: d1e6a1262d11e9413a43f4173462a174 +lib/smart_answer_flows/pip-checker.rb: f6dcb2c011e67ec01133aa7d2f57f969 lib/smart_answer_flows/locales/en/pip-checker.yml: 985bc50d508bf8922e9de6e0703087b6 test/data/pip-checker-questions-and-responses.yml: b1d68ebfb76a9e2793705c55b82294f5 test/data/pip-checker-responses-and-expected-results.yml: a2c772b69a493d1844cfa32681057796 From 08a1c92456bae8d04f0577670c0f7b6414511999 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 16:49:58 +0100 Subject: [PATCH 35/52] Use permitted option in report-a-lost-or-stolen-passport --- lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb b/lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb index a7e4a7e22b1..012fb4644f4 100644 --- a/lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb +++ b/lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb @@ -14,7 +14,11 @@ def define save_input_as :location - next_node do + permitted_next_nodes = [ + :complete_LS01_form, + :which_country? + ] + next_node(permitted: permitted_next_nodes) do case location when 'in_the_uk' then :complete_LS01_form when 'abroad' then :which_country? From 5667e6042ff1f20d357f6e51b139b067b9cb91ee Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 16:50:53 +0100 Subject: [PATCH 36/52] Update checksum data for report-a-lost-or-stolen-passport --- test/data/report-a-lost-or-stolen-passport-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/report-a-lost-or-stolen-passport-files.yml b/test/data/report-a-lost-or-stolen-passport-files.yml index 3d9c1e44f43..129c05a4bca 100644 --- a/test/data/report-a-lost-or-stolen-passport-files.yml +++ b/test/data/report-a-lost-or-stolen-passport-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb: 6451dcf9cd6a29df60f3d272ce20d808 +lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb: 6fd91372c8982473b857f57cb6b4e540 lib/smart_answer_flows/locales/en/report-a-lost-or-stolen-passport.yml: 8bb218f43294aa0267418047f18038a6 test/data/report-a-lost-or-stolen-passport-questions-and-responses.yml: cb7d64407b737eeb4924389f3bd335c6 test/data/report-a-lost-or-stolen-passport-responses-and-expected-results.yml: 2ef8837f76907e72aadb198636a62078 From 767578533caa0e9e39a26c3474009a5871ab6869 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 16:55:06 +0100 Subject: [PATCH 37/52] Use permitted option in simplified-expenses-checker --- .../simplified-expenses-checker.rb | 64 ++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/lib/smart_answer_flows/simplified-expenses-checker.rb b/lib/smart_answer_flows/simplified-expenses-checker.rb index fde88103786..7727ecd7ed3 100644 --- a/lib/smart_answer_flows/simplified-expenses-checker.rb +++ b/lib/smart_answer_flows/simplified-expenses-checker.rb @@ -35,7 +35,13 @@ def define response == "none" ? [] : response.split(",") end - next_node do |response| + permitted_next_nodes = [ + :you_cant_use_result, + :buying_new_vehicle?, + :hours_work_home?, + :deduct_from_premises? + ] + next_node(permitted: permitted_next_nodes) do |response| next_question = nil if response == "none" :you_cant_use_result @@ -58,7 +64,12 @@ def define option :yes option :no - next_node do |response| + permitted_next_nodes = [ + :is_vehicle_green?, + :capital_allowances?, + :how_much_expect_to_claim? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == "yes" :is_vehicle_green? else @@ -86,7 +97,13 @@ def define response == "yes" and (list_of_expenses & %w(using_home_for_business live_on_business_premises)).any? end - next_node do |response| + permitted_next_nodes = [ + :hours_work_home?, + :deduct_from_premises?, + :capital_allowance_result, + :how_much_expect_to_claim? + ] + next_node(permitted: permitted_next_nodes) do |response| if response == "yes" if (list_of_expenses & %w(using_home_for_business live_on_business_premises)).any? if list_of_expenses.include?("using_home_for_business") @@ -110,7 +127,11 @@ def define money_question :how_much_expect_to_claim? do save_input_as :vehicle_costs - next_node do + permitted_next_nodes = [ + :drive_business_miles_car_van?, + :drive_business_miles_motorcycle? + ] + next_node(permitted: permitted_next_nodes) do if list_of_expenses.include?("car_or_van") :drive_business_miles_car_van? else @@ -167,7 +188,11 @@ def define vehicle_is_green ? nil : Money.new(dirty_vehicle_price * ( business_use_percent / 100)) end - next_node do |response| + permitted_next_nodes = [ + :drive_business_miles_car_van?, + :drive_business_miles_motorcycle? + ] + next_node(permitted: permitted_next_nodes) do |response| raise InvalidResponse if response.to_i > 100 list_of_expenses.include?("car_or_van") ? :drive_business_miles_car_van? : :drive_business_miles_motorcycle? @@ -188,7 +213,14 @@ def define Money.new(4500.0 + answer_over_amount) end end - next_node do + + permitted_next_nodes = [ + :drive_business_miles_motorcycle?, + :hours_work_home?, + :deduct_from_premises?, + :you_can_use_result + ] + next_node(permitted: permitted_next_nodes) do if list_of_expenses.include?("motorcycle") :drive_business_miles_motorcycle? elsif list_of_expenses.include?("using_home_for_business") @@ -206,7 +238,13 @@ def define calculate :simple_motorcycle_costs do |response| Money.new(response.gsub(",", "").to_f * 0.24) end - next_node do + + permitted_next_nodes = [ + :hours_work_home?, + :deduct_from_premises?, + :you_can_use_result + ] + next_node(permitted: permitted_next_nodes) do if list_of_expenses.include?("using_home_for_business") :hours_work_home? elsif list_of_expenses.include?("live_on_business_premises") @@ -234,7 +272,11 @@ def define Money.new(amount) end - next_node do |response| + permitted_next_nodes = [ + :you_cant_use_result, + :current_claim_amount_home? + ] + next_node(permitted: permitted_next_nodes) do |response| hours = response.to_i if hours < 1 raise SmartAnswer::InvalidResponse @@ -250,7 +292,11 @@ def define money_question :current_claim_amount_home? do save_input_as :home_costs - next_node do + permitted_next_nodes = [ + :deduct_from_premises?, + :you_can_use_result + ] + next_node(permitted: permitted_next_nodes) do list_of_expenses.include?("live_on_business_premises") ? :deduct_from_premises? : :you_can_use_result end From a2d840538efc5be37489f4833852e5c03a95fde8 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 16:55:40 +0100 Subject: [PATCH 38/52] Update checksum data for simplified-expenses-checker --- test/data/simplified-expenses-checker-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/simplified-expenses-checker-files.yml b/test/data/simplified-expenses-checker-files.yml index 98d1f1dce5d..ad0a1c8c9cc 100644 --- a/test/data/simplified-expenses-checker-files.yml +++ b/test/data/simplified-expenses-checker-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/simplified-expenses-checker.rb: 9f175300a38da904bee8bfacb26af032 +lib/smart_answer_flows/simplified-expenses-checker.rb: 08c2a1ffb98fac5e69533e1bdd0b373b lib/smart_answer_flows/locales/en/simplified-expenses-checker.yml: 92dcc0726b8a8fc148ab3aefeed6689e test/data/simplified-expenses-checker-questions-and-responses.yml: 6b1c358b3730897b6cbefa9477ada15b test/data/simplified-expenses-checker-responses-and-expected-results.yml: 983e72657f76697beafb2dcbe4018bee From 67845f5878c38edf14345978dc77baa59026608d Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 16:57:10 +0100 Subject: [PATCH 39/52] Use permitted option in student-finance-calculator --- .../student-finance-calculator.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/smart_answer_flows/student-finance-calculator.rb b/lib/smart_answer_flows/student-finance-calculator.rb index e0aed76357e..ec07bf5c730 100644 --- a/lib/smart_answer_flows/student-finance-calculator.rb +++ b/lib/smart_answer_flows/student-finance-calculator.rb @@ -38,7 +38,12 @@ def define Money.new(response) end - next_node do + permitted_next_nodes = [ + :where_will_you_live_while_studying?, + :do_any_of_the_following_apply_all_uk_students?, + :outcome_eu_students + ] + next_node(permitted: permitted_next_nodes) do case course_type when 'uk-full-time' :where_will_you_live_while_studying? @@ -119,7 +124,12 @@ def define save_input_as :course_studied - next_node do + permitted_next_nodes = [ + :outcome_uk_full_time_students, + :outcome_uk_all_students, + :outcome_eu_students + ] + next_node(permitted: permitted_next_nodes) do case course_type when 'uk-full-time' :outcome_uk_full_time_students From 34327e0726c379b2456c59f95aa6e4d2ec449133 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 16:57:47 +0100 Subject: [PATCH 40/52] Update checksum data for student-finance-calculator --- test/data/student-finance-calculator-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/student-finance-calculator-files.yml b/test/data/student-finance-calculator-files.yml index 7058bc7f101..7104ff9e40b 100644 --- a/test/data/student-finance-calculator-files.yml +++ b/test/data/student-finance-calculator-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/student-finance-calculator.rb: 3235722e11f9cd2ef9d2b29ea988c453 +lib/smart_answer_flows/student-finance-calculator.rb: 7dad8190af5f892d12312b7f9ad30d32 lib/smart_answer_flows/locales/en/student-finance-calculator.yml: c1c56f850e993f1b7dd48964ae268292 test/data/student-finance-calculator-questions-and-responses.yml: 8f68ec47644191cd01864ba288acf7ec test/data/student-finance-calculator-responses-and-expected-results.yml: 4d17ae39630843d360460ef2131c5980 From 1411df9da250f896b14e8133cfc53420feeb7727 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:03:53 +0100 Subject: [PATCH 41/52] Use permitted option in graph test flow --- test/fixtures/graph_presenter_test/graph.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/graph_presenter_test/graph.rb b/test/fixtures/graph_presenter_test/graph.rb index c515b894e75..3ee465dea95 100644 --- a/test/fixtures/graph_presenter_test/graph.rb +++ b/test/fixtures/graph_presenter_test/graph.rb @@ -13,9 +13,9 @@ def define option :a option :b - permitted_next_nodes :done_a, :done_b + permitted_next_nodes = [:done_a, :done_b] - next_node do |response| + next_node(permitted: permitted_next_nodes) do |response| if response == 'a' :done_a else From b80ab4547dfa2cc6220ffeb216f7859b74300afa Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:04:30 +0100 Subject: [PATCH 42/52] Use permitted option in missing_transition test flow --- test/fixtures/graph_presenter_test/missing_transition.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/graph_presenter_test/missing_transition.rb b/test/fixtures/graph_presenter_test/missing_transition.rb index eb7e7a27ede..797d624af9c 100644 --- a/test/fixtures/graph_presenter_test/missing_transition.rb +++ b/test/fixtures/graph_presenter_test/missing_transition.rb @@ -8,7 +8,7 @@ def define option :yes option :no - next_node do + next_node(permitted: [:done]) do :done end end From f680161433484a0503af91beae29071b7828ce34 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:05:40 +0100 Subject: [PATCH 43/52] Use permitted option in bridge-of-death test flow --- test/fixtures/smart_answer_flows/bridge-of-death.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/fixtures/smart_answer_flows/bridge-of-death.rb b/test/fixtures/smart_answer_flows/bridge-of-death.rb index 28320015474..8156a79f651 100644 --- a/test/fixtures/smart_answer_flows/bridge-of-death.rb +++ b/test/fixtures/smart_answer_flows/bridge-of-death.rb @@ -14,7 +14,11 @@ def define option :to_rescue_the_princess option :dunno - next_node do |response| + permitted_next_nodes = [ + :what_is_the_capital_of_assyria?, + :what_is_your_favorite_colour? + ] + next_node(permitted: permitted_next_nodes) do |response| if your_name =~ /robin/i and response == 'to_seek_the_holy_grail' :what_is_the_capital_of_assyria? else From 4406cd414ebb77e3b84e96ae20394e289e74e879 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:06:14 +0100 Subject: [PATCH 44/52] Use permitted option in checkbox-sample test flow --- test/fixtures/smart_answer_flows/checkbox-sample.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/fixtures/smart_answer_flows/checkbox-sample.rb b/test/fixtures/smart_answer_flows/checkbox-sample.rb index 601d0822ff3..979d24966e3 100644 --- a/test/fixtures/smart_answer_flows/checkbox-sample.rb +++ b/test/fixtures/smart_answer_flows/checkbox-sample.rb @@ -12,7 +12,12 @@ def define save_input_as :toppings - next_node do |response| + permitted_next_nodes = [ + :margherita, + :no_way, + :on_its_way + ] + next_node(permitted: permitted_next_nodes) do |response| if response == 'none' :margherita else From 3d17ecd73425c2e64c978dc72c9f2660586d24c7 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:06:44 +0100 Subject: [PATCH 45/52] Use permitted option in custom-errors-sample test flow --- test/fixtures/smart_answer_flows/custom-errors-sample.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/smart_answer_flows/custom-errors-sample.rb b/test/fixtures/smart_answer_flows/custom-errors-sample.rb index e9028c52312..d03805cbf2e 100644 --- a/test/fixtures/smart_answer_flows/custom-errors-sample.rb +++ b/test/fixtures/smart_answer_flows/custom-errors-sample.rb @@ -5,7 +5,7 @@ def define status :draft value_question :how_many_things_do_you_own? do - next_node do |response| + next_node(permitted: [:done]) do |response| raise SmartAnswer::InvalidResponse, :custom_error unless response.to_i > 0 :done end From 1692d08bec246858fa460b441bbc3bafcd0f6e0b Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:13:24 +0100 Subject: [PATCH 46/52] Use permitted option in multiple_choice_question_test --- test/unit/multiple_choice_question_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/multiple_choice_question_test.rb b/test/unit/multiple_choice_question_test.rb index 1ba3c2fac5a..2174b7a0adc 100644 --- a/test/unit/multiple_choice_question_test.rb +++ b/test/unit/multiple_choice_question_test.rb @@ -38,8 +38,7 @@ class MultipleChoiceQuestionTest < ActiveSupport::TestCase q = Question::MultipleChoice.new(nil, :example) do option yes: :fred option :no - next_node { :baz } - permitted_next_nodes(:baz) + next_node(permitted: [:baz]) { :baz } end new_state = q.transition(State.new(:example), :no) From ecd72b8cd0711e5094ae59d868e90c3f6c115f43 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:17:32 +0100 Subject: [PATCH 47/52] Update graph_presenter_test We no longer have any graphs that can not be visualised --- .../missing_transition.rb | 19 ------------------- test/unit/graph_presenter_test.rb | 4 ---- 2 files changed, 23 deletions(-) delete mode 100644 test/fixtures/graph_presenter_test/missing_transition.rb diff --git a/test/fixtures/graph_presenter_test/missing_transition.rb b/test/fixtures/graph_presenter_test/missing_transition.rb deleted file mode 100644 index 797d624af9c..00000000000 --- a/test/fixtures/graph_presenter_test/missing_transition.rb +++ /dev/null @@ -1,19 +0,0 @@ -module SmartAnswer - class MissingTransitionFlow < Flow - def define - name 'missing-transition' - status :draft - - multiple_choice :q1? do - option :yes - option :no - - next_node(permitted: [:done]) do - :done - end - end - - outcome :done - end - end -end diff --git a/test/unit/graph_presenter_test.rb b/test/unit/graph_presenter_test.rb index d57d35e33fb..2df7d88dfde 100644 --- a/test/unit/graph_presenter_test.rb +++ b/test/unit/graph_presenter_test.rb @@ -2,7 +2,6 @@ require_relative '../helpers/i18n_test_helper' require 'fixtures/graph_presenter_test/graph' -require 'fixtures/graph_presenter_test/missing_transition' module SmartAnswer class GraphPresenterTest < ActiveSupport::TestCase @@ -43,9 +42,6 @@ class GraphPresenterTest < ActiveSupport::TestCase test "indicates does not define transitions in a way which can be visualised" do p = GraphPresenter.new(SmartAnswer::GraphFlow.build) assert p.visualisable?, "'graph' should be visualisable" - - p = GraphPresenter.new(SmartAnswer::MissingTransitionFlow.build) - refute p.visualisable?, "'missing_transition' should not be visualisable" end end end From b3865af4f881b1b5959574b45de0a35b1e1a48c4 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:20:06 +0100 Subject: [PATCH 48/52] Fix Rubocop warning in calculate-married-couples-allowance Rubocop warning: "Unused block argument" --- lib/smart_answer_flows/calculate-married-couples-allowance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/smart_answer_flows/calculate-married-couples-allowance.rb b/lib/smart_answer_flows/calculate-married-couples-allowance.rb index bdb5c82dc29..0ec153074d2 100644 --- a/lib/smart_answer_flows/calculate-married-couples-allowance.rb +++ b/lib/smart_answer_flows/calculate-married-couples-allowance.rb @@ -119,7 +119,7 @@ def define :husband_done, :highest_earner_done ] - next_node(permitted: permitted_next_nodes) do |response| + next_node(permitted: permitted_next_nodes) do if income_measure == "husband" :husband_done else From ae5aaa839ba69c2cbdd2d79143891fa2f400c362 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:21:05 +0100 Subject: [PATCH 49/52] Fix Rubocop warnings in minimum_wage.rb Rubocop warning: "Surrounding space missing for operator =" --- lib/smart_answer_flows/shared_logic/minimum_wage.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/smart_answer_flows/shared_logic/minimum_wage.rb b/lib/smart_answer_flows/shared_logic/minimum_wage.rb index bcb863a12e3..7cef240a2d8 100644 --- a/lib/smart_answer_flows/shared_logic/minimum_wage.rb +++ b/lib/smart_answer_flows/shared_logic/minimum_wage.rb @@ -3,7 +3,7 @@ option "current_payment" option "past_payment" - permitted_next_nodes =[ + permitted_next_nodes = [ :are_you_an_apprentice?, :past_payment_date? ] @@ -216,7 +216,7 @@ calculator.valid_overtime_hours_worked?(response) end - permitted_next_nodes =[ + permitted_next_nodes = [ :what_is_overtime_pay_per_hour?, :is_provided_with_accommodation? ] From dd0fb80808c8ccc41ca7d754507d9985b5adb083 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:22:51 +0100 Subject: [PATCH 50/52] Fix Rubocop warning in redundancy_pay.rb Rubocop warning: "Unused block argument - response". --- lib/smart_answer_flows/shared_logic/redundancy_pay.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/smart_answer_flows/shared_logic/redundancy_pay.rb b/lib/smart_answer_flows/shared_logic/redundancy_pay.rb index e0dd2964421..478331d1aa8 100644 --- a/lib/smart_answer_flows/shared_logic/redundancy_pay.rb +++ b/lib/smart_answer_flows/shared_logic/redundancy_pay.rb @@ -87,7 +87,7 @@ :done_no_statutory, :done ] - next_node(permitted: permitted_next_nodes) do |response| + next_node(permitted: permitted_next_nodes) do if years_employed < 2 :done_no_statutory else From 60df5b75b0f8b76b3aaae1813c2c6f53dbc0d4d2 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:48:24 +0100 Subject: [PATCH 51/52] Update checksum data for minimum-wage Smart Answers --- test/data/am-i-getting-minimum-wage-files.yml | 2 +- test/data/minimum-wage-calculator-employers-files.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data/am-i-getting-minimum-wage-files.yml b/test/data/am-i-getting-minimum-wage-files.yml index 8a9b90ac81c..33e4e14f231 100644 --- a/test/data/am-i-getting-minimum-wage-files.yml +++ b/test/data/am-i-getting-minimum-wage-files.yml @@ -12,6 +12,6 @@ lib/smart_answer_flows/am-i-getting-minimum-wage/past_payment_below.govspeak.erb lib/smart_answer_flows/am-i-getting-minimum-wage/under_school_leaving_age.govspeak.erb: 44bf68757d1ef90249d19f5d88ad4bc2 lib/smart_answer_flows/am-i-getting-minimum-wage/under_school_leaving_age_past.govspeak.erb: 2182c103915b753894722760c9a56cf3 lib/smart_answer_flows/shared/minimum_wage/_acas_information.govspeak.erb: 0d2f7c4d01e3c928701e7d649663707e -lib/smart_answer_flows/shared_logic/minimum_wage.rb: 8c9f7af1c7fc9e333e15aa014d3aa129 +lib/smart_answer_flows/shared_logic/minimum_wage.rb: 434cb45cdd375590238a8097d34ce987 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 diff --git a/test/data/minimum-wage-calculator-employers-files.yml b/test/data/minimum-wage-calculator-employers-files.yml index 1cdfcebbc28..7c4f7fb930f 100644 --- a/test/data/minimum-wage-calculator-employers-files.yml +++ b/test/data/minimum-wage-calculator-employers-files.yml @@ -12,6 +12,6 @@ lib/smart_answer_flows/minimum-wage-calculator-employers/past_payment_below.govs lib/smart_answer_flows/minimum-wage-calculator-employers/under_school_leaving_age.govspeak.erb: 13de5d10bbbb015df597f78c66da1b67 lib/smart_answer_flows/minimum-wage-calculator-employers/under_school_leaving_age_past.govspeak.erb: 9c56f76e04984f07627efbc1f42b2b63 lib/smart_answer_flows/shared/minimum_wage/_acas_information.govspeak.erb: 0d2f7c4d01e3c928701e7d649663707e -lib/smart_answer_flows/shared_logic/minimum_wage.rb: 8c9f7af1c7fc9e333e15aa014d3aa129 +lib/smart_answer_flows/shared_logic/minimum_wage.rb: 434cb45cdd375590238a8097d34ce987 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 From 05477a8569a69d598e82ab2b0523342fa79ce0b6 Mon Sep 17 00:00:00 2001 From: Chris Roos <chris@seagul.co.uk> Date: Tue, 13 Oct 2015 17:49:04 +0100 Subject: [PATCH 52/52] Update checksum data for calculate-married-couples-allowance --- test/data/calculate-married-couples-allowance-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/calculate-married-couples-allowance-files.yml b/test/data/calculate-married-couples-allowance-files.yml index fbe589f0b70..67f402ff0e1 100644 --- a/test/data/calculate-married-couples-allowance-files.yml +++ b/test/data/calculate-married-couples-allowance-files.yml @@ -1,5 +1,5 @@ --- -lib/smart_answer_flows/calculate-married-couples-allowance.rb: 2d6577b929490a2d44be463be7abd031 +lib/smart_answer_flows/calculate-married-couples-allowance.rb: 45b0a1885607ee65b9261b93588e3ed9 lib/smart_answer_flows/locales/en/calculate-married-couples-allowance.yml: 4d69826e7196274c5e4f87001c441262 test/data/calculate-married-couples-allowance-questions-and-responses.yml: 1bbef5f2f30d470433bbb63f029881cd test/data/calculate-married-couples-allowance-responses-and-expected-results.yml: 3bb53e4211718b8b1b7dacfaa52f3f49