Merge pull request #5598 from inspec/nm/filtertable-range

Fix range based filtering in filter tables
This commit is contained in:
Clinton Wolfe 2021-08-17 20:51:05 -04:00 committed by GitHub
commit d191964e23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -256,7 +256,7 @@ module FilterTable
end
def matches(x, y)
x === y # rubocop:disable Style/CaseEquality
y === x # rubocop:disable Style/CaseEquality
end
def filter_raw_data(current_raw_data, field, desired_value)

View file

@ -35,6 +35,11 @@ describe FilterTable do
_(resource.new(nil).where { false }.params).must_equal []
end
it "supports range" do
factory.add_accessor(:where).connect(resource, :data)
_(instance.where({ foo: (3..5) }).params).must_equal [data[0]]
end
it "retrieves the resource from all entries" do
factory.add_accessor(:where)
.add(:baz?) { |x| x.resource } # rubocop: disable Style/SymbolProc
@ -181,4 +186,16 @@ describe FilterTable do
_(instance.baz(/zzz/).params).must_equal []
end
end
describe "with a range filter" do
before { factory.add(:foo).connect(resource, :data) }
it "filter and retrieves data with matching range" do
_(instance.foo((3..5)).params).must_equal [data[0]]
end
it "filter and retrieves empty result if no data in matching range" do
_(instance.foo((4..5)).params).must_equal []
end
end
end