8000 fix the problem with multi-word model · FiveBox/ajax-datatables-rails@e502fda · GitHub
[go: up one dir, main page]

Skip to content

Commit e502fda

Browse files
author
Makoto NAKAYA
committed
fix the problem with multi-word model
1 parent 5e787e1 commit e502fda

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/ajax-datatables-rails/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def build_conditions_for(query)
9292

9393
def search_condition(column, value)
9494
model, column = column.split('.')
95-
model = model.singularize.titleize.constantize
95+
model = model.singularize.titleize.gsub( / /, '' ).constantize
9696
model.arel_table[column.to_sym].matches("%#{value}%")
9797
end
9898

@@ -125,4 +125,4 @@ def sort_direction
125125
options.include?(params[:sSortDir_0]) ? params[:sSortDir_0].upcase : 'ASC'
126126
end
127127
end
128-
end
128+
end

spec/ajax-datatables-rails/ajax_datatables_rails_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def self.arel_table
1313
end
1414
end
1515

16+
class UserData
17+
def self.arel_table
18+
{ :bar => Column.new }
19+
end
20+
end
21+
1622
params = {
1723
:sEcho => '0', :sSortDir_0 => 'asc',
1824
:iSortCol_0 => '1', :iDisplayStart => '11'
@@ -137,6 +143,19 @@ def self.arel_table
137143
datatable.send(:filter_records, records)
138144
end
139145
end
146+
147+
describe '#filter_records with multi word model' do
148+
let(:records) { double('UserData', :where => []) }
149+
let(:search_view) { double('view', :params => { :sSearch => 'bar' }) }
150+
151+
it 'applies search like functionality on a collection' do
152+
datatable = AjaxDatatablesRails::Base.new(search_view)
153+
datatable.stub(:searchable_columns) { ['user_datas.bar'] }
154+
155+
records.should_receive(:where)
156+
datatable.send(:filter_records, records)
157+
end
158+
end
140159
end
141160

142161
describe 'hook methods' do

0 commit comments

Comments
 (0)
0