diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index d6f0fa03..cd928891 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -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 diff --git a/test/test_filters.rb b/test/test_filters.rb index 35ea6f0b..d7457cdd 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -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