tabulatr2 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1dc69e34a9977e78a0969398cdbbb39bd2601f4
4
- data.tar.gz: b4c0b9bd6cb6e97829767fc3f2a85942e49cfb11
3
+ metadata.gz: fd5b1a160633c8bae84ebece41b6f6d308665ec3
4
+ data.tar.gz: a0f086d976130d0dd0d7606df9be042466f4a563
5
5
  SHA512:
6
- metadata.gz: f4fa0da835396c1cc9e355559a74934e723a00fccbc26e5db23bd84ff2b603c198f0cf9b74126f5a1e9be09e59a37cd1d9e082a276c029adc7e67973228a025b
7
- data.tar.gz: 9c33aa54ee60d5035b02e229dcc37c0e9db393261a48ac4aa641a8cf1ba7b7c04e426d0af454cdcbb9a958dac8edfea69067d80179de68158c826a347b431bca
6
+ metadata.gz: 5100e0221f28bbcc286e290e69657bc1ba4df72d1bcebd19742605222ab954270c019e6cf7a6a6efcd74f66594f839807b3797bce579951cb1e0c3bcc528a53c
7
+ data.tar.gz: 75fabed7e79bd0c2e7200295b7cb20addf0e88b45ced815dec84375b4c775ea22fce2fbb64c517cfeda3939c14200ea154abd7d2a2ff4c41cc787f62c77d1a21
@@ -0,0 +1,19 @@
1
+ ## 0.8.3
2
+
3
+ * New table_column_options `cell_style` and `header_style`
4
+ Example:
5
+ ```
6
+ column :name, cell_style: {:'background-color' => 'red'}, header_style: {:'font-weight' => 'bold'}
7
+ ```
8
+
9
+ * Added `classes` attribute to `table_column_options`.
10
+ Example:
11
+ ```
12
+ column :foobar, table_column_options: {classes: "mycssclass foobar-column"}
13
+ ```
14
+
15
+ * Fixed prefiltering.
16
+ Example:
17
+ ```
18
+ tabulatr_for(Product.where(price: 10))
19
+ ```
data/Gemfile CHANGED
@@ -7,6 +7,11 @@ gem 'tabulatr2', path: './'
7
7
  gem 'jquery-rails'
8
8
  gem 'slim'
9
9
 
10
+ group :development do
11
+ gem 'better_errors'
12
+ gem 'binding_of_caller'
13
+ end
14
+
10
15
 
11
16
  group :development, :test do
12
17
  gem 'sqlite3', :require => 'sqlite3'
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  Require tabulatr2 in your Gemfile:
9
9
  ```ruby
10
- gem 'tabulatr2', github: 'provideal/tabulatr2'
10
+ gem 'tabulatr2'
11
11
  ```
12
12
  After that run `bundle install`.
13
13
 
@@ -193,6 +193,15 @@ Tabulatr = {
193
193
  return unescape(action).replace(/{{([\w:]+)}}/g, Tabulatr.replacer);
194
194
  },
195
195
 
