1
0
Fork 0

Ensure we're not interpolating an object

Dieser Commit ist enthalten in:
Angus McLeod 2023-03-21 17:20:58 +01:00
Ursprung 78f5af87e1
Commit a146d57f0e
2 geänderte Dateien mit 46 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -44,7 +44,7 @@ class CustomWizard::Mapper
def initialize(params)
@inputs = params[:inputs] || {}
@data = params[:data] || {}
@data = params[:data].with_indifferent_access || {}
@user = params[:user]
@opts = params[:opts] || {}
end
@ -267,7 +267,12 @@ class CustomWizard::Mapper
return nil if data.nil?
k = keys.shift
result = data[k]
keys.empty? ? result : self.recurse(result, keys)
if keys.empty?
result.is_a?(Object) ? "" : result
else
self.recurse(result, keys)
end
end
def bool(value)

Datei anzeigen

@ -58,6 +58,11 @@ describe CustomWizard::Mapper do
"step_1_field_3" => "Value"
}
}
let(:template_params_object) {
{
"step_1_field_1": get_wizard_fixture("field/upload")
}
}
def create_template_mapper(data, user)
CustomWizard::Mapper.new(
@ -448,6 +453,40 @@ describe CustomWizard::Mapper do
expect(result).to eq(template)
end
it "handles correct object variable references" do
template = <<-LIQUID.strip
{%- if "w{step_1_field_1.id}" == "step_2_field_7" -%}
Correct
{%- else -%}
Incorrect
{%-endif-%}
LIQUID
mapper = create_template_mapper(template_params_object, user1)
result = mapper.interpolate(
template.dup,
template: true,
wizard: true
)
expect(result).to eq("Correct")
end
it "handles incorrect object variable references" do
template = <<-LIQUID.strip
{%- if "w{step_1_field_1}" == "step_2_field_7" -%}
Correct
{%- else -%}
Incorrect
{%-endif-%}
LIQUID
mapper = create_template_mapper(template_params_object, user1)
result = mapper.interpolate(
template.dup,
template: true,
wizard: true
)
expect(result).to eq("Incorrect")
end
context "custom filter: 'first_non_empty'" do
it "gives first non empty element from list" do
template = <<-LIQUID.strip