Merge pull request #2986 from tamagokun/where_filters_enumerable
This commit is contained in:
commit
5ed4638400
|
@ -219,7 +219,8 @@ module Jekyll
|
|||
#
|
||||
# Returns the filtered array of objects
|
||||
def where(input, property, value)
|
||||
return input unless input.is_a?(Array)
|
||||
return input unless input.is_a?(Enumerable)
|
||||
input = input.values if input.is_a?(Hash)
|
||||
input.select { |object| item_property(object, property) == value }
|
||||
end
|
||||
|
||||
|
|
|
@ -172,10 +172,15 @@ class TestFilters < Test::Unit::TestCase
|
|||
|
||||
context "where filter" do
|
||||
should "return any input that is not an array" do
|
||||
assert_equal Hash.new, @filter.where(Hash.new, nil, nil)
|
||||
assert_equal "some string", @filter.where("some string", "la", "le")
|
||||
end
|
||||
|
||||
should "filter objects in a hash appropriately" do
|
||||
hash = {"a"=>{"color"=>"red"}, "b"=>{"color"=>"blue"}}
|
||||
assert_equal 1, @filter.where(hash, "color", "red").length
|
||||
assert_equal [{"color"=>"red"}], @filter.where(hash, "color", "red")
|
||||
end
|
||||
|
||||
should "filter objects appropriately" do
|
||||
assert_equal 2, @filter.where(@array_of_objects, "color", "red").length
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue