Fix range usage in filter table

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2021-07-14 14:27:01 +05:30
parent ec76259eb1
commit 69b15b6e64
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