diff --git a/lib/sift/filtrator.rb b/lib/sift/filtrator.rb index 36cc6b0..86bce57 100644 --- a/lib/sift/filtrator.rb +++ b/lib/sift/filtrator.rb @@ -46,7 +46,7 @@ def active_sorts_hash def active_filters filters.select do |filter| - filter_params[filter.param].present? || filter.default || filter.always_active? + filter_params.include?(filter.param) || filter.default || filter.always_active? end end end diff --git a/test/filtrator_test.rb b/test/filtrator_test.rb index 99bb406..b277a52 100644 --- a/test/filtrator_test.rb +++ b/test/filtrator_test.rb @@ -18,6 +18,19 @@ class FiltratorTest < ActiveSupport::TestCase assert_equal Post.where(id: post.id), collection end + test "it filters by boolean field even when the value is false" do + Post.create!(visible: false) + filter = Sift::Filter.new(:visible, :boolean, :visible, nil) + + collection = Sift::Filtrator.filter( + Post.all, + { filters: { visible: false } }, + [filter], + ) + + assert_equal Post.where(visible: false), collection + end + test "it will not try to make a range out of a string field that includes ..." do post = Post.create!(title: "wow...man") filter = Sift::Filter.new(:title, :string, :title, nil)