Skip to content

Commit dc2ea2b

Browse files
committed
Merge pull request #2010 from alphagov/specify-permitted-next-nodes-for-all-flows
Specify permitted next nodes for all flows
2 parents e4d9441 + 8c785e4 commit dc2ea2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+722
-161
lines changed

lib/smart_answer/question/base.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ def initialize(flow, name, options = {}, &block)
1515
super
1616
end
1717

18-
def next_node(next_node = nil, &block)
18+
def next_node(next_node = nil, permitted: [], &block)
1919
if block_given?
20+
unless permitted.any?
21+
raise "You must specify the permitted next nodes"
22+
end
23+
@permitted_next_nodes += permitted
2024
@default_next_node_function = block
2125
elsif next_node
2226
next_node_if(next_node)
@@ -44,6 +48,9 @@ def next_node_for(current_state, input)
4448
next_node = next_node_from_function_chain(current_state, input) || next_node_from_default_function(current_state, input)
4549
responses_and_input = current_state.responses + [input]
4650
raise NextNodeUndefined.new("Next node undefined. Node: #{current_state.current_node}. Responses: #{responses_and_input}") unless next_node
51+
unless @permitted_next_nodes.include?(next_node)
52+
raise "Next node (#{next_node}) not in list of permitted next nodes (#{@permitted_next_nodes.to_sentence})"
53+
end
4754
next_node
4855
end
4956

lib/smart_answer_flows/additional-commodity-code.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ def define
1717

1818
save_input_as :starch_glucose_weight
1919

20-
next_node do |response|
20+
permitted_next_nodes = [
21+
:how_much_sucrose_1?,
22+
:how_much_sucrose_2?,
23+
:how_much_sucrose_3?,
24+
:how_much_sucrose_4?
25+
]
26+
27+
next_node(permitted: permitted_next_nodes) do |response|
2128
case response.to_i
2229
when 25
2330
:how_much_sucrose_2?
@@ -90,7 +97,16 @@ def define
9097

9198
save_input_as :milk_fat_weight
9299

93-
next_node do |response|
100+
permitted_next_nodes = [
101+
:commodity_code_result,
102+
:how_much_milk_protein_ab?,
103+
:how_much_milk_protein_c?,
104+
:how_much_milk_protein_d?,
105+
:how_much_milk_protein_ef?,
106+
:how_much_milk_protein_gh?
107+
]
108+
109+
next_node(permitted: permitted_next_nodes) do |response|
94110
case response.to_i
95111
when 0, 1
96112
:how_much_milk_protein_ab?

0 commit comments

Comments
 (0)