mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 03:10:39 -07:00
Fix broken map test and add sort test
This commit is contained in:
@@ -101,7 +101,6 @@ module Liquid
|
|||||||
def map(input, property)
|
def map(input, property)
|
||||||
flatten_if_necessary(input).map do |e|
|
flatten_if_necessary(input).map do |e|
|
||||||
e = e.call if e.is_a?(Proc)
|
e = e.call if e.is_a?(Proc)
|
||||||
e = e.to_liquid if e.respond_to?(:to_liquid)
|
|
||||||
|
|
||||||
if property == "to_liquid"
|
if property == "to_liquid"
|
||||||
e
|
e
|
||||||
@@ -249,13 +248,14 @@ module Liquid
|
|||||||
private
|
private
|
||||||
|
|
||||||
def flatten_if_necessary(input)
|
def flatten_if_necessary(input)
|
||||||
if input.is_a?(Array)
|
ary = if input.is_a?(Array)
|
||||||
input.flatten
|
input.flatten
|
||||||
elsif input.kind_of?(Enumerable)
|
elsif input.kind_of?(Enumerable)
|
||||||
input
|
input
|
||||||
else
|
else
|
||||||
[input].flatten
|
[input].flatten
|
||||||
end
|
end
|
||||||
|
ary.map{ |e| e.respond_to?(:to_liquid) ? e.to_liquid : e }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_number(obj)
|
def to_number(obj)
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ class TestThing
|
|||||||
"woot: #{@foo}"
|
"woot: #{@foo}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def [](whatever)
|
||||||
|
to_s
|
||||||
|
end
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
@foo += 1
|
@foo += 1
|
||||||
self
|
self
|
||||||
@@ -133,7 +137,12 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_map_calls_to_liquid
|
def test_map_calls_to_liquid
|
||||||
t = TestThing.new
|
t = TestThing.new
|
||||||
assert_equal "woot: 1", Liquid::Template.parse('{{ foo }}').render("foo" => t)
|
assert_equal "woot: 1", Liquid::Template.parse('{{ foo | map: "whatever" }}').render("foo" => [t])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sort_calls_to_liquid
|
||||||
|
t = TestThing.new
|
||||||
|
assert_equal "woot: 1", Liquid::Template.parse('{{ foo | sort: "whatever" }}').render("foo" => [t])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_map_over_proc
|
def test_map_over_proc
|
||||||
|
|||||||
Reference in New Issue
Block a user