From 6543cee1345270d926b790119d80a1e6339a4cee Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Wed, 14 Oct 2015 14:48:42 +0100 Subject: [PATCH 01/28] Add permitted option to next_node This allows us to define the permitted next nodes by passing an option to next_node, rather than having to use `permitted_next_nodes`. --- lib/smart_answer/question/base.rb | 3 ++- test/unit/question_base_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/smart_answer/question/base.rb b/lib/smart_answer/question/base.rb index 8d0b6a8abe1..29d873aeeec 100644 --- a/lib/smart_answer/question/base.rb +++ b/lib/smart_answer/question/base.rb @@ -15,8 +15,9 @@ 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? + @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 5d1d7d948d3..e4bd7ded43d 100644 --- a/test/unit/question_base_test.rb +++ b/test/unit/question_base_test.rb @@ -3,6 +3,15 @@ require_relative '../test_helper' class QuestionBaseTest < ActiveSupport::TestCase + test 'permitted next nodes can be supplied to next_node' do + q = SmartAnswer::Question::Base.new(nil, :example) { + next_node(permitted: [:done]) do + :done + end + } + assert_equal [:done], q.permitted_next_nodes + end + test "State is carried over on a state transition" do q = SmartAnswer::Question::Base.new(nil, :example) { next_node :done From c3079b58923ae35b24e8761936a5bcc315e50492 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Mon, 12 Oct 2015 17:18:09 +0100 Subject: [PATCH 02/28] Use permitted option in additional-commodity-code --- .../additional-commodity-code.rb | 20 +++++++++++++++++-- test/data/additional-commodity-code-files.yml | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/smart_answer_flows/additional-commodity-code.rb b/lib/smart_answer_flows/additional-commodity-code.rb index d5b3a7c82b3..fafe22c7698 100644 --- a/lib/smart_answer_flows/additional-commodity-code.rb +++ b/lib/smart_answer_flows/additional-commodity-code.rb @@ -17,7 +17,14 @@ def define save_input_as :starch_glucose_weight - next_node do |response| + permitted_next_nodes = [ + :how_much_sucrose_1?, + :how_much_sucrose_2?, + :how_much_sucrose_3?, + :how_much_sucrose_4? + ] + + next_node(permitted: permitted_next_nodes) do |response| case response.to_i when 25 :how_much_sucrose_2? @@ -90,7 +97,16 @@ def define save_input_as :milk_fat_weight - next_node do |response| + 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(permitted: permitted_next_nodes) do |response| case response.to_i when 0, 1 :how_much_milk_protein_ab? diff --git a/test/data/additional-commodity-code-files.yml b/test/data/additional-commodity-code-files.yml index 9942d07f0e6..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: a824498493048a251eefac4c2cbc97fb +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 84a0314351b277986a5c61735dd14a70d96329f0 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Mon, 12 Oct 2015 17:23:51 +0100 Subject: [PATCH 03/28] Use permitted option in minimum-wage --- .../shared_logic/minimum_wage.rb | 118 +++++++++++++++--- test/data/am-i-getting-minimum-wage-files.yml | 2 +- ...inimum-wage-calculator-employers-files.yml | 2 +- 3 files changed, 100 insertions(+), 22 deletions(-) diff --git a/lib/smart_answer_flows/shared_logic/minimum_wage.rb b/lib/smart_answer_flows/shared_logic/minimum_wage.rb index f4edf73523e..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,12 @@ option "current_payment" option "past_payment" - next_node do |response| + permitted_next_nodes = [ + :are_you_an_apprentice?, + :past_payment_date? + ] + + next_node(permitted: permitted_next_nodes) do |response| case response when 'current_payment' :are_you_an_apprentice? @@ -27,7 +32,9 @@ option "2009-10-01" option "2008-10-01" - next_node do |response| + permitted_next_nodes = [:were_you_an_apprentice?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.date = Date.parse(response) :were_you_an_apprentice? end @@ -40,7 +47,12 @@ option "apprentice_over_19_first_year" option "apprentice_over_19_second_year_onwards" - next_node do |response| + permitted_next_nodes = [ + :how_old_are_you?, + :how_often_do_you_get_paid? + ] + + next_node(permitted: permitted_next_nodes) do |response| case response when 'not_an_apprentice', 'apprentice_over_19_second_year_onwards' calculator.is_apprentice = false @@ -58,7 +70,13 @@ option "apprentice_under_19" option "apprentice_over_19" - next_node do |response| + permitted_next_nodes = [ + :how_old_were_you?, + :how_often_did_you_get_paid?, + :does_not_apply_to_historical_apprentices + ] + + next_node(permitted: permitted_next_nodes) do |response| case response when "no" calculator.is_apprentice = false @@ -80,7 +98,12 @@ calculator.valid_age?(response) end - next_node do |response| + permitted_next_nodes = [ + :under_school_leaving_age, + :how_often_do_you_get_paid? + ] + + next_node(permitted: permitted_next_nodes) do |response| calculator.age = response if calculator.under_school_leaving_age? :under_school_leaving_age @@ -96,7 +119,12 @@ calculator.valid_age?(response) end - next_node do |response| + permitted_next_nodes = [ + :under_school_leaving_age_past, + :how_often_did_you_get_paid? + ] + + next_node(permitted: permitted_next_nodes) do |response| calculator.age = response if calculator.under_school_leaving_age? :under_school_leaving_age_past @@ -112,7 +140,9 @@ calculator.valid_pay_frequency?(response) end - next_node do |response| + permitted_next_nodes = [:how_many_hours_do_you_work?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.pay_frequency = response :how_many_hours_do_you_work? end @@ -124,7 +154,9 @@ calculator.valid_pay_frequency?(response) end - next_node do |response| + permitted_next_nodes = [:how_many_hours_did_you_work?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.pay_frequency = response :how_many_hours_did_you_work? end @@ -136,7 +168,9 @@ calculator.valid_hours_worked?(response) end - next_node do |response| + permitted_next_nodes = [:how_much_are_you_paid_during_pay_period?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_hours = response :how_much_are_you_paid_during_pay_period? end @@ -148,7 +182,9 @@ calculator.valid_hours_worked?(response) end - next_node do |response| + permitted_next_nodes = [:how_much_were_you_paid_during_pay_period?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_hours = response :how_much_were_you_paid_during_pay_period? end @@ -156,7 +192,9 @@ # Q6 money_question :how_much_are_you_paid_during_pay_period? do - next_node do |response| + permitted_next_nodes = [:how_many_hours_overtime_do_you_work?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_pay = Float(response) :how_many_hours_overtime_do_you_work? end @@ -164,7 +202,9 @@ # Q6 Past money_question :how_much_were_you_paid_during_pay_period? do - next_node do |response| + permitted_next_nodes = [:how_many_hours_overtime_did_you_work?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.basic_pay = Float(response) :how_many_hours_overtime_did_you_work? end @@ -176,7 +216,12 @@ calculator.valid_overtime_hours_worked?(response) end - next_node do |response| + permitted_next_nodes = [ + :what_is_overtime_pay_per_hour?, + :is_provided_with_accommodation? + ] + + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hours = response if calculator.any_overtime_hours_worked? :what_is_overtime_pay_per_hour? @@ -192,7 +237,12 @@ calculator.valid_overtime_hours_worked?(response) end - next_node do |response| + permitted_next_nodes = [ + :what_was_overtime_pay_per_hour?, + :was_provided_with_accommodation? + ] + + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hours = response if calculator.any_overtime_hours_worked? :what_was_overtime_pay_per_hour? @@ -204,7 +254,9 @@ # Q8 money_question :what_is_overtime_pay_per_hour? do - next_node do |response| + permitted_next_nodes = [:is_provided_with_accommodation?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hourly_rate = Float(response) :is_provided_with_accommodation? end @@ -212,7 +264,9 @@ # Q8 Past money_question :what_was_overtime_pay_per_hour? do - next_node do |response| + permitted_next_nodes = [:was_provided_with_accommodation?] + + next_node(permitted: permitted_next_nodes) do |response| calculator.overtime_hourly_rate = Float(response) :was_provided_with_accommodation? end @@ -224,7 +278,14 @@ option "yes_free" option "yes_charged" - next_node do |response| + permitted_next_nodes = [ + :current_accommodation_usage?, + :current_accommodation_charge?, + :current_payment_above, + :current_payment_below + ] + + next_node(permitted: permitted_next_nodes) do |response| case response when "yes_free" :current_accommodation_usage? @@ -246,7 +307,14 @@ option "yes_free" option "yes_charged" - next_node do |response| + permitted_next_nodes = [ + :past_accommodation_usage?, + :past_accommodation_charge?, + :past_payment_above, + :past_payment_below + ] + + next_node(permitted: permitted_next_nodes) do |response| case response when "yes_free" :past_accommodation_usage? @@ -290,7 +358,12 @@ calculator.valid_accommodation_usage?(response) end - next_node do |response| + permitted_next_nodes = [ + :current_payment_above, + :current_payment_below + ] + + next_node(permitted: permitted_next_nodes) do |response| calculator.accommodation_adjustment(accommodation_charge, response) if calculator.minimum_wage_or_above? :current_payment_above @@ -306,7 +379,12 @@ calculator.valid_accommodation_usage?(response) end - next_node do |response| + permitted_next_nodes = [ + :past_payment_above, + :past_payment_below + ] + + next_node(permitted: permitted_next_nodes) do |response| calculator.accommodation_adjustment(accommodation_charge, response) if calculator.historically_receiving_minimum_wage? :past_payment_above diff --git a/test/data/am-i-getting-minimum-wage-files.yml b/test/data/am-i-getting-minimum-wage-files.yml index 1ad4b804600..1d488861662 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: 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 cd59ab8ac7b..dc0e86d7295 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: 434cb45cdd375590238a8097d34ce987 lib/smart_answer/calculators/minimum_wage_calculator.rb: cab354bb2fc0f660d6c6aef70b9fabc5 lib/data/minimum_wage_data.yml: 3feed11191d68237289203a2c659ecf9 From 152c055649bfd6476eceebc9d2a1d956a717058a Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Wed, 14 Oct 2015 16:27:42 +0100 Subject: [PATCH 04/28] Reorder questions in benefit-cap-calculator Move the `widow_pension_amount?` question before `widowed_mother_amount?`. Responses to `multiple_choice` questions are always ordered alphabetically. This flow iterates over the responses to the `:receiving_non_exemption_benefits?` question and uses that to decide which node to display next. The alphabetical ordering of responses means that `widow_pension_amount?` will always be asked before `widowed_mother_amount?`. --- lib/smart_answer_flows/benefit-cap-calculator.rb | 12 ++++++------ test/data/benefit-cap-calculator-files.yml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/smart_answer_flows/benefit-cap-calculator.rb b/lib/smart_answer_flows/benefit-cap-calculator.rb index 20901e11e0c..60b8997e6e6 100644 --- a/lib/smart_answer_flows/benefit-cap-calculator.rb +++ b/lib/smart_answer_flows/benefit-cap-calculator.rb @@ -226,8 +226,8 @@ def define end end - #Q5l - money_question :widowed_mother_amount? do + #Q5n + money_question :widow_pension_amount? do calculate :total_benefits do |response| total_benefits + response.to_f @@ -238,8 +238,8 @@ def define end end - #Q5m - money_question :widowed_parent_amount? do + #Q5l + money_question :widowed_mother_amount? do calculate :total_benefits do |response| total_benefits + response.to_f @@ -250,8 +250,8 @@ def define end end - #Q5n - money_question :widow_pension_amount? do + #Q5m + money_question :widowed_parent_amount? do calculate :total_benefits do |response| total_benefits + response.to_f diff --git a/test/data/benefit-cap-calculator-files.yml b/test/data/benefit-cap-calculator-files.yml index d8673aeacbf..b9b0d7ce124 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: 6be14aabe2cbf187179d6de2466af6ae lib/smart_answer_flows/locales/en/benefit-cap-calculator.yml: f529cf71d32a7e802454eb79244a0a36 test/data/benefit-cap-calculator-questions-and-responses.yml: 460336f2cf1f2acc62729ef5d831f25e test/data/benefit-cap-calculator-responses-and-expected-results.yml: 19c0bc207cde0d94c76b769b0da5d0bd From 6ede28b252763775926b03cb77324e63699c71e5 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Mon, 12 Oct 2015 17:37:53 +0100 Subject: [PATCH 05/28] Use permitted option in benefit-cap-calculator --- .../benefit-cap-calculator.rb | 265 ++++++++++++++++-- test/data/benefit-cap-calculator-files.yml | 2 +- 2 files changed, 245 insertions(+), 22 deletions(-) diff --git a/lib/smart_answer_flows/benefit-cap-calculator.rb b/lib/smart_answer_flows/benefit-cap-calculator.rb index 60b8997e6e6..6a2286cb06e 100644 --- a/lib/smart_answer_flows/benefit-cap-calculator.rb +++ b/lib/smart_answer_flows/benefit-cap-calculator.rb @@ -13,7 +13,12 @@ def define save_input_as :housing_benefit - next_node do |response| + permitted_next_nodes = [ + :working_tax_credit?, + :outcome_not_affected_no_housing_benefit + ] + + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' :working_tax_credit? else @@ -27,7 +32,12 @@ def define option :yes option :no - next_node do |response| + permitted_next_nodes = [ + :outcome_not_affected_exemptions, + :receiving_exemption_benefits? + ] + + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' :outcome_not_affected_exemptions else @@ -41,7 +51,12 @@ def define option :yes option :no - next_node do |response| + permitted_next_nodes = [ + :outcome_not_affected_exemptions, + :receiving_non_exemption_benefits? + ] + + next_node(permitted: permitted_next_nodes) do |response| if response == 'yes' :outcome_not_affected_exemptions else @@ -84,7 +99,28 @@ def define 0 end - next_node do |response| + 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?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do |response| first_value = response.split(",").first if response == "none" :outcome_not_affected @@ -101,7 +137,26 @@ def define total_benefits + response.to_f end - next_node do + 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?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -113,7 +168,25 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :child_benefit_amount?, + :child_tax_amount?, + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -125,7 +198,24 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :child_tax_amount?, + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -137,7 +227,23 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :esa_amount?, + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -149,7 +255,22 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :guardian_amount?, + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -161,7 +282,21 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :incapacity_amount?, + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -173,7 +308,20 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :income_support_amount?, + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -185,7 +333,19 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :jsa_amount?, + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -197,7 +357,18 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :maternity_amount?, + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -209,7 +380,17 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :sda_amount?, + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -221,7 +402,16 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :widow_pension_amount?, + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -233,7 +423,15 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :widowed_mother_amount?, + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -245,7 +443,14 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :widowed_parent_amount?, + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -257,7 +462,13 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :widows_aged_amount?, + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -269,7 +480,12 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [ + :housing_benefit_amount?, + :single_couple_lone_parent? + ] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -283,7 +499,9 @@ def define total_benefits + response.to_f end - next_node do + permitted_next_nodes = [:single_couple_lone_parent?] + + next_node(permitted: permitted_next_nodes) do benefit_related_questions.shift end end @@ -303,7 +521,12 @@ def define sprintf("%.2f", benefit_cap) end - next_node do |response| + permitted_next_nodes = [ + :outcome_affected_greater_than_cap, + :outcome_not_affected_less_than_cap + ] + + next_node(permitted: permitted_next_nodes) do |response| if response == 'single' cap = 350 else diff --git a/test/data/benefit-cap-calculator-files.yml b/test/data/benefit-cap-calculator-files.yml index b9b0d7ce124..b07555b8a8c 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: 6be14aabe2cbf187179d6de2466af6ae +lib/smart_answer_flows/benefit-cap-calculator.rb: 3272eb6344567f88ec75694fc1d4b7d6 lib/smart_answer_flows/locales/en/benefit-cap-calculator.yml: f529cf71d32a7e802454eb79244a0a36 test/data/benefit-cap-calculator-questions-and-responses.yml: 460336f2cf1f2acc62729ef5d831f25e test/data/benefit-cap-calculator-responses-and-expected-results.yml: 19c0bc207cde0d94c76b769b0da5d0bd From 2281714cc478cb56f7b812444a59bbb14db9fc71 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 14:35:50 +0100 Subject: [PATCH 06/28] Use permitted option in redundancy-pay I've also removed the unused `response` block argument to avoid the following Rubocop warning: "Unused block argument - response". --- .../shared_logic/redundancy_pay.rb | 12 ++++++++++-- .../data/calculate-employee-redundancy-pay-files.yml | 2 +- test/data/calculate-your-redundancy-pay-files.yml | 2 +- 3 files changed, 12 insertions(+), 4 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..478331d1aa8 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 if years_employed < 2 :done_no_statutory else diff --git a/test/data/calculate-employee-redundancy-pay-files.yml b/test/data/calculate-employee-redundancy-pay-files.yml index 7d08ee3dd3a..fe4247b8116 100644 --- a/test/data/calculate-employee-redundancy-pay-files.yml +++ b/test/data/calculate-employee-redundancy-pay-files.yml @@ -6,7 +6,7 @@ test/data/calculate-employee-redundancy-pay-responses-and-expected-results.yml: lib/smart_answer_flows/calculate-employee-redundancy-pay/calculate_employee_redundancy_pay.govspeak.erb: 22dbc473918685ceb57b7a2a87b6fe47 lib/smart_answer_flows/calculate-employee-redundancy-pay/done.govspeak.erb: 87c7dfc2a59723966e585ef0c2c66b47 lib/smart_answer_flows/calculate-employee-redundancy-pay/done_no_statutory.govspeak.erb: 446e959e823c5e4631e86de58f9f0349 -lib/smart_answer_flows/shared_logic/redundancy_pay.rb: ec40180eb9c26b00736173986375d60c +lib/smart_answer_flows/shared_logic/redundancy_pay.rb: 2e1a5aeacda3efca59b18efecb256e58 lib/smart_answer/calculators/redundancy_calculator.rb: 6f97d315c840f829670f64e2fabce6dd lib/data/rates/redundancy_pay.yml: 270b43298e223b28ba7ad3f81f5e0a08 lib/data/rates/redundancy_pay_northern_ireland.yml: 01a56e2760328e0213318050689f2556 diff --git a/test/data/calculate-your-redundancy-pay-files.yml b/test/data/calculate-your-redundancy-pay-files.yml index 8d5847fe7b6..e1c90f4a589 100644 --- a/test/data/calculate-your-redundancy-pay-files.yml +++ b/test/data/calculate-your-redundancy-pay-files.yml @@ -6,7 +6,7 @@ test/data/calculate-your-redundancy-pay-responses-and-expected-results.yml: c2a4 lib/smart_answer_flows/calculate-your-redundancy-pay/calculate_your_redundancy_pay.govspeak.erb: 063d747da3117bc0e06d271bd78bbe88 lib/smart_answer_flows/calculate-your-redundancy-pay/done.govspeak.erb: 627ae9150dfcf72d8294f9f68019ba91 lib/smart_answer_flows/calculate-your-redundancy-pay/done_no_statutory.govspeak.erb: e4f6b40f10295e4757075ff698b39707 -lib/smart_answer_flows/shared_logic/redundancy_pay.rb: ec40180eb9c26b00736173986375d60c +lib/smart_answer_flows/shared_logic/redundancy_pay.rb: 2e1a5aeacda3efca59b18efecb256e58 lib/smart_answer/calculators/redundancy_calculator.rb: 6f97d315c840f829670f64e2fabce6dd lib/data/rates/redundancy_pay.yml: 270b43298e223b28ba7ad3f81f5e0a08 lib/data/rates/redundancy_pay_northern_ireland.yml: 01a56e2760328e0213318050689f2556 From e2a248a30f0cf604b3418c343c3540baa8761dbd Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:05:14 +0100 Subject: [PATCH 07/28] Use permitted option in calculate-married-couples-allowance I've also removed the unused `response` block argument to avoid the following Rubocop warning: "Unused block argument - response". --- .../calculate-married-couples-allowance.rb | 18 +++++++++++++++--- ...lculate-married-couples-allowance-files.yml | 2 +- 2 files changed, 16 insertions(+), 4 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..0ec153074d2 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 if income_measure == "husband" :husband_done else diff --git a/test/data/calculate-married-couples-allowance-files.yml b/test/data/calculate-married-couples-allowance-files.yml index 7a60fd681cc..8d8356b28cb 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: 45b0a1885607ee65b9261b93588e3ed9 lib/smart_answer_flows/locales/en/calculate-married-couples-allowance.yml: d3000af873a9c53b2f62719b3d72e91d test/data/calculate-married-couples-allowance-questions-and-responses.yml: 1bbef5f2f30d470433bbb63f029881cd test/data/calculate-married-couples-allowance-responses-and-expected-results.yml: 3bb53e4211718b8b1b7dacfaa52f3f49 From 220a4a081354a3b2fe1f55c17c070c647b9c5e66 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:07:51 +0100 Subject: [PATCH 08/28] Use permitted option in calculate-state-pension --- lib/smart_answer_flows/calculate-state-pension.rb | 6 +++++- test/data/calculate-state-pension-files.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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 diff --git a/test/data/calculate-state-pension-files.yml b/test/data/calculate-state-pension-files.yml index 905eb471486..1bb808c2851 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: 59b2577b5bd537db695a998d82264e7e test/data/calculate-state-pension-questions-and-responses.yml: 8fe4d28d6b90ff1030ed15470d5b458f test/data/calculate-state-pension-responses-and-expected-results.yml: 61e8ccba31841f6616cf8b26f3da6ff9 From a6e30f1f73a77abbc9a222cff53fcca6a8dfe80b Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:11:30 +0100 Subject: [PATCH 09/28] Use permitted option in calculate-your-holiday-entitlement --- .../calculate-your-holiday-entitlement.rb | 31 ++++++++++++++++--- ...lculate-your-holiday-entitlement-files.yml | 2 +- 2 files changed, 28 insertions(+), 5 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? diff --git a/test/data/calculate-your-holiday-entitlement-files.yml b/test/data/calculate-your-holiday-entitlement-files.yml index 03ef404f7fe..4490557e33d 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: 0e0af2f45c9cca757b9d5fcb6fd3cc6d test/data/calculate-your-holiday-entitlement-questions-and-responses.yml: a5d687911e6173e74f2b70af6a5ff7bd test/data/calculate-your-holiday-entitlement-responses-and-expected-results.yml: b7d4735ae33ef0dceeeb97c12019db84 From 37373c34f115d544f1bb9533bbc6c3a67f5d0a33 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:13:36 +0100 Subject: [PATCH 10/28] Use permitted option in check-uk-visa --- lib/smart_answer_flows/check-uk-visa.rb | 10 ++++++++-- test/data/check-uk-visa-files.yml | 2 +- 2 files changed, 9 insertions(+), 3 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 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 b0ca6bc6f554e290e01ed319a9ef0b6851a85da1 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:15:38 +0100 Subject: [PATCH 11/28] Use permitted option in childcare-costs-for-tax-credits --- .../childcare-costs-for-tax-credits.rb | 26 ++++++++++++++++--- .../childcare-costs-for-tax-credits-files.yml | 2 +- 2 files changed, 23 insertions(+), 5 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 diff --git a/test/data/childcare-costs-for-tax-credits-files.yml b/test/data/childcare-costs-for-tax-credits-files.yml index 0616ef0880d..29f2a11b1f3 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: 1f9c5671b17aa97b6ea2472634481997 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 ca8e8a5885d60939f456f1c769ccd9d96adef3cf Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:18:50 +0100 Subject: [PATCH 12/28] Use permitted option in estimate-self-assessment-penalties --- .../estimate-self-assessment-penalties.rb | 9 +++++++-- test/data/estimate-self-assessment-penalties-files.yml | 2 +- 2 files changed, 8 insertions(+), 3 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 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 bd5c5ccb1307abb86a042f3a48278ab85fbe6cf7 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:20:13 +0100 Subject: [PATCH 13/28] Use permitted option in help-if-you-are-arrested-abroad --- lib/smart_answer_flows/help-if-you-are-arrested-abroad.rb | 7 ++++++- test/data/help-if-you-are-arrested-abroad-files.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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" 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 82a3be19294f1ed65b75871d15085e2eb7b0fd49 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:26:25 +0100 Subject: [PATCH 14/28] Use permitted option in landlord-immigration-check --- .../landlord-immigration-check.rb | 91 ++++++++++++++++--- .../data/landlord-immigration-check-files.yml | 2 +- 2 files changed, 78 insertions(+), 15 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 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 6faf113c2f424bfc9faa70de7ddc50b214e5c10b Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:33:11 +0100 Subject: [PATCH 15/28] 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 4339d943d79b3e7261c8e95b78f16d5dc8509d38 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 15:42:34 +0100 Subject: [PATCH 16/28] Use permitted option in pip-checker --- lib/smart_answer_flows/pip-checker.rb | 10 +++++++++- test/data/pip-checker-files.yml | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) 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? diff --git a/test/data/pip-checker-files.yml b/test/data/pip-checker-files.yml index 7ae6cb31e86..c9fce84c922 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: 726e0dd42e3505341c9bfc7e4888d4a5 test/data/pip-checker-questions-and-responses.yml: b1d68ebfb76a9e2793705c55b82294f5 test/data/pip-checker-responses-and-expected-results.yml: a2c772b69a493d1844cfa32681057796 From 3301905cfdc3d91ec3053c907875900e963284ab Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 16:49:58 +0100 Subject: [PATCH 17/28] Use permitted option in report-a-lost-or-stolen-passport --- lib/smart_answer_flows/report-a-lost-or-stolen-passport.rb | 6 +++++- test/data/report-a-lost-or-stolen-passport-files.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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? 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 59b176fe06e..93f3cecbef6 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: b3b8d31d025f554b1589e8c33fdd8c15 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 0f41e1dc342431c8ec450c4f206b57af420aa8e8 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 16:55:06 +0100 Subject: [PATCH 18/28] Use permitted option in simplified-expenses-checker --- .../simplified-expenses-checker.rb | 64 ++++++++++++++++--- .../simplified-expenses-checker-files.yml | 2 +- 2 files changed, 56 insertions(+), 10 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 diff --git a/test/data/simplified-expenses-checker-files.yml b/test/data/simplified-expenses-checker-files.yml index f088444d4a2..07d15c1feb7 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: ae340f0f515377411d8710468afa4962 test/data/simplified-expenses-checker-questions-and-responses.yml: 6b1c358b3730897b6cbefa9477ada15b test/data/simplified-expenses-checker-responses-and-expected-results.yml: 983e72657f76697beafb2dcbe4018bee From 8493df5310ae000389661483970fa3e5fac1f0a9 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 16:57:10 +0100 Subject: [PATCH 19/28] Use permitted option in student-finance-calculator --- .../student-finance-calculator.rb | 14 ++++++++++++-- test/data/student-finance-calculator-files.yml | 2 +- 2 files changed, 13 insertions(+), 3 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 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 cd9ce0aa34d8464fc1ec46fc8108b13eda1ac66c Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:03:53 +0100 Subject: [PATCH 20/28] 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 ff7919c71662f038a24ac5a1fde09faee9ca81f7 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:04:30 +0100 Subject: [PATCH 21/28] 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 fe43f91aca13c5988004feae62f942c809c84b9c Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:05:40 +0100 Subject: [PATCH 22/28] 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 11c6a93fd39e71b35cc6d277661ddf5758302e59 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:06:14 +0100 Subject: [PATCH 23/28] 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 c3cc1bdc49f5054eda68e5b09ff492354e473d2b Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:06:44 +0100 Subject: [PATCH 24/28] 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 02a9cf28ffebaa0e19d10ee77405d1893facc151 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:13:24 +0100 Subject: [PATCH 25/28] 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 a939ee31afc9d468c74be867aa133834de6cd585 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Tue, 13 Oct 2015 17:17:32 +0100 Subject: [PATCH 26/28] 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 b8c0cbe544687a1c44964ec64c94f0cb1326fb39 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Wed, 14 Oct 2015 14:40:32 +0100 Subject: [PATCH 27/28] Fail fast if permitted option not specified When calling `next_node` with a block. This isn't foolproof as it only checks that we pass something as the `permitted` option, and not that the permitted options actually make sense. It's probably good enough to prevent people accidentally forgetting to specify the `permitted` option. --- lib/smart_answer/question/base.rb | 3 +++ test/unit/question_base_test.rb | 15 ++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/smart_answer/question/base.rb b/lib/smart_answer/question/base.rb index 29d873aeeec..fe6c659a9b4 100644 --- a/lib/smart_answer/question/base.rb +++ b/lib/smart_answer/question/base.rb @@ -17,6 +17,9 @@ def initialize(flow, name, options = {}, &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 diff --git a/test/unit/question_base_test.rb b/test/unit/question_base_test.rb index e4bd7ded43d..67f183f8b17 100644 --- a/test/unit/question_base_test.rb +++ b/test/unit/question_base_test.rb @@ -43,8 +43,7 @@ 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) + next_node(permitted: [:done_done]) { :done_done } } initial_state = SmartAnswer::State.new(q.name) new_state = q.transition(initial_state, :anything) @@ -53,10 +52,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' @@ -67,11 +66,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') @@ -202,8 +200,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) @@ -212,7 +209,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 8c785e436b80b80136fa4dd423948fb867b3ab61 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Mon, 12 Oct 2015 17:16:44 +0100 Subject: [PATCH 28/28] Fail fast if next_node not in permitted_next_nodes This should help ensure that we supply the correct set of permitted next nodes when calling `next_node` with a block. --- 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 fe6c659a9b4..039d76673c1 100644 --- a/lib/smart_answer/question/base.rb +++ b/lib/smart_answer/question/base.rb @@ -48,6 +48,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.to_sentence})" + end next_node end diff --git a/test/unit/question_base_test.rb b/test/unit/question_base_test.rb index 67f183f8b17..7d8c6bab3ea 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(permitted: permitted_next_nodes) { :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 and allowed_next_node_2)" + exception = assert_raises do + q.next_node_for(state, 'response') + end + assert_equal expected_message, exception.message + end + test 'permitted next nodes can be supplied to next_node' do q = SmartAnswer::Question::Base.new(nil, :example) { next_node(permitted: [:done]) do