tableficate 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/README.markdown +6 -4
  2. data/app/views/tableficate/_data.html.erb +7 -1
  3. data/app/views/tableficate/_header.html.erb +2 -2
  4. data/app/views/tableficate/_table.html.erb +16 -23
  5. data/app/views/tableficate/_table_for.html.erb +9 -0
  6. data/app/views/tableficate/filters/_check_box_choice.html.erb +3 -0
  7. data/app/views/tableficate/filters/_form.html.erb +16 -0
  8. data/app/views/tableficate/filters/_radio_choice.html.erb +3 -0
  9. data/changelog.markdown +17 -0
  10. data/lib/generators/tableficate/theme/theme_generator.rb +17 -1
  11. data/lib/tableficate.rb +3 -0
  12. data/lib/tableficate/action_column.rb +2 -2
  13. data/lib/tableficate/caption.rb +29 -0
  14. data/lib/tableficate/column.rb +13 -7
  15. data/lib/tableficate/empty.rb +34 -0
  16. data/lib/tableficate/filters/base.rb +7 -5
  17. data/lib/tableficate/filters/check_box.rb +1 -1
  18. data/lib/tableficate/filters/choice.rb +2 -2
  19. data/lib/tableficate/filters/collection_base.rb +13 -0
  20. data/lib/tableficate/filters/input.rb +2 -2
  21. data/lib/tableficate/filters/input_range.rb +6 -6
  22. data/lib/tableficate/filters/radio.rb +1 -1
  23. data/lib/tableficate/filters/select.rb +1 -1
  24. data/lib/tableficate/filters/select_range.rb +4 -4
  25. data/lib/tableficate/finder.rb +70 -28
  26. data/lib/tableficate/helper.rb +44 -47
  27. data/lib/tableficate/table.rb +64 -24
  28. data/lib/tableficate/utils.rb +27 -2
  29. data/lib/tableficate/version.rb +1 -1
  30. data/spec/action_column_spec.rb +9 -1
  31. data/spec/base_spec.rb +10 -0
  32. data/spec/caption_spec.rb +33 -0
  33. data/spec/column_spec.rb +29 -0
  34. data/spec/empty_spec.rb +45 -0
  35. data/spec/filters/base_spec.rb +6 -5
  36. data/spec/filters/choice_spec.rb +5 -2
  37. data/spec/filters/collection_spec.rb +4 -4
  38. data/spec/filters/input_range_spec.rb +10 -8
  39. data/spec/filters/select_range_spec.rb +79 -0
  40. data/spec/finder_spec.rb +48 -1
  41. data/spec/generators/tableficate_theme_spec.rb +14 -0
  42. data/spec/table_spec.rb +114 -3
  43. data/spec/test_app/app/controllers/filters_controller.rb +1 -1
  44. data/spec/test_app/app/controllers/tests_controller.rb +5 -0
  45. data/spec/test_app/app/controllers/themes_controller.rb +7 -0
  46. data/spec/test_app/app/views/filters/html5_input_types.html.erb +31 -0
  47. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box_choice.html.erb +2 -0
  48. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio_choice.html.erb +2 -0
  49. data/spec/test_app/app/views/tests/index.html.erb +13 -0
  50. data/spec/test_app/app/views/themes/caption.html.erb +9 -0
  51. data/spec/test_app/app/views/themes/column_attrs.html.erb +7 -0
  52. data/spec/test_app/app/views/themes/column_cell_attrs.html.erb +7 -0
  53. data/spec/test_app/app/views/themes/column_cell_attrs_with_proc.html.erb +7 -0
  54. data/spec/test_app/app/views/themes/column_header_attrs.html.erb +7 -0
  55. data/spec/test_app/app/views/themes/empty_with_data.html.erb +9 -0
  56. data/spec/test_app/app/views/themes/empty_with_no_data.html.erb +9 -0
  57. data/spec/test_app/app/views/themes/no_caption.html.erb +7 -0
  58. data/spec/test_app/app/views/themes/no_column_attrs.html.erb +7 -0
  59. data/spec/test_app/config/application.rb +1 -1
  60. data/spec/test_app/config/routes.rb +2 -0
  61. data/spec/test_app/db/migrate/20111227224959_additional_columns.rb +73 -0
  62. data/spec/test_app/db/migrate/20111230203456_created_at_specific_dates.rb +11 -0
  63. data/spec/test_app/db/schema.rb +10 -3
  64. data/spec/test_app/db/test.sqlite3 +0 -0
  65. data/spec/theme/caption_spec.rb +15 -0
  66. data/spec/theme/column_spec.rb +35 -0
  67. data/spec/theme/empty_spec.rb +15 -0
  68. data/spec/utils_spec.rb +44 -4
  69. metadata +69 -58
  70. data/spec/test_app/app/views/tableficate/custom_check_box_block/_data.html.erb +0 -1
  71. data/spec/test_app/app/views/tableficate/custom_check_box_block/_header.html.erb +0 -8
  72. data/spec/test_app/app/views/tableficate/custom_check_box_block/_row.html.erb +0 -5
  73. data/spec/test_app/app/views/tableficate/custom_check_box_block/_table.html.erb +0 -36
  74. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box.html.erb +0 -7
  75. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input.html.erb +0 -4
  76. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input_range.html.erb +0 -6
  77. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_radio.html.erb +0 -4
  78. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select.html.erb +0 -4
  79. data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select_range_filter.html.erb +0 -6
  80. data/spec/test_app/app/views/tableficate/custom_radio_block/_data.html.erb +0 -1
  81. data/spec/test_app/app/views/tableficate/custom_radio_block/_header.html.erb +0 -8
  82. data/spec/test_app/app/views/tableficate/custom_radio_block/_row.html.erb +0 -5
  83. data/spec/test_app/app/views/tableficate/custom_radio_block/_table.html.erb +0 -36
  84. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_check_box.html.erb +0 -4
  85. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input.html.erb +0 -4
  86. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input_range.html.erb +0 -6
  87. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio.html.erb +0 -7
  88. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select.html.erb +0 -4
  89. data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select_range_filter.html.erb +0 -6
  90. data/spec/test_app/public/index.html +0 -241