196
+ submitFilterForm: function(tableId){
197
+ if($('.pagination[data-table='+ tableId +']').length == 0){
198
+ $('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
199
+ $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
200
+ }
201
+ Tabulatr.updateTable({page: 1, append: false}, tableId, true);
202
+ return false;
203
+ },
204
+
196
205
  createParameterString: function(hash, tableId){
197
206
  var tableName = tableId.split('_')[0];
198
207
  if(hash === undefined){
@@ -299,11 +308,7 @@ $(document).on('ready page:load', function(){
299
308
 
300
309
  $('form.tabulatr_filter_form').submit(function(ev){
301
310
  var tableId = $(this).data('table');
302
- if($('.pagination[data-table='+ tableId +']').length == 0){
303
- $('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
304
- $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
305
- }
306
- Tabulatr.updateTable({page: 1, append: false}, tableId, true);
311
+ Tabulatr.submitFilterForm(tableId);
307
312
  return false;
308
313
  });
309
314
 
@@ -433,6 +438,9 @@ $(document).on('click', 'a[data-hide-table-filter]', function(){
433
438
  $('a[data-show-table-filter="'+nam+'"]').show();
434
439
  if ($('div[data-filter-column-name]:visible').length <= 2)
435
440
  $('div[data-filter-column-name="_submit"]').hide('blind');
441
+
442
+ var tableId = $(this).parents('form').data('table');
443
+ Tabulatr.submitFilterForm(tableId);
436
444
  return false;
437
445
  })
438
446
 
@@ -440,7 +448,6 @@ $(document).on('change', 'select[data-tabulatr-date-filter]', function() {
440
448
  var select = $(this);
441
449
  var option = select.find('option:selected');
442
450
  var val = option.val();
443
- console.log(val);
444
451
  if (val === 'from_to') {
445
452
  select.parents('.controls').find(".from_to").show().removeClass('hidden');
446
453
  } else {
@@ -148,6 +148,10 @@ table.tabulatr_table {
148
148
 
149
149
  .tabulatr-filter-dialog-wrapper {
150
150
  display: block;
151
+
152
+ .submit-table{
153
+ z-index: 2;
154
+ }
151
155
  }
152
156
  }
153
157
 
@@ -24,12 +24,16 @@ table.table.tabulatr_table id=table_id data-path=table_options[:path] data-pages
24
24
  thead
25
25
  tr
26
26
  - columns.each do |column|
27
- th data-tabulatr-column-name=column.full_name align=column.align width=column.width valign=column.valign class="#{column.sortable ? 'tabulatr-sortable' : ''}"
27
+ - classes = column.sortable ? ['tabulatr-sortable'] : []
28
+ - classes = [classes, column.classes].flatten.compact.join(' ')
29
+ th data-tabulatr-column-name=column.full_name style=column.header_style class=classes
28
30
  = column.human_name
29
31
  tbody
30
32
  tfoot
31
33
  tr.empty_row
32
34
  - columns.each do |column|
33
- td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype align=column.align width=column.width valign=column.valign
35
+ - classes = column.sortable ? ['tabulatr-sortable'] : []
36
+ - classes = [classes, column.classes].flatten.compact.join(' ')
37
+ td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype style=column.cell_style class=classes
34
38
  span.pagination_trigger data-table="#{table_id}"
35
39
 
@@ -23,11 +23,11 @@ table.table.tabulatr_table
23
23
  thead
24
24
  tr
25
25
  - columns.each do |column|
26
- th data-tabulatr-column-name=column.full_name align=column.align width=column.width valign=column.valign
26
+ th data-tabulatr-column-name=column.full_name style=column.header_style
27
27
  = column.human_name
28
28
  tbody
29
29
  - records.each do |record|
30
30
  tr
31
31
  - columns.each do |column|
32
- td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype align=column.align width=column.width valign=column.valign
32
+ td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype style=column.cell_style
33
33
  = column.value_for(record, self)
@@ -22,10 +22,11 @@
22
22
  #++
23
23
 
24
24
  class ActionController::Base
25
- def tabulatr_for(klaz, tabulatr_data_class: nil, serializer: nil, render_action: nil, &block)
25
+ def tabulatr_for(relation, tabulatr_data_class: nil, serializer: nil, render_action: nil, &block)
26
+ klass = relation.respond_to?(:klass) ? relation.klass : relation
26
27
  respond_to do |format|
27
28
  format.json {
28
- records = klaz.tabulatr(tabulatr_data_class).data_for_table(params, &block)
29
+ records = klass.tabulatr(relation, tabulatr_data_class).data_for_table(params, &block)
29
30
  render json: records.to_tabulatr_json(serializer)
30
31
  }
31
32
  format.html {
@@ -25,15 +25,14 @@
25
25
  # the information of the params hash as created by a Tabulatr table
26
26
  if Object.const_defined? "ActiveRecord"
27
27
  class ActiveRecord::Base
28
- def self.tabulatr(tabulatr_data_class = nil)
29
- return tabulatr_data_class.new(self) if tabulatr_data_class
28
+ def self.tabulatr(relation, tabulatr_data_class = nil)
29
+ return tabulatr_data_class.new(relation) if tabulatr_data_class
30
30
  begin
31
- klaz = self.respond_to?(:klass) ? self.klass : self
32
- "#{klaz.name}TabulatrData".constantize.new(self)
31
+ "#{self.name}TabulatrData".constantize.new(relation)
33
32
  rescue NameError => e
34
33
  puts e.message
35
34
  # TODO: Better message
36
- raise "No class `#{klaz.name}TabulatrData' defined. Explanation here."
35
+ raise "No class `#{self.name}TabulatrData' defined. Explanation here."
37
36
  end
38
37
  end
39
38
  end
@@ -26,17 +26,17 @@ class Tabulatr::Renderer::Column
26
26
 
27
27
  attr_accessor *%i{name header width align valign wrap type th_html filter_html
28
28
  filter checkbox_value checkbox_label filter_width range_filter_symbol
29
- sortable table_name block klass format map}
29
+ sortable table_name block klass format map classes cell_style header_style}
30
30
 
31
31
  def self.from(
32
32
  name: nil,
33
33
  table_name: nil,
34
- header: false,
34
+ header: nil,
35
+ classes: nil,
35
36
  width: false,
36
37
  align: false,
37
38
  valign: false,
38
- wrap: true,
39
- type: :string,
39
+ wrap: nil,
40
40
  th_html: false,
41
41
  filter_html: false,
42
42
  filter: true,
@@ -46,17 +46,19 @@ class Tabulatr::Renderer::Column
46
46
  format: nil,
47
47
  map: true,
48
48
  klass: nil,
49
+ cell_style: {},
50
+ header_style: {},
49
51
  &block)
50
52
  b = block_given? ? block : nil
51
53
  self.new(
52
54
  name: name,
53
55
  table_name: table_name,
54
56
  header: header,
57
+ classes: classes,
55
58
  width: width,
56
59
  align: align,
57
60
  valign: valign,
58
61
  wrap: wrap,
59
- type: type,
60
62
  th_html: th_html,
61
63
  filter_html: filter_html,
62
64
  filter: filter,
@@ -66,8 +68,10 @@ class Tabulatr::Renderer::Column
66
68
  format: format,
67
69
  map: map,
68
70
  klass: klass,
69
- block: b
70
- )
71
+ block: b,
72
+ cell_style: cell_style,
73
+ header_style: header_style
74
+ ).apply_styles!
71
75
  end
72
76
 
73
77
  def klassname() @_klassname ||= @klass.name.underscore end
@@ -81,6 +85,24 @@ class Tabulatr::Renderer::Column
81
85
  def checkbox?() false end
82
86
  def action?() false end
83
87
 
88
+ def apply_styles!
89
+ # raise cell_style.inspect
90
+ self.cell_style = style_options.merge(self.cell_style).map{|e| e.join(':')}.join(';')
91
+ self.header_style = style_options.merge(self.header_style).map{|e| e.join(':')}.join(';')
92
+ self
93
+ end
94
+
95
+ def style_options
96
+ default_style_attributes = {
97
+ :'text-align' => align,
98
+ width: width,
99
+ :'vertical-align' => valign,
100
+ :'white-space' => wrap
101
+ }.select{|k,v| v}
102
+
103
+ default_style_attributes || {}
104
+ end
105
+
84
106
  def value_for(record, view)
85
107
  if block
86
108
  return view.instance_exec(record, &block)
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.8.2"
25
+ VERSION = "0.8.3"
26
26
  end
@@ -42,6 +42,10 @@ class ProductsController < ApplicationController
42
42
  end
43
43
  end
44
44
 
45
+ def with_styling
46
+ tabulatr_for Product
47
+ end
48
+
45
49
  def implicit_columns
46
50
  tabulatr_for Product
47
51
  end
@@ -0,0 +1,10 @@
1
+ <%= table_for Product, :paginate => true do |t|
2
+ t.checkbox
3
+ t.column :title, sortable: true, width: '60px', align: 'left', valign: 'top', wrap: 'nowrap', cell_style: {:'background-color' => 'green'}, header_style: {color: 'orange'}
4
+ t.column :price, filter: :range
5
+ t.column :active, sortable: false
6
+ t.column :vendor_product_name, header: 'Product by vendor'
7
+ t.column :updated_at, filter: :date
8
+ t.association :vendor, :name, filter: :exact
9
+ t.association :tags, :titletd
10
+ end %>
@@ -8,6 +8,7 @@ Rails.application.routes.draw do
8
8
  get :stupid_array
9
9
  get :with_batch_actions
10
10
  get :implicit_columns
11
+ get :with_styling
11
12
  end
12
13
  end
13
14
 
@@ -23,14 +23,15 @@ describe "Tabulatr" do
23
23
 
24
24
  it "contains buttons" do
25
25
  visit simple_index_products_path
26
- ['Filter'].each do |n|
27
- page.should have_content(n)
26
+ ['.tabulatr-filter-menu-wrapper', '.tabulatr-batch-actions-menu-wrapper',
27
+ '.tabulatr-paginator-wrapper'].each do |n|
28
+ expect(find(n).visible?)
28
29
  end
29
30
  end
30
31
 
31
32
  it "contains column headers" do
32
33
  visit simple_index_products_path
33
- ['Title','Price','Active','Updated At'].each do |n|
34
+ ['Title','Price','Active','Updated at'].each do |n|
34
35
  find('.tabulatr_table thead').should have_content(n)
35
36
  end
36
37
  end
@@ -57,7 +58,7 @@ describe "Tabulatr" do
57
58
  end
58
59
  end
59
60
 
60
- it "contains the actual data multiple", js: true do
61
+ it "contains the actual data multiple times", js: true do
61
62
  9.times do |i|
62
63
  product = Product.create!(:title => names[i], :active => i.even?, :price => 11.0+i,
63
64
  :vendor => i.even? ? @vendor1 : @vendor2)
@@ -72,7 +73,7 @@ describe "Tabulatr" do
72
73
  product = Product.create!(:title => n, :active => i.even?, :price => 20.0+i,
73
74
  :vendor => i.even? ? @vendor1 : @vendor2)
74
75
  visit simple_index_products_path
75
- page.should_not have_content(n)
76
+ page.should_not have_content(/\s+#{n}\s+/)
76
77
  page.should_not have_content((30.0+i).to_s)
77
78
  end
78
79
  end
@@ -128,19 +129,24 @@ describe "Tabulatr" do
128
129
  Product.create!(:title => n, :active => true, :price => 10.0)
129
130
  end
130
131
  visit simple_index_products_path
131
- find("a[href='#tabulatr_filter_dialog_product']").click()
132
- within("#tabulatr_filter_dialog_product") do
133
- fill_in("product_filter[title][like]", :with => "ore")
132
+ find(".tabulatr-filter-menu-wrapper a.btn").click
133
+ within(".tabulatr-filter-menu-wrapper .dropdown.open") do
134
+ find_link('Title').click
135
+ end
136
+ expect(find('.dropdown-menu').visible?)
137
+ find(".tabulatr-filter-menu-wrapper a.btn").trigger('click')
138
+ within(".tabulatr_filter_form") do
139
+ fill_in("product_filter[title][like]", with: "ore")
140
+ expect(find('#title_from').visible?)
141
+ click_button("Apply")
134
142
  end
135
- click_button("Apply")
136
143
  page.should have_content("lorem")
137
144
  page.should have_content("labore")
138
145
  page.should have_content("dolore")
139
- find("a[href='#tabulatr_filter_dialog_product']").click()
140
- within("#tabulatr_filter_dialog_product") do
146
+ within(".tabulatr_filter_form") do
141
147
  fill_in("product_filter[title][like]", :with => "loreem")
148
+ click_button("Apply")
142
149
  end
143
- click_button("Apply")
144
150
  page.should_not have_content("lorem")
145
151
  page.should_not have_content("labore")
146
152
  page.should_not have_content("dolore")
@@ -150,31 +156,63 @@ describe "Tabulatr" do
150
156
  Product.create!([{title: 'foo', vendor: @vendor1},
151
157
  {title: 'bar', vendor: @vendor2}])
152
158
  visit simple_index_products_path
153
- find('.icon-filter').trigger('click')
154
- fill_in("product_filter[__association][vendor.name]", :with => 'producer')
155
- click_button("Apply")
159
+ find(".tabulatr-filter-menu-wrapper a.btn").click
160
+ within(".tabulatr-filter-menu-wrapper .dropdown.open") do
161
+ find_link('Vendor Name').click
162
+ end
163
+ find(".tabulatr-filter-menu-wrapper a.btn").trigger('click')
164
+ within(".tabulatr_filter_form") do
165
+ fill_in("product_filter[vendor:name]", with: "producer")
166
+ click_button("Apply")
167
+ end
156
168
  page.should have_content(@vendor2.name)
157
- page.should_not have_content(@vendor1.name)
169
+ page.should have_no_content(@vendor1.name)
158
170
  end
159
171
 
160
172
  it "filters with range", js: true do
161
173
  n = names.length
162
174
  Product.create!([{title: 'foo', price: 5}, {title: 'bar', price: 17}])
163
175
  visit simple_index_products_path
164
- find('.icon-filter').trigger('click')
165
- within('form.tabulatr_filter_form') do
176
+ find(".tabulatr-filter-menu-wrapper a.btn").click
177
+ within(".tabulatr-filter-menu-wrapper .dropdown.open") do
178
+ find_link('Price').click
179
+ end
180
+ find(".tabulatr-filter-menu-wrapper a.btn").trigger('click')
181
+ within('.tabulatr_filter_form') do
166
182
  fill_in("product_filter[price][from]", :with => 4)
167
183
  fill_in("product_filter[price][to]", :with => 10)
184
+ click_button("Apply")
168
185
  end
169
- click_button("Apply")
170
- page.should have_content('foo')
171
- page.should_not have_content('bar')
172
- find('.icon-filter').trigger('click')
173
- fill_in("product_filter[price][from]", :with => 12)
174
- fill_in("product_filter[price][to]", :with => 19)
175
- click_button("Apply")
176
- page.should have_content('bar')
177
- page.should_not have_content('foo')
186
+ page.find(".tabulatr_table tbody tr[data-id='#{Product.first.id}']").should have_content('foo')
187
+ page.has_no_css?(".tabulatr_table tbody tr[data-id='#{Product.last.id}']")
188
+ within('.tabulatr_filter_form') do
189
+ fill_in("product_filter[price][from]", :with => 12)
190
+ fill_in("product_filter[price][to]", :with => 19)
191
+ click_button("Apply")
192
+ end
193
+ page.should have_selector(".tabulatr_table tbody tr[data-id='#{Product.last.id}']")
194
+ page.should have_no_selector(".tabulatr_table tbody tr[data-id='#{Product.first.id}']")
195
+ end
196
+
197
+ it 'removes the filters', js: true do
198
+ Product.create!([{title: 'foo', price: 5}, {title: 'bar', price: 5}])
199
+ visit simple_index_products_path
200
+ find(".tabulatr-filter-menu-wrapper a.btn").click
201
+ within(".tabulatr-filter-menu-wrapper .dropdown.open") do
202
+ find_link('Title').click
203
+ end
204
+ expect(find('.dropdown-menu').visible?)
205
+ find(".tabulatr-filter-menu-wrapper a.btn").trigger('click')
206
+ within(".tabulatr_filter_form") do
207
+ fill_in("product_filter[title][like]", with: "foo")
208
+ expect(find('#title_from').visible?)
209
+ click_button("Apply")
210
+ end
211
+ expect(page).to have_content('foo')
212
+ expect(page).to have_no_content('bar')
213
+ find("a[data-hide-table-filter='title']").click
214
+ expect(page).to have_content('foo')
215
+ expect(page).to have_content('bar')
178
216
  end
179
217
  end
180
218
 
@@ -188,12 +226,16 @@ describe "Tabulatr" do
188
226
  (1..10).each do |i|
189
227
  page.should have_content names[i-1]
190
228
  end
191
- find("#product_sort_title").click
229
+ within('.tabulatr_table thead') do
230
+ find('th[data-tabulatr-column-name=title]').click
231
+ end
192
232
  snames = names.sort
193
233
  (1..10).each do |i|
194
234
  page.should have_content snames[i-1]
195
235
  end
196
- find("#product_sort_title").click
236
+ within('.tabulatr_table thead') do
237
+ find('th[data-tabulatr-column-name=title]').click
238
+ end
197
239
  (1..10).each do |i|
198
240
  page.should have_content snames[-i]
199
241
  end
@@ -214,44 +256,28 @@ describe "Tabulatr" do
214
256
  page.should have_content(product.title)
215
257
  page.should have_content(product.title.upcase)
216
258
  page.should have_content(product.price)
217
- find(".tabulatr_table tbody #product_#{product.id}").should have_content(product.vendor.name)
218
- find(".tabulatr_table tbody #product_#{product.id}").should have_content(product.title)
219
- find(".tabulatr_table tbody #product_#{product.id}").should have_content("foo#{product.title}foo")
220
- find(".tabulatr_table tbody #product_#{product.id}").should have_content("bar#{product.title}bar")
221
- find(".tabulatr_table tbody #product_#{product.id}").should have_content("%08.4f" % product.price)
222
- find(".tabulatr_table tbody #product_#{product.id}").should have_content(product.tags.count)
259
+ page.should have_content(product.vendor.name)
260
+ page.should have_content(product.title)
261
+ page.should have_content("foo#{product.title}foo")
262
+ page.should have_content("bar#{product.title}bar")
263
+ page.should have_content("%08.4f" % product.price)
264
+ page.should have_content(product.tags.count)
223
265
  product.tags.each do |tag|
224
- find(".tabulatr_table tbody #product_#{product.id}").should have_content(tag.title)
225
- find(".tabulatr_table tbody #product_#{product.id}").should have_content("foo#{tag.title}foo")
226
- find(".tabulatr_table tbody #product_#{product.id}").should have_content("bar#{tag.title}bar")
266
+ page.should have_content(tag.title)
267
+ page.should have_content("foo#{tag.title}foo")
268
+ page.should have_content("bar#{tag.title}bar")
227
269
  end
228
270
  end
229
271
  end
230
272
  end
231
273
 
232
274
  describe "Batch actions", js: true do
233
- it "shows the actions" do
234
- visit with_batch_actions_products_path
235
- find(".tabulatr-wrench").should have_content('Batch actions')
236
- end
237
275
 
238
276
  it "hides the actions if there are none" do
239
- visit simple_index_products_path
240
- page.should have_no_selector('.tabulatr-wrench')
277
+ visit one_item_per_page_with_pagination_products_path
278
+ page.should have_no_selector('.tabulatr-batch-actions-menu-wrapper a')
241
279
  end
242
280
 
243
- it 'is initially not active' do
244
- visit with_batch_actions_products_path
245
- page.should have_selector('.tabulatr-wrench.disabled')
246
- end
247
-
248
- it 'becomes active when a checkbox is checked' do
249
- product = Product.create!(:title => names[0], :active => true, :price => 10.0)
250
- visit with_batch_actions_products_path
251
- find('.tabulatr-checkbox').trigger('click')
252
- page.should have_no_selector('.tabulatr-wrench.disabled')
253
- page.should have_selector('.tabulatr-wrench')
254
- end
255
281
 
256
282
  it 'executes the action when clicked' do
257
283
  product1 = Product.create!(:title => names[0], :active => true, :price => 10.0)
@@ -261,9 +287,26 @@ describe "Tabulatr" do
261
287
  visit with_batch_actions_products_path
262
288
  find(".tabulatr-checkbox[value='#{product1.id}']").trigger('click')
263
289
  find(".tabulatr-checkbox[value='#{product3.id}']").trigger('click')
264
- find('.tabulatr-wrench').trigger('click')
265
- find("a[name='product_batch\\[destroy\\]']").trigger('click')
290
+ find('.tabulatr-batch-actions-menu-wrapper a').click
291
+ within('.dropdown.open') do
292
+ click_link 'Delete'
293
+ end
266
294
  page.has_css?(".tabulatr_table tbody tr", :count => 1)
267
295
  end
268
296
  end
297
+
298
+ describe "Column options", js: true do
299
+ it 'applys the given style' do
300
+ p = Product.create!(:title => names[0], :active => true, :price => 10.0)
301
+ visit with_styling_products_path
302
+ cell = find(".tabulatr_table tbody td[data-tabulatr-column-name='title']")
303
+ header = find(".tabulatr_table thead th[data-tabulatr-column-name='title']")
304
+ cell_without_style = find(".tabulatr_table tbody td[data-tabulatr-column-name='price']")
305
+ header_without_style = find(".tabulatr_table thead th[data-tabulatr-column-name='price']")
306
+ expect(cell[:style]).to eql 'text-align:left;width:60px;vertical-align:top;white-space:nowrap;background-color:green'
307
+ expect(header[:style]).to eql 'text-align:left;width:60px;vertical-align:top;white-space:nowrap;color:orange'
308
+ expect(cell_without_style[:style]).to be_empty
309
+ expect(header_without_style[:style]).to be_empty
310
+ end
311
+ end
269
312
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tabulatr::Data do
4
+ it 'prefilters the result' do
5
+ Tabulatr::Data.any_instance.stub_chain(:table_columns, :klass=).and_return(Product)
6
+ Tabulatr::Data.any_instance.stub_chain(:table_columns, :map).as_null_object
7
+
8
+ td = Tabulatr::Data.new(Product.where(price: 10))
9
+ td.data_for_table(example_params)
10
+ expect(td.instance_variable_get('@relation').to_sql).to match(/.+WHERE \"products\".\"price\" = 10.+/)
11
+ end
12
+ end
13
+
14
+
15
+ private
16
+
17
+ def example_params
18
+ {
19
+ page: 1,
20
+ pagesize: 20,
21
+ arguments: 'title,price,active,vendor_product_name,updated_at,vendor:name,tags:title',
22
+ table_id: 'product_table',
23
+ product_search: nil,
24
+ product_sort: nil
25
+ }
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-29 00:00:00.000000000 Z
13
+ date: 2013-11-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -143,6 +143,7 @@ files:
143
143
  - spec/dummy/app/views/products/simple_index.html.erb
144
144
  - spec/dummy/app/views/products/stupid_array.html.erb
145
145
  - spec/dummy/app/views/products/with_batch_actions.html.erb
146
+ - spec/dummy/app/views/products/with_styling.html.erb
146
147
  - spec/dummy/bin/bundle
147
148
  - spec/dummy/bin/rails
148
149
  - spec/dummy/bin/rake
@@ -176,6 +177,7 @@ files:
176
177
  - spec/dummy/public/500.html
177
178
  - spec/dummy/public/favicon.ico
178
179
  - spec/features/tabulatrs_spec.rb
180
+ - spec/lib/tabulatr/data/data_spec.rb
179
181
  - spec/spec_helper.rb
180
182
  - tabulatr.gemspec
181
183
  homepage: http://github.com/provideal/tabulatr2
@@ -230,6 +232,7 @@ test_files:
230
232
  - spec/dummy/app/views/products/simple_index.html.erb
231
233
  - spec/dummy/app/views/products/stupid_array.html.erb
232
234
  - spec/dummy/app/views/products/with_batch_actions.html.erb
235
+ - spec/dummy/app/views/products/with_styling.html.erb
233
236
  - spec/dummy/bin/bundle
234
237
  - spec/dummy/bin/rails
235
238
  - spec/dummy/bin/rake
@@ -263,5 +266,6 @@ test_files:
263
266
  - spec/dummy/public/500.html
264
267
  - spec/dummy/public/favicon.ico
265
268
  - spec/features/tabulatrs_spec.rb
269
+ - spec/lib/tabulatr/data/data_spec.rb
266
270
  - spec/spec_helper.rb
267
271
  has_rdoc: