From 441967510f58f9580b219c0a39d27d8c8cba3016 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Wed, 5 Oct 2016 13:03:28 +0200 Subject: [PATCH] bugfix: support nil entries in filter table --- lib/utils/filter.rb | 1 + test/unit/utils/filter_table_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/utils/filter.rb b/lib/utils/filter.rb index 80716df1f..74980b9ca 100644 --- a/lib/utils/filter.rb +++ b/lib/utils/filter.rb @@ -44,6 +44,7 @@ module FilterTable def initialize(resource, params, filters) @resource = resource @params = params + @params = [] if @params.nil? @filters = filters end diff --git a/test/unit/utils/filter_table_test.rb b/test/unit/utils/filter_table_test.rb index c8c1dbc04..aaff04b1f 100644 --- a/test/unit/utils/filter_table_test.rb +++ b/test/unit/utils/filter_table_test.rb @@ -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 }