@@ -4,24 +4,25 @@ describe Tableficate::Filter::Base do
4
4
  before(:all) do
5
5
  @table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {})
6
6
  @table.column(:first_name, header: 'Given Name')
7
+ @first_name_filter = Tableficate::Filter::Base.new(@table, :first_name)
7
8
  end
8
9
 
9
10
  it 'should find the correct template type' do
10
- Tableficate::Filter::Base.new(@table, :first_name).template.should == 'filters/base'
11
+ @first_name_filter.template.should == 'filters/base'
11
12
  end
12
13
 
13
14
  it 'should use the provided label or default to the column header' do
14
- Tableficate::Filter::Base.new(@table, :first_name).label.should == 'Given Name'
15
+ @first_name_filter.label.should == 'Given Name'
15
16
  Tableficate::Filter::Base.new(@table, :first_name, label: 'First').label.should == 'First'
16
17
  end
17
18
 
18
19
  it 'should provide a field name' do
19
- Tableficate::Filter::Base.new(@table, :first_name).field_name.should == "#{@table.as}[filter][first_name]"
20
+ @first_name_filter.field_name.should == "#{@table.as}[filter][first_name]"
20
21
  end
21
22
 
22
23
  it 'should provide a field value when given params or a blank value' do
23
- Tableficate::Filter::Base.new(@table, :first_name).field_value({filter: {first_name: 'Aaron'}}).should == 'Aaron'
24
- Tableficate::Filter::Base.new(@table, :first_name).field_value({}).should == ''
24
+ @first_name_filter.field_value({filter: {first_name: 'Aaron'}}).should == 'Aaron'
25
+ @first_name_filter.field_value({}).should == ''
25
26
  end
26
27
 
27
28
  it 'should allow for filters that do not match a particular field' do
@@ -4,10 +4,13 @@ describe Tableficate::Filter::Choice do
4
4
  it 'should mark a choice as selected if it has a :selected or :checked option' do
5
5
  choice = Tableficate::Filter::Choice.new('foo', 'bar', {selected: 'selected'})
6
6
  choice.selected?.should be true
7
- choice.options[:selected].should be nil
7
+ choice.attrs[:selected].should be nil
8
+
9
+ choice = Tableficate::Filter::Choice.new('foo', 'bar')
10
+ choice.selected?.should be false
8
11
 
9
12
  choice = Tableficate::Filter::Choice.new('foo', 'bar', {checked: 'checked'})
10
13
  choice.checked?.should be true
11
- choice.options[:checked].should be nil
14
+ choice.attrs[:checked].should be nil
12
15
  end
13
16
  end
