tableficate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.markdown +120 -0
- data/Rakefile +1 -0
- data/app/views/tableficate/_column_header.html.erb +8 -0
- data/app/views/tableficate/_data.html.erb +1 -0
- data/app/views/tableficate/_input_filter.html.erb +4 -0
- data/app/views/tableficate/_input_range_filter.html.erb +6 -0
- data/app/views/tableficate/_row.html.erb +5 -0
- data/app/views/tableficate/_select_filter.html.erb +4 -0
- data/app/views/tableficate/_table.html.erb +36 -0
- data/changelog.markdown +2 -0
- data/lib/generators/tableficate/table/table_generator.rb +17 -0
- data/lib/generators/tableficate/table/templates/table.rb +5 -0
- data/lib/generators/tableficate/theme/theme_generator.rb +15 -0
- data/lib/tableficate/action_column.rb +15 -0
- data/lib/tableficate/active_record_extension.rb +20 -0
- data/lib/tableficate/base.rb +37 -0
- data/lib/tableficate/column.rb +33 -0
- data/lib/tableficate/engine.rb +4 -0
- data/lib/tableficate/exceptions.rb +3 -0
- data/lib/tableficate/filters/filter.rb +19 -0
- data/lib/tableficate/filters/input_filters.rb +64 -0
- data/lib/tableficate/filters/select_filter.rb +11 -0
- data/lib/tableficate/finder.rb +79 -0
- data/lib/tableficate/helper.rb +37 -0
- data/lib/tableficate/table.rb +57 -0
- data/lib/tableficate/utils.rb +7 -0
- data/lib/tableficate/version.rb +3 -0
- data/lib/tableficate.rb +17 -0
- data/spec/action_column_spec.rb +21 -0
- data/spec/active_record_extension_spec.rb +9 -0
- data/spec/base_spec.rb +103 -0
- data/spec/column_spec.rb +54 -0
- data/spec/filter_spec.rb +30 -0
- data/spec/finder_spec.rb +35 -0
- data/spec/input_filter_spec.rb +90 -0
- data/spec/select_filter_spec.rb +10 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/table_spec.rb +94 -0
- data/spec/test_app/.gitignore +4 -0
- data/spec/test_app/Gemfile +21 -0
- data/spec/test_app/README +261 -0
- data/spec/test_app/Rakefile +7 -0
- data/spec/test_app/app/assets/images/rails.png +0 -0
- data/spec/test_app/app/assets/javascripts/application.js +9 -0
- data/spec/test_app/app/assets/stylesheets/application.css +7 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/mailers/.gitkeep +0 -0
- data/spec/test_app/app/models/.gitkeep +0 -0
- data/spec/test_app/app/models/nobel_prize.rb +3 -0
- data/spec/test_app/app/models/nobel_prize_winner.rb +3 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/config/application.rb +48 -0
- data/spec/test_app/config/boot.rb +6 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +30 -0
- data/spec/test_app/config/environments/production.rb +60 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/inflections.rb +10 -0
- data/spec/test_app/config/initializers/mime_types.rb +5 -0
- data/spec/test_app/config/initializers/secret_token.rb +7 -0
- data/spec/test_app/config/initializers/session_store.rb +8 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +5 -0
- data/spec/test_app/config/routes.rb +58 -0
- data/spec/test_app/config.ru +4 -0
- data/spec/test_app/db/migrate/20111007154222_create_nobel_prize_winners.rb +30 -0
- data/spec/test_app/db/migrate/20111010191626_create_nobel_prizes.rb +34 -0
- data/spec/test_app/db/schema.rb +27 -0
- data/spec/test_app/db/seeds.rb +7 -0
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/doc/README_FOR_APP +2 -0
- data/spec/test_app/lib/assets/.gitkeep +0 -0
- data/spec/test_app/lib/tasks/.gitkeep +0 -0
- data/spec/test_app/log/.gitkeep +0 -0
- data/spec/test_app/public/404.html +26 -0
- data/spec/test_app/public/422.html +26 -0
- data/spec/test_app/public/500.html +26 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/test_app/public/index.html +241 -0
- data/spec/test_app/public/robots.txt +5 -0
- data/spec/test_app/script/rails +6 -0
- data/spec/test_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/test_app/vendor/plugins/.gitkeep +0 -0
- data/spec/utils_spec.rb +11 -0
- data/tableficate.gemspec +26 -0
- metadata +245 -0
data/lib/tableficate.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'tableficate/engine'
|
2
|
+
require 'tableficate/exceptions'
|
3
|
+
require 'tableficate/utils'
|
4
|
+
require 'tableficate/finder'
|
5
|
+
require 'tableficate/column'
|
6
|
+
require 'tableficate/action_column'
|
7
|
+
require 'tableficate/filters/filter'
|
8
|
+
require 'tableficate/filters/input_filters'
|
9
|
+
require 'tableficate/filters/select_filter'
|
10
|
+
require 'tableficate/table'
|
11
|
+
require 'tableficate/helper'
|
12
|
+
require 'tableficate/base'
|
13
|
+
require 'tableficate/active_record_extension'
|
14
|
+
require 'tableficate/version'
|
15
|
+
|
16
|
+
ActionView::Base.send(:include, Tableficate::Helper)
|
17
|
+
ActiveRecord::Base.send(:include, Tableficate::ActiveRecordExtension)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::ActionColumn do
|
4
|
+
before(:all) do
|
5
|
+
@action_column = Tableficate::ActionColumn.new(nil, nil) do
|
6
|
+
Actions!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should always have sorting off ' do
|
11
|
+
@action_column.show_sort?.should be false
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should always indicate that it is not sorted' do
|
15
|
+
@action_column.is_sorted?.should be false
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have a blank name' do
|
19
|
+
@action_column.name.should == ''
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Tableficate::ActiveRecordExtention' do
|
4
|
+
it 'should add and retreive data from the scope' do
|
5
|
+
scope = NobelPrizeWinner.tableficate_ext
|
6
|
+
scope.tableficate_add_data(:name, 'Aaron')
|
7
|
+
scope.tableficate_get_data.should == {name: 'Aaron'}
|
8
|
+
end
|
9
|
+
end
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::Base do
|
4
|
+
it 'should set the scope' do
|
5
|
+
class SymbolScope < Tableficate::Base
|
6
|
+
scope(:nobel_prize_winner)
|
7
|
+
end
|
8
|
+
SymbolScope.send(:instance_variable_get, '@scope').should == NobelPrizeWinner
|
9
|
+
|
10
|
+
class BlockScope < Tableficate::Base
|
11
|
+
scope do
|
12
|
+
NobelPrizeWinner.joins(:nobel_prizes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
BlockScope.send(:instance_variable_get, '@scope').should == NobelPrizeWinner.joins(:nobel_prizes)
|
16
|
+
|
17
|
+
class NoScope < Tableficate::Base; end
|
18
|
+
lambda {NoScope.tableficate({})}.should raise_error(Tableficate::MissingScope)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should allow for a default order' do
|
22
|
+
class DefaultOrder < Tableficate::Base
|
23
|
+
scope(:nobel_prize_winner)
|
24
|
+
|
25
|
+
default_sort(:first_name)
|
26
|
+
end
|
27
|
+
npw = DefaultOrder.tableficate({})
|
28
|
+
npw.order_values.should == ["#{npw.table_name}.first_name ASC"]
|
29
|
+
npw.reverse_order_value.should == nil
|
30
|
+
|
31
|
+
class DefaultOrderDesc < Tableficate::Base
|
32
|
+
scope(:nobel_prize_winner)
|
33
|
+
|
34
|
+
default_sort(:first_name, 'desc')
|
35
|
+
end
|
36
|
+
npw = DefaultOrderDesc.tableficate({})
|
37
|
+
npw.order_values.should == ["#{npw.table_name}.first_name ASC"]
|
38
|
+
npw.reverse_order_value.should be true
|
39
|
+
|
40
|
+
class DefaultOrderWithOverride < Tableficate::Base
|
41
|
+
scope(:nobel_prize_winner)
|
42
|
+
|
43
|
+
default_sort(:full_name)
|
44
|
+
|
45
|
+
column(:full_name, sort: 'first_name ASC, last_name ASC')
|
46
|
+
end
|
47
|
+
npw = DefaultOrderWithOverride.tableficate({})
|
48
|
+
npw.order_values.should == ["first_name ASC, last_name ASC"]
|
49
|
+
npw.reverse_order_value.should == nil
|
50
|
+
|
51
|
+
class DefaultOrderWithOverrideDesc < Tableficate::Base
|
52
|
+
scope(:nobel_prize_winner)
|
53
|
+
|
54
|
+
default_sort(:full_name, 'desc')
|
55
|
+
|
56
|
+
column(:full_name, sort: 'first_name ASC, last_name ASC')
|
57
|
+
end
|
58
|
+
npw = DefaultOrderWithOverrideDesc.tableficate({})
|
59
|
+
npw.order_values.should == ["first_name ASC, last_name ASC"]
|
60
|
+
npw.reverse_order_value.should be true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should filter using match: "contains"' do
|
64
|
+
class FilterByContainsInput < Tableficate::Base
|
65
|
+
scope(:nobel_prize_winner)
|
66
|
+
|
67
|
+
filter(:first_name, match: 'contains')
|
68
|
+
end
|
69
|
+
npw = FilterByContainsInput.tableficate({filter: {first_name: 'Al'}})
|
70
|
+
npw.size.should == 1
|
71
|
+
npw.first.first_name.should == 'Albert'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should filter multiple inputs using match: "contains"' do
|
75
|
+
class FilterByContainsInput < Tableficate::Base
|
76
|
+
scope(:nobel_prize_winner)
|
77
|
+
|
78
|
+
filter(:first_name, match: 'contains')
|
79
|
+
end
|
80
|
+
npw = FilterByContainsInput.tableficate({filter: {first_name: ['Al', 'Mar']}})
|
81
|
+
npw.size.should == 2
|
82
|
+
npw.first.first_name.should == 'Albert'
|
83
|
+
npw.last.first_name.should == 'Marie'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should allow custom block filters' do
|
87
|
+
class BlockFilter < Tableficate::Base
|
88
|
+
scope(:nobel_prize_winner)
|
89
|
+
|
90
|
+
filter(:full_name) do |value, scope|
|
91
|
+
first_name, last_name = value.split(/\s+/)
|
92
|
+
|
93
|
+
if last_name.nil?
|
94
|
+
scope.where(['first_name LIKE ? OR last_name LIKE ?', first_name, first_name])
|
95
|
+
else
|
96
|
+
scope.where(['first_name LIKE ? AND last_name LIKE ?', first_name, last_name])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
npw = BlockFilter.tableficate({filter: {full_name: 'Bohr'}})
|
101
|
+
npw.first.first_name.should == 'Niels'
|
102
|
+
end
|
103
|
+
end
|
data/spec/column_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::Column do
|
4
|
+
it 'should show the header provided or default to the column name' do
|
5
|
+
column = Tableficate::Column.new(nil, :first_name)
|
6
|
+
column.header.should == 'First Name'
|
7
|
+
|
8
|
+
column = Tableficate::Column.new(nil, :first_name, header: 'Given Name')
|
9
|
+
column.header.should == 'Given Name'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should show the value from the database field if no alternative is provided' do
|
13
|
+
row = NobelPrizeWinner.find_by_first_name('Norman')
|
14
|
+
column = Tableficate::Column.new(nil, :first_name)
|
15
|
+
|
16
|
+
column.value(row).should == 'Norman'
|
17
|
+
end
|
18
|
+
it 'should return the value provided from the block' do
|
19
|
+
row = NobelPrizeWinner.find_by_first_name_and_last_name('Norman', 'Borlaug')
|
20
|
+
column = Tableficate::Column.new(nil, :full_name) do |row|
|
21
|
+
[row.first_name, row.last_name].join(' ')
|
22
|
+
end
|
23
|
+
|
24
|
+
column.value(row).should == 'Norman Borlaug'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow sorting to be turned on and off' do
|
28
|
+
column = Tableficate::Column.new(nil, :first_name, show_sort: false)
|
29
|
+
column.show_sort?.should be false
|
30
|
+
|
31
|
+
column = Tableficate::Column.new(nil, :first_name, show_sort: true)
|
32
|
+
column.show_sort?.should be true
|
33
|
+
|
34
|
+
# defaults to false
|
35
|
+
column = Tableficate::Column.new(nil, :first_name)
|
36
|
+
column.show_sort?.should be false
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should indicate whether a column is sorted or not' do
|
40
|
+
table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}})
|
41
|
+
|
42
|
+
column = Tableficate::Column.new(table, :first_name)
|
43
|
+
column.is_sorted?('asc').should be true
|
44
|
+
|
45
|
+
column = Tableficate::Column.new(table, :first_name)
|
46
|
+
column.is_sorted?('desc').should be false
|
47
|
+
|
48
|
+
column = Tableficate::Column.new(table, :first_name)
|
49
|
+
column.is_sorted?.should be true
|
50
|
+
|
51
|
+
column = Tableficate::Column.new(table, :last_name)
|
52
|
+
column.is_sorted?.should be false
|
53
|
+
end
|
54
|
+
end
|
data/spec/filter_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::Filter do
|
4
|
+
before(:all) do
|
5
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {})
|
6
|
+
@table.column(:first_name, header: 'Given Name')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should find the correct template type' do
|
10
|
+
Tableficate::Filter.new(@table, :first_name).template.should == 'filter'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should use the provided label or default to the column header' do
|
14
|
+
Tableficate::Filter.new(@table, :first_name).label.should == 'Given Name'
|
15
|
+
Tableficate::Filter.new(@table, :first_name, label: 'First').label.should == 'First'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should provide a field name' do
|
19
|
+
Tableficate::Filter.new(@table, :first_name).field_name.should == "#{@table.as}[filter][first_name]"
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should provide a field value when given params or a blank value' do
|
23
|
+
Tableficate::Filter.new(@table, :first_name).field_value({filter: {first_name: 'Aaron'}}).should == 'Aaron'
|
24
|
+
Tableficate::Filter.new(@table, :first_name).field_value({}).should == ''
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow for filters that do not match a particular field' do
|
28
|
+
Tableficate::Filter.new(@table, :custom_field).label.should == 'Custom Field'
|
29
|
+
end
|
30
|
+
end
|
data/spec/finder_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::Finder do
|
4
|
+
it 'should filter based on single input passed in' do
|
5
|
+
# exact input
|
6
|
+
npw = NobelPrizeWinner.tableficate({filter: {first_name: 'Albert'}})
|
7
|
+
npw.size.should == 1
|
8
|
+
npw.first.first_name.should == 'Albert'
|
9
|
+
npw = NobelPrizeWinner.tableficate({filter: {first_name: 'Al'}})
|
10
|
+
npw.size.should == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should filter based on multiple inputs passed in' do
|
14
|
+
npw = NobelPrizeWinner.tableficate({filter: {first_name: ['Albert', 'Marie']}})
|
15
|
+
npw.size.should == 2
|
16
|
+
npw.first.first_name.should == 'Albert'
|
17
|
+
npw.last.first_name.should == 'Marie'
|
18
|
+
npw = NobelPrizeWinner.tableficate({filter: {first_name: ['Al', 'Mar']}})
|
19
|
+
npw.size.should == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should attach the table name to the fields from the primary table to avoid ambiguity' do
|
23
|
+
npw = NobelPrizeWinner.joins(:nobel_prizes).tableficate({sort: 'first_name'})
|
24
|
+
npw.order_values.should == ["#{npw.table_name}.first_name ASC"]
|
25
|
+
|
26
|
+
# secondary table fields are left vague for maximum flexibility
|
27
|
+
npw = NobelPrizeWinner.joins(:nobel_prizes).tableficate({sort: 'year'})
|
28
|
+
npw.order_values.should == ["year ASC"]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should allow ranged input filters' do
|
32
|
+
np = NobelPrize.tableficate({filter: {year: {start: 1900, stop: 1930}}})
|
33
|
+
np.size.should == 4
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::InputFilter do
|
4
|
+
before(:all) do
|
5
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
|
6
|
+
@table.column(:first_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should find the correct template type' do
|
10
|
+
Tableficate::InputFilter.new(@table, :first_name).template.should == 'input_filter'
|
11
|
+
|
12
|
+
Tableficate::InputFilter.new(@table, :first_name, field_options: {type: 'email'}).template.should == 'input_filter'
|
13
|
+
|
14
|
+
file = File.open('app/views/tableficate/_email_input_filter.html.erb', 'w')
|
15
|
+
Tableficate::InputFilter.new(@table, :first_name, field_options: {type: 'email'}).template.should == 'email_input_filter'
|
16
|
+
File.delete(file.path)
|
17
|
+
|
18
|
+
file = File.open('app/views/tableficate/_email_input_filter.html.haml', 'w')
|
19
|
+
Tableficate::InputFilter.new(@table, :first_name, field_options: {type: 'email'}).template.should == 'email_input_filter'
|
20
|
+
File.delete(file.path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Tableficate::InputStartFilter do
|
25
|
+
before(:all) do
|
26
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
|
27
|
+
@table.column(:year)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should append "[start]" to field_name' do
|
31
|
+
Tableficate::InputStartFilter.new(@table, :year).field_name == "#{@table.as}[filter][year][start]"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should append "_start" to the name' do
|
35
|
+
Tableficate::InputStartFilter.new(@table, :year).name == :year_start
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should provide a field value when given params or a blank value' do
|
39
|
+
Tableficate::InputStartFilter.new(@table, :year).field_value({filter: {year: {start: '2011'}}}).should == '2011'
|
40
|
+
Tableficate::InputStartFilter.new(@table, :year).field_value({}).should == ''
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Tableficate::InputStopFilter do
|
45
|
+
before(:all) do
|
46
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
|
47
|
+
@table.column(:year)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should append "[stop]" to field_name' do
|
51
|
+
Tableficate::InputStopFilter.new(@table, :year).field_name == "#{@table.as}[filter][year][stop]"
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should append "_stop" to the name' do
|
55
|
+
Tableficate::InputStopFilter.new(@table, :year).name == :year_stop
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should provide a field value when given params or a blank value' do
|
59
|
+
Tableficate::InputStopFilter.new(@table, :year).field_value({filter: {year: {stop: '2011'}}}).should == '2011'
|
60
|
+
Tableficate::InputStopFilter.new(@table, :year).field_value({}).should == ''
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe Tableficate::InputRangeFilter do
|
65
|
+
before(:all) do
|
66
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
|
67
|
+
@table.column(:year)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should find the correct template type' do
|
71
|
+
Tableficate::InputRangeFilter.new(@table, :year).template.should == 'input_range_filter'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should create a start and stop input' do
|
75
|
+
filter = Tableficate::InputRangeFilter.new(@table, :year)
|
76
|
+
|
77
|
+
filter.start.is_a?(Tableficate::InputStartFilter).should be true
|
78
|
+
filter.stop.is_a?(Tableficate::InputStopFilter).should be true
|
79
|
+
end
|
80
|
+
|
81
|
+
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
|
82
|
+
filter = Tableficate::InputRangeFilter.new(@table, :year, label: 'Nobel Prize Won In')
|
83
|
+
filter.start.label.should == 'Nobel Prize Won In'
|
84
|
+
filter.stop.label.should == 'Nobel Prize Won In'
|
85
|
+
|
86
|
+
filter = Tableficate::InputRangeFilter.new(@table, :birth_date, label: 'Nobel Prize Won In', start: {label: 'Nobel Prize Won Between'}, stop: {label: 'and'})
|
87
|
+
filter.start.label.should == 'Nobel Prize Won Between'
|
88
|
+
filter.stop.label.should == 'and'
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::SelectFilter do
|
4
|
+
it 'should find the correct template type' do
|
5
|
+
table = Tableficate::Table.new(nil, NobelPrizeWinner.joins(:nobel_prizes).limit(1), {}, {})
|
6
|
+
table.column(:year)
|
7
|
+
|
8
|
+
Tableficate::SelectFilter.new(table, :year, []).template.should == 'select_filter'
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/table_spec.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tableficate::Table do
|
4
|
+
before(:each) do
|
5
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}})
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should have the current sort if provided' do
|
9
|
+
@table.current_sort.should == {column: :first_name, dir: 'asc'}
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should use the :as option or default to the table_name of the scope' do
|
13
|
+
Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {as: 'npw'}, {}).as.should == 'npw'
|
14
|
+
@table.as.should == 'nobel_prize_winners'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should add a Column' do
|
18
|
+
@table.column(:first_name)
|
19
|
+
@table.column(:last_name)
|
20
|
+
|
21
|
+
@table.columns.first.name.should == :first_name
|
22
|
+
@table.columns.first.is_a?(Tableficate::Column).should be true
|
23
|
+
@table.columns.last.name.should == :last_name
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should indicate that it is sortble if any column is sortable' do
|
27
|
+
@table.column(:first_name)
|
28
|
+
@table.show_sort?.should be false
|
29
|
+
|
30
|
+
@table.column(:last_name, show_sort: true)
|
31
|
+
@table.show_sort?.should be true
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should overwrite the column sorting unless it is provided' do
|
35
|
+
@table.column(:first_name)
|
36
|
+
@table.column(:last_name, show_sort: true)
|
37
|
+
|
38
|
+
@table.columns.first.show_sort?.should be false
|
39
|
+
@table.columns.last.show_sort?.should be true
|
40
|
+
|
41
|
+
table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {show_sorts: true}, {})
|
42
|
+
table.column(:first_name)
|
43
|
+
table.column(:last_name, show_sort: false)
|
44
|
+
|
45
|
+
table.columns.first.show_sort?.should be true
|
46
|
+
table.columns.last.show_sort?.should be false
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should add an ActionColumn' do
|
50
|
+
@table.actions do
|
51
|
+
Action!
|
52
|
+
end
|
53
|
+
|
54
|
+
@table.columns.first.is_a?(Tableficate::ActionColumn).should be true
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should determine whether any columns are sortable' do
|
58
|
+
@table.column(:first_name, show_sort: true)
|
59
|
+
|
60
|
+
@table.show_sort?.should be true
|
61
|
+
|
62
|
+
table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {show_sorts: true}, {})
|
63
|
+
table.column(:first_name, show_sort: false)
|
64
|
+
|
65
|
+
table.show_sort?.should be false
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should add an InputFilter' do
|
69
|
+
@table.input_filter(:first_name, label: 'First')
|
70
|
+
@table.input_filter(:last_name, label: 'Last')
|
71
|
+
|
72
|
+
@table.filters.first.name.should == :first_name
|
73
|
+
@table.filters.first.is_a?(Tableficate::InputFilter).should be true
|
74
|
+
@table.filters.last.name.should == :last_name
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should add an InputRangeFilter' do
|
78
|
+
@table.input_range_filter(:first_name, label: 'First')
|
79
|
+
@table.input_range_filter(:last_name, label: 'Last')
|
80
|
+
|
81
|
+
@table.filters.first.name.should == :first_name
|
82
|
+
@table.filters.first.is_a?(Tableficate::InputRangeFilter).should be true
|
83
|
+
@table.filters.last.name.should == :last_name
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should add an SelectFilter' do
|
87
|
+
@table.select_filter(:first_name, {}, label: 'First')
|
88
|
+
@table.select_filter(:last_name, {}, label: 'Last')
|
89
|
+
|
90
|
+
@table.filters.first.name.should == :first_name
|
91
|
+
@table.filters.first.is_a?(Tableficate::SelectFilter).should be true
|
92
|
+
@table.filters.last.name.should == :last_name
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.1.0'
|
4
|
+
|
5
|
+
gem 'sqlite3'
|
6
|
+
|
7
|
+
group :assets do
|
8
|
+
gem 'sass-rails', '~> 3.1.0'
|
9
|
+
gem 'coffee-rails', '~> 3.1.0'
|
10
|
+
gem 'uglifier'
|
11
|
+
end
|
12
|
+
|
13
|
+
gem 'jquery-rails'
|
14
|
+
|
15
|
+
gem 'tableficate', path: '../../'
|
16
|
+
|
17
|
+
group :test do
|
18
|
+
gem 'turn', :require => false
|
19
|
+
gem 'rspec'
|
20
|
+
gem 'capybara'
|
21
|
+
end
|