Merge pull request #1201 from chef/dr/empty-filter

bugfix: support nil entries in filter table
This commit is contained in:
Alex Pop 2016-10-05 13:12:35 +01:00 committed by GitHub
commit 78b02c754d
2 changed files with 11 additions and 0 deletions

View file

@ -44,6 +44,7 @@ module FilterTable
def initialize(resource, params, filters)
@resource = resource
@params = params
@params = [] if @params.nil?
@filters = filters
end

View file

@ -28,6 +28,16 @@ describe FilterTable do
factory.must_be_kind_of FilterTable::Factory
end
it 'supports empty arrays' do
factory.add_accessor(:where).add(:baz).connect(resource, :data)
resource.new([]).where { false }.params.must_equal []
end
it 'supports nil arrays' do
factory.add_accessor(:where).add(:baz).connect(resource, :data)
resource.new(nil).where { false }.params.must_equal []
end
it 'retrieves the resource from all entries' do
factory.add_accessor(:where)
.add(:baz?) { |x| x.resource }