@@ -75,9 +75,9 @@ describe Tableficate::Filter::Collection do
75
75
 
76
76
  1.upto(3) do |i|
77
77
  if i == 2
78
- collection[i - 1].options[:disabled].should == 'disabled'
78
+ collection[i - 1].attrs[:disabled].should == 'disabled'
79
79
  else
80
- collection[i - 1].options.has_key?(:disabled).should be false
80
+ collection[i - 1].attrs.has_key?(:disabled).should be false
81
81
  end
82
82
  end
83
83
 
@@ -85,9 +85,9 @@ describe Tableficate::Filter::Collection do
85
85
 
86
86
  1.upto(3) do |i|
87
87
  if i == 2 or i == 3
88
- collection[i - 1].options[:disabled].should == 'disabled'
88
+ collection[i - 1].attrs[:disabled].should == 'disabled'
89
89
  else
90
- collection[i - 1].options.has_key?(:disabled).should be false
90
+ collection[i - 1].attrs.has_key?(:disabled).should be false
91
91
  end
92
92
  end
93
93
  end
@@ -7,19 +7,20 @@ describe Tableficate::Filter::InputStart do
7
7
  template.lookup_context.stub!(:exists?).and_return(true)
8
8
  @table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
9
9
  @table.column(:year)
10
+ @input_start_filter = Tableficate::Filter::InputStart.new(@table, :year)
10
11
  end
11
12
 
12
13
  it 'should append "[start]" to field_name' do
13
- Tableficate::Filter::InputStart.new(@table, :year).field_name == "#{@table.as}[filter][year][start]"
14
+ @input_start_filter.field_name == "#{@table.as}[filter][year][start]"
14
15
  end
15
16
 
16
17
  it 'should append "_start" to the name' do
17
- Tableficate::Filter::InputStart.new(@table, :year).name == :year_start
18
+ @input_start_filter.name == :year_start
18
19
  end
19
20
 
20
21
  it 'should provide a field value when given params or a blank value' do
21
- Tableficate::Filter::InputStart.new(@table, :year).field_value({filter: {year: {start: '2011'}}}).should == '2011'
22
- Tableficate::Filter::InputStart.new(@table, :year).field_value({}).should == ''
22
+ @input_start_filter.field_value({filter: {year: {start: '2011'}}}).should == '2011'
23
+ @input_start_filter.field_value({}).should == ''
23
24
  end
24
25
  end
25
26
 
@@ -30,19 +31,20 @@ describe Tableficate::Filter::InputStop do
30
31
  template.lookup_context.stub!(:exists?).and_return(true)
31
32
  @table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
32
33
  @table.column(:year)
34
+ @input_stop_filter = Tableficate::Filter::InputStop.new(@table, :year)
33
35
  end
34
36
 
35
37
  it 'should append "[stop]" to field_name' do
36
- Tableficate::Filter::InputStop.new(@table, :year).field_name == "#{@table.as}[filter][year][stop]"
38
+ @input_stop_filter.field_name == "#{@table.as}[filter][year][stop]"
37
39
  end
38
40
 
39
41
  it 'should append "_stop" to the name' do
40
- Tableficate::Filter::InputStop.new(@table, :year).name == :year_stop
42
+ @input_stop_filter.name == :year_stop
41
43
  end
42
44
 
43
45
  it 'should provide a field value when given params or a blank value' do
44
- Tableficate::Filter::InputStop.new(@table, :year).field_value({filter: {year: {stop: '2011'}}}).should == '2011'
45
- Tableficate::Filter::InputStop.new(@table, :year).field_value({}).should == ''
46
+ @input_stop_filter.field_value({filter: {year: {stop: '2011'}}}).should == '2011'
47
+ @input_stop_filter.field_value({}).should == ''
46
48
  end
47
49
  end
