Skip to content

Commit

Permalink
Rename filter option of table_for to filters
Browse files Browse the repository at this point in the history
This needs to be done to not conceal the `table_option` also named `filter`.

fixes #44
  • Loading branch information
Crunch09 committed Aug 25, 2015
1 parent 330263c commit 63cd016
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## UNRELEASED
* Rename `filter` option of `table_for` to `filters` to not conceal the
`table_option` also named `filter`.

## 0.9.20
* Add `filter` to DSL to define custom filters

Expand Down
4 changes: 2 additions & 2 deletions lib/tabulatr/rails/action_view.rb
Expand Up @@ -23,9 +23,9 @@

class ActionView::Base
# render the table in a view
def table_for(klass, columns: [], filter: [], tabulatr_data_class: nil, **opts, &block)
def table_for(klass, columns: [], filters: [], tabulatr_data_class: nil, **opts, &block)
@_tabulatr_table_index += 1
Tabulatr::Renderer.build_table(klass, self, opts, columns, filter, tabulatr_data_class, &block)
Tabulatr::Renderer.build_table(klass, self, opts, columns, filters, tabulatr_data_class, &block)
end

def static_table_for(records, opts={}, &block)
Expand Down
6 changes: 4 additions & 2 deletions lib/tabulatr/renderer/renderer.rb
Expand Up @@ -131,12 +131,14 @@ def get_data_class(name = '')
def set_columns_and_filters(data_class, columns, filters, &block)
if block_given?
@columns = ColumnsFromBlock.process(@klass, data_class, &block).columns
elsif columns.any? || filters.any?
elsif columns.any?
@columns = get_requested_columns(data_class.table_columns, columns)
@filters = get_requested_filters(data_class.filters, filters)
else
@columns = data_class.table_columns
end
if filters && filters.any?
@filters = get_requested_filters(data_class.filters, filters)
end
end

end
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/controllers/products_controller.rb
Expand Up @@ -53,4 +53,8 @@ def local_storage
raise e
end
end

def without_filters
tabulatr_for Product
end
end
1 change: 1 addition & 0 deletions spec/dummy/app/views/products/without_filters.html.erb
@@ -0,0 +1 @@
<%= table_for Product, filter: false %>
1 change: 1 addition & 0 deletions spec/dummy/config/routes.rb
Expand Up @@ -10,6 +10,7 @@
get :implicit_columns
get :with_styling
get :local_storage
get :without_filters
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/features/tabulatrs_spec.rb
Expand Up @@ -153,6 +153,11 @@
expect(page).to have_selector('td[data-tabulatr-column-name="vendor:name"]', text: @vendor2.name)
end

scenario "without filters", js: true do
visit without_filters_products_path
expect(page).to have_no_content('Filter')
end

scenario "filters with range", js: true do
n = names.length
Product.create!([{title: 'foo', price: 5}, {title: 'bar', price: 17}])
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/tabulatr/renderer/renderer_spec.rb
Expand Up @@ -45,5 +45,13 @@ def double_view
filters = renderer.instance_variable_get('@filters')
expect(filters.map(&:name)).to match_array([:simple_filter])
end

it 'renders no custom filters if `filters` option is false' do
allow_any_instance_of(Tabulatr::Data).to receive(:table_columns).and_return([])
renderer = Tabulatr::Renderer.new(Product, double_view)
renderer.build_table([], false, 'FakeRendererSpecTabulatrData')
filters = renderer.instance_variable_get('@filters')
expect(filters).to be_nil
end
end
end

0 comments on commit 63cd016

Please sign in to comment.