File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
app/services/forest_liana/utils
spec/services/forest_liana/utils Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ class ContextVariablesInjector
4
4
5
5
def self . inject_context_in_value ( value , context_variables )
6
6
inject_context_in_value_custom ( value ) do |context_variable_key |
7
- context_variables . get_value ( context_variable_key ) . to_s
7
+ value = context_variables . get_value ( context_variable_key )
8
+ raise "Unknown context variable: #{ context_variable_key } , please check the query for any typos" if value . nil?
9
+ value . to_s
8
10
end
9
11
end
10
12
@@ -18,12 +20,10 @@ def self.inject_context_in_value_custom(value)
18
20
while ( match = regex . match ( value_with_context_variables_injected ) )
19
21
context_variable_key = match [ 1 ]
20
22
21
- unless encountered_variables . include? ( context_variable_key )
22
- value_with_context_variables_injected . gsub! (
23
- /{{#{ context_variable_key } }}/ ,
24
- yield ( context_variable_key )
25
- )
26
- end
23
+ value_with_context_variables_injected . gsub! (
24
+ /{{#{ context_variable_key } }}/ ,
25
+ yield ( context_variable_key )
26
+ )
27
27
28
28
encountered_variables . push ( context_variable_key )
29
29
end
Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ module Utils
101
101
) . to eq ( expected_value . to_s )
102
102
end
103
103
end
104
+
105
+ it 'raises an error when the variable is not found' do
106
+ expect {
107
+ described_class . inject_context_in_value ( "{{siths.selectedRecord.evilString}}" , context_variables )
108
+ } . to raise_error ( 'Unknown context variable: siths.selectedRecord.evilString, please check the query for any typos' )
109
+ end
104
110
end
105
111
end
106
112
end
You can’t perform that action at this time.
0 commit comments