Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sift/filtrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/filtrator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down