Merge pull request #4555 from timwis/patch-1

Merge pull request 4555
This commit is contained in:
jekyllbot 2016-03-08 16:25:15 -08:00
commit 9e0ed00a59
2 changed files with 16 additions and 1 deletions

View File

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

View File

@ -321,6 +321,21 @@ class TestFilters < JekyllUnitTest
assert_equal 2, @filter.where(@array_of_objects, "color", "red").length assert_equal 2, @filter.where(@array_of_objects, "color", "red").length
end end
should "filter array properties appropriately" do
hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>["x"]}, "c"=>{"tags"=>["y","z"]}}
assert_equal 2, @filter.where(hash, "tags", "x").length
end
should "filter array properties alongside string properties" do
hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>"x"}, "c"=>{"tags"=>["y","z"]}}
assert_equal 2, @filter.where(hash, "tags", "x").length
end
should "not match substrings" do
hash = {"a"=>{"category"=>"bear"}, "b"=>{"category"=>"wolf"}, "c"=>{"category"=>["bear","lion"]}}
assert_equal 0, @filter.where(hash, "category", "ear").length
end
should "stringify during comparison for compatibility with liquid parsing" do should "stringify during comparison for compatibility with liquid parsing" do
hash = { hash = {
"The Words" => {"rating" => 1.2, "featured" => false}, "The Words" => {"rating" => 1.2, "featured" => false},