48
50
 
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tableficate::Filter::SelectStart do
4
+ before(:each) do
5
+ template = mock('Template')
6
+ template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
7
+ template.lookup_context.stub!(:exists?).and_return(true)
8
+ @table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
9
+ @table.column(:year)
10
+ @select_start_filter = Tableficate::Filter::SelectStart.new(@table, :year, collection: 1900..2000)
11
+ end
12
+
13
+ it 'should append "[start]" to field_name' do
14
+ @select_start_filter.field_name == "#{@table.as}[filter][year][start]"
15
+ end
16
+
17
+ it 'should append "_start" to the name' do
18
+ @select_start_filter.name == :year_start
19
+ end
20
+
21
+ it 'should provide a field value when given params or a blank value' do
22
+ @select_start_filter.field_value({filter: {year: {start: '1911'}}}).should == '1911'
23
+ @select_start_filter.field_value({}).should == ''
24
+ end
25
+ end
26
+
27
+ describe Tableficate::Filter::SelectStop do
28
+ before(:each) do
29
+ template = mock('Template')
30
+ template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
31
+ template.lookup_context.stub!(:exists?).and_return(true)
32
+ @table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
33
+ @table.column(:year)
34
+ @select_stop_filter = Tableficate::Filter::SelectStop.new(@table, :year, collection: 1900..2000)
35
+ end
36
+
37
+ it 'should append "[stop]" to field_name' do
38
+ @select_stop_filter.field_name == "#{@table.as}[filter][year][stop]"
39
+ end
40
+
41
+ it 'should append "_stop" to the name' do
42
+ @select_stop_filter.name == :year_stop
43
+ end
44
+
45
+ it 'should provide a field value when given params or a blank value' do
46
+ @select_stop_filter.field_value({filter: {year: {stop: '1911'}}}).should == '1911'
47
+ @select_stop_filter.field_value({}).should == ''
48
+ end
49
+ end
50
+
51
+ describe Tableficate::Filter::SelectRange do
52
+ before(:each) do
53
+ template = mock('Template')
54
+ template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
55
+ @table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
56
+ @table.column(:year)
57
+ end
58
+
59
+ it 'should create a start and stop select' do
60
+ @table.template.lookup_context.stub!(:exists?).and_return(true)
61
+
62
+ filter = Tableficate::Filter::SelectRange.new(@table, :year, collection: 1900..2000)
63
+
64
+ filter.start.is_a?(Tableficate::Filter::SelectStart).should be true
65
+ filter.stop.is_a?(Tableficate::Filter::SelectStop).should be true
66
+ end
67
+
68
+ it 'should use the :start and :stop option hashes for the individual filters and default any values not passed to the range options provided' do
69
+ @table.template.lookup_context.stub!(:exists?).and_return(true)
70
+
71
+ filter = Tableficate::Filter::SelectRange.new(@table, :year, label: 'Nobel Prize Won In', collection: 1900..2000)
72
+ filter.start.label.should == 'Nobel Prize Won In'
73
+ filter.stop.label.should == 'Nobel Prize Won In'
74
+
75
+ filter = Tableficate::Filter::SelectRange.new(@table, :year, label: 'Nobel Prize Won In', start: {label: 'Nobel Prize Won Between'}, stop: {label: 'and'}, collection: 1900..2000)
76
+ filter.start.label.should == 'Nobel Prize Won Between'
77
+ filter.stop.label.should == 'and'
78
+ end
79
+ end
@@ -2,21 +2,43 @@ require 'spec_helper'
2
2
 
3
3
  describe Tableficate::Finder do
4
4
  it 'should filter based on single input passed in' do
5
- # exact input
5
+ # exact match
6
6
  npw = NobelPrizeWinner.tableficate({filter: {first_name: 'Albert'}})
7
7
  npw.size.should == 1
8
8
  npw.first.first_name.should == 'Albert'
9
9
  npw = NobelPrizeWinner.tableficate({filter: {first_name: 'Al'}})
10
10
  npw.size.should == 0
11
+
12
+ # contains match
13
+ class ContainsNobelPrizeWinner < Tableficate::Base
14
+ scope :nobel_prize_winner
15
+
16
+ filter(:first_name, match: 'contains')
17
+ end
18
+ npw = ContainsNobelPrizeWinner.tableficate({filter: {first_name: 'Al'}})
19
+ npw.size.should == 1
20
+ npw.first.first_name.should == 'Albert'
11
21
  end
12
22
 
13
23
  it 'should filter based on multiple inputs passed in' do
24
+ # exact match
14
25
  npw = NobelPrizeWinner.tableficate({filter: {first_name: ['Albert', 'Marie']}})
15
26
  npw.size.should == 2
16
27
  npw.first.first_name.should == 'Albert'
17
28
  npw.last.first_name.should == 'Marie'
18
29
  npw = NobelPrizeWinner.tableficate({filter: {first_name: ['Al', 'Mar']}})
19
30
  npw.size.should == 0
