File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
lib/ajax-datatables-rails
spec/ajax-datatables-rails Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ def build_conditions_for(query)
92
92
93
93
def search_condition ( column , value )
94
94
model , column = column . split ( '.' )
95
- model = model . singularize . titleize . constantize
95
+ model = model . singularize . titleize . gsub ( / / , '' ) . constantize
96
96
model . arel_table [ column . to_sym ] . matches ( "%#{ value } %" )
97
97
end
98
98
@@ -125,4 +125,4 @@ def sort_direction
125
125
options . include? ( params [ :sSortDir_0 ] ) ? params [ :sSortDir_0 ] . upcase : 'ASC'
126
126
end
127
127
end
128
- end
128
+ end
Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ def self.arel_table
13
13
end
14
14
end
15
15
16
+ class UserData
17
+ def self . arel_table
18
+ { :bar => Column . new }
19
+ end
20
+ end
21
+
16
22
params = {
17
23
:sEcho => '0' , :sSortDir_0 => 'asc' ,
18
24
:iSortCol_0 => '1' , :iDisplayStart => '11'
@@ -137,6 +143,19 @@ def self.arel_table
137
143
datatable . send ( :filter_records , records )
138
144
end
139
145
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
140
159
end
141
160
142
161
describe 'hook methods' do
You can’t perform that action at this time.
0 commit comments