Skip to content

Commit 1831893

Browse files
committed
Make custom_field? method public
1 parent 3205053 commit 1831893

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/ajax-datatables-rails/datatable/column.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def initialize(datatable, index, options)
2727
@datatable = datatable
2828
@index = index
2929
@options = options
30-
@view_column = datatable.view_columns[options['data'].to_sym]
30+
@view_column = datatable.view_columns[options[:data].to_sym]
3131
end
3232

3333
def data
@@ -50,6 +50,10 @@ def field
5050
source.split('.').last.to_sym
5151
end
5252

53+
def custom_field?
54+
!source.include?('.')
55+
end
56+
5357
# Add formater option to allow modification of the value
5458
# before passing it to the database
5559
def formater
@@ -62,10 +66,6 @@ def formated_value
6266

6367
private
6468

65-
def custom_field?
66-
!source.include?('.')
67-
end
68-
6969
def config
7070
@config ||= AjaxDatatablesRails.config
7171
end

spec/ajax-datatables-rails/datatable/column_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
expect(column.data).to eq('username')
3030
end
3131

32-
describe 'data' do
32+
describe '#data' do
3333
it 'should return the data from params' do
3434
expect(column.data).to eq 'username'
3535
end
3636
end
3737

38-
describe 'source' do
38+
describe '#source' do
3939
it 'should return the data source from view_column' do
4040
expect(column.source).to eq 'User.username'
4141
end
4242
end
4343

44-
describe 'table' do
44+
describe '#table' do
4545
context 'with ActiveRecord ORM' do
4646
it 'should return the corresponding AR table' do
4747
expect(column.table).to eq User.arel_table
@@ -55,18 +55,24 @@
5555
end
5656
end
5757

58-
describe 'model' do
58+
describe '#model' do
5959
it 'should return the corresponding AR model' do
6060
expect(column.model).to eq User
6161
end
6262
end
6363

64-
describe 'field' do
64+
describe '#field' do
6565
it 'should return the corresponding field in DB' do
6666
expect(column.field).to eq :username
6767
end
6868
end
6969

70+
describe '#custom_field?' do
71+
it 'should return false if field is bound to an AR field' do
72+
expect(column.custom_field?).to be false
73+
end
74+
end
75+
7076
describe '#search' do
7177
it 'child class' do
7278
expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch)

0 commit comments

Comments
 (0)