31
+
32
+ # contains match
33
+ class ContainsNobelPrizeWinner < Tableficate::Base
34
+ scope :nobel_prize_winner
35
+
36
+ filter(:first_name, match: 'contains')
37
+ end
38
+ npw = ContainsNobelPrizeWinner.tableficate({filter: {first_name: ['Al', 'Mar']}})
39
+ npw.size.should == 2
40
+ npw.first.first_name.should == 'Albert'
41
+ npw.last.first_name.should == 'Marie'
20
42
  end
21
43
 
22
44
  it 'should attach the table name to the fields from the primary table to avoid ambiguity' do
@@ -32,4 +54,29 @@ describe Tableficate::Finder do
32
54
  np = NobelPrize.tableficate({filter: {year: {start: 1900, stop: 1930}}})
33
55
  np.size.should == 4
34
56
  end
57
+
58
+ it 'should remove harmful characters from the param name' do
59
+ np = NobelPrize.tableficate({filter: {"ye'ar" => {start: 1900, stop: 1930}}})
60
+ np.size.should == 4
61
+ end
62
+
63
+ it 'should handle a date string being used against a datetime or timestamp column' do
64
+ np = NobelPrizeWinner.tableficate({filter: {created_at: '20110101'}})
65
+ np.size.should == 1
66
+ end
67
+
68
+ it 'should handle a date range being used against a datetime or timestamp column' do
69
+ np = NobelPrizeWinner.tableficate({filter: {created_at: {start: '20110101', stop: '20110105'}}})
70
+ np.size.should == 5
71
+ end
72
+
73
+ it 'should match an exact datetime and account for the timezone setting' do
74
+ np = NobelPrizeWinner.tableficate({filter: {created_at: '20110101050112'}})
75
+ np.size.should == 1
76
+ end
77
+
78
+ it 'should match an exact datetime range and account for the timezone setting' do
79
+ np = NobelPrizeWinner.tableficate({filter: {created_at: {start: '20110101050112', stop: '20110102050212'}}})
80
+ np.size.should == 2
81
+ end
35
82
  end
@@ -8,4 +8,18 @@ describe 'tableficate:theme' do
8
8
  subject.should generate('app/views/tableficate/foo/_table.html.erb')
9
9
  end
10
10
  end
11
+
12
+ with_args :foo, 'table_for' do
13
+ it 'should generate a single file in app/views/tableficate/foo/' do
14
+ subject.should generate('app/views/tableficate/foo')
15
+ subject.should generate('app/views/tableficate/foo/_table_for.html.erb')
16
+ end
17
+ end
18
+
19
+ with_args :foo, 'filters/form' do
20
+ it 'should generate a single file in app/views/tableficate/foo/filters' do
21
+ subject.should generate('app/views/tableficate/foo/filters')
22
+ subject.should generate('app/views/tableficate/foo/filters/_form.html.erb')
23
+ end
24
+ end
11
25
  end
@@ -5,7 +5,7 @@ describe Tableficate::Table do
5
5
  template = mock('Template')
6
6
  template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
7
7
  template.lookup_context.stub!(:exists?).and_return(true)
8
- @table = Tableficate::Table.new(template, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}})
8
+ @table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}})
9
9
  end
10
10
 
11
11
  it 'should have the current sort if provided' do
@@ -17,6 +17,28 @@ describe Tableficate::Table do
17
17
  @table.as.should == 'nobel_prize_winners'
18
18
  end
19
19
 
20
+ it 'should add a empty' do
21
+ @table.empty('There is no data.')
22
+ @table.empty.is_a?(Tableficate::Empty).should be true
23
+ @table.empty.value.should == 'There is no data.'
24
+
25
+ @table.empty do
26
+ 'No data.'
27
+ end
28
+ @table.empty.value.should == 'No data.'
29
+ end
30
+
31
+ it 'should add a caption' do
32
+ @table.caption('Nobel Prize Winners')
33
+ @table.caption.is_a?(Tableficate::Caption).should be true
34
+ @table.caption.value.should == 'Nobel Prize Winners'
35
+
36
+ @table.caption do
37
+ 'Nobel Winners'
38
+ end
39
+ @table.caption.value.should == 'Nobel Winners'
40
+ end
41
+
20
42
  it 'should add a Column' do
21
43
  @table.column(:first_name)
22
44
  @table.column(:last_name)
@@ -85,7 +107,96 @@ describe Tableficate::Table do
85
107
  @table.filter(:first_name, as: :search)
