Merge pull request #3935 from jekyll/filter-where-to_s

Merge pull request 3935
This commit is contained in:
Parker Moore 2015-08-25 23:39:19 -07:00
commit 831eb17b29
2 changed files with 18 additions and 1 deletions

View File

@ -211,7 +211,7 @@ module Jekyll
def where(input, property, value)
return input unless input.is_a?(Enumerable)
input = input.values if input.is_a?(Hash)
input.select { |object| item_property(object, property) == value }
input.select { |object| item_property(object, property).to_s == value.to_s }
end
# Sort an array of objects

View File

@ -277,6 +277,23 @@ class TestFilters < JekyllUnitTest
should "filter objects appropriately" do
assert_equal 2, @filter.where(@array_of_objects, "color", "red").length
end
should "stringify during comparison for compatibility with liquid parsing" do
hash = {
"The Words" => {"rating" => 1.2, "featured" => false},
"Limitless" => {"rating" => 9.2, "featured" => true},
"Hustle" => {"rating" => 4.7, "featured" => true},
}
results = @filter.where(hash, "featured", "true")
assert_equal 2, results.length
assert_equal 9.2, results[0]["rating"]
assert_equal 4.7, results[1]["rating"]
results = @filter.where(hash, "rating", 4.7)
assert_equal 1, results.length
assert_equal 4.7, results[0]["rating"]
end
end
context "sort filter" do