mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fix map filter on Hash inputs
This commit is contained in:
@@ -250,7 +250,7 @@ module Liquid
|
|||||||
def flatten_if_necessary(input)
|
def flatten_if_necessary(input)
|
||||||
ary = if input.is_a?(Array)
|
ary = if input.is_a?(Array)
|
||||||
input.flatten
|
input.flatten
|
||||||
elsif input.kind_of?(Enumerable)
|
elsif input.is_a?(Enumerable) && !input.is_a?(Hash)
|
||||||
input
|
input
|
||||||
else
|
else
|
||||||
[input].flatten
|
[input].flatten
|
||||||
|
|||||||
@@ -140,6 +140,10 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|||||||
assert_equal "woot: 1", Liquid::Template.parse('{{ foo | map: "whatever" }}').render("foo" => [t])
|
assert_equal "woot: 1", Liquid::Template.parse('{{ foo | map: "whatever" }}').render("foo" => [t])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_map_on_hashes
|
||||||
|
assert_equal "4217", Liquid::Template.parse('{{ thing | map: "foo" | map: "bar" }}').render("thing" => { "foo" => [ { "bar" => 42 }, { "bar" => 17 } ] })
|
||||||
|
end
|
||||||
|
|
||||||
def test_sort_calls_to_liquid
|
def test_sort_calls_to_liquid
|
||||||
t = TestThing.new
|
t = TestThing.new
|
||||||
assert_equal "woot: 1", Liquid::Template.parse('{{ foo | sort: "whatever" }}').render("foo" => [t])
|
assert_equal "woot: 1", Liquid::Template.parse('{{ foo | sort: "whatever" }}').render("foo" => [t])
|
||||||
|
|||||||
Reference in New Issue
Block a user