86
108
 
87
109
  @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
88
- @table.filters.first.options[:type].should == 'search'
110
+ @table.filters.first.attrs[:type].should == 'search'
111
+ end
112
+
113
+ it 'should default the type to "checkbox" for boolean fields' do
114
+ @table.filter(:shared)
115
+
116
+ @table.filters.first.is_a?(Tableficate::Filter::CheckBox).should be true
117
+ @table.filters.first.attrs[:type].should == 'checkbox'
118
+ end
119
+
120
+ it 'should default the type to "email" for string fields with "email" somewhere in the name' do
121
+ @table.filter(:email)
122
+
123
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
124
+ @table.filters.first.attrs[:type].should == 'email'
125
+ end
126
+
127
+ it 'should default the type to "url" for string fields with "url" somewhere in the name' do
128
+ @table.filter(:url)
129
+
130
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
131
+ @table.filters.first.attrs[:type].should == 'url'
132
+ end
133
+
134
+ it 'should default the type to "tel" for string fields with "phone" somewhere in the name' do
135
+ @table.filter(:home_phone)
136
+
137
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
138
+ @table.filters.first.attrs[:type].should == 'tel'
139
+ end
140
+
141
+ it 'should default the type to "number" for integer fields' do
142
+ @table.filter(:year)
143
+
144
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
145
+ @table.filters.first.attrs[:type].should == 'number'
146
+ end
147
+
148
+ it 'should default the type to "number" for float fields' do
149
+ @table.filter(:meaningless_float)
150
+
151
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
152
+ @table.filters.first.attrs[:type].should == 'number'
153
+ end
154
+
155
+ it 'should default the type to "number" for decimal fields' do
156
+ @table.filter(:meaningless_decimal)
157
+
158
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
159
+ @table.filters.first.attrs[:type].should == 'number'
160
+ end
161
+
162
+ it 'should default the type to "date" for date fields' do
163
+ @table.filter(:birthdate)
164
+
165
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
166
+ @table.filters.first.attrs[:type].should == 'date'
167
+ end
168
+
169
+ it 'should default the type to "time" for time fields' do
170
+ @table.filter(:meaningless_time)
171
+
172
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
173
+ @table.filters.first.attrs[:type].should == 'time'
174
+ end
175
+
176
+ it 'should default the type to "datetime" for datetime fields' do
177
+ @table.filter(:created_at)
178
+
179
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
180
+ @table.filters.first.attrs[:type].should == 'datetime'
181
+ end
182
+
183
+ it 'should default the type to "datetime" for timestamp fields' do
184
+ @table.filter(:updated_at)
185
+
186
+ @table.filters.first.is_a?(Tableficate::Filter::Input).should be true
187
+ @table.filters.first.attrs[:type].should == 'datetime'
188
+ end
189
+
190
+ it 'should default the type based on the actual field, not the label' do
191
+ template = mock('Template')
192
+ template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
193
+ template.lookup_context.stub!(:exists?).and_return(true)
194
+ table = Tableficate::Table.new(template, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {field_map: {foo: 'year'}})
195
+
196
+ table.filter(:foo)
197
+
198
+ table.filters.first.is_a?(Tableficate::Filter::Input).should be true
199
+ table.filters.first.attrs[:type].should == 'number'
89
200
  end
90
201
 
91
202
  it 'should add a InputRange filter' do
@@ -105,7 +216,7 @@ describe Tableficate::Table do
105
216
  @table.filter_range(:first_name, as: :search)
106
217
 
107
218
  @table.filters.first.is_a?(Tableficate::Filter::InputRange).should be true
108
- @table.filters.first.options[:type].should == 'search'
219
+ @table.filters.first.attrs[:type].should == 'search'
109
220
  end
110
221
 
111
222
  it 'should add a Select filter' do
@@ -2,6 +2,6 @@ class FiltersController < ApplicationController
2
2
  before_filter :get_npw
3
3
 
4
4
  def get_npw
5
- @npw = NobelPrizeWinner.select('nobel_prize_winners.*, nobel_prizes.category, nobel_prizes.year').joins(:nobel_prizes).tableficate(params[:nobel_prize_winners])
5
+ @npw = NobelPrizeWinner.select('nobel_prize_winners.*, nobel_prizes.*').joins(:nobel_prizes).tableficate(params[:nobel_prize_winners])
6
6
  end
7
7
  end