|
56 | 56 |
|
57 | 57 | context 'with search query' do
|
58 | 58 | before(:each) do
|
59 |
| - datatable.params[:search] = { value: "John", regex: "false" } |
| 59 | + datatable.params[:search] = { value: "john", regex: "false" } |
60 | 60 | end
|
61 | 61 |
|
62 | 62 | it 'returns a filtering query' do
|
|
97 | 97 | end
|
98 | 98 | end
|
99 | 99 |
|
| 100 | + if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] |
| 101 | + context 'when db_adapter is oracle' do |
| 102 | + it 'can call #to_sql on returned object' do |
| 103 | + result = datatable.send(:build_conditions_for_selected_columns) |
| 104 | + expect(result).to respond_to(:to_sql) |
| 105 | + expect(result.to_sql).to eq( |
| 106 | + "CAST(\"USERS\".\"USERNAME\" AS VARCHAR2(4000)) LIKE '%doe%' AND CAST(\"USERS\".\"EMAIL\" AS VARCHAR2(4000)) LIKE '%example%'" |
| 107 | + ) |
| 108 | + end |
| 109 | + end |
| 110 | + end |
| 111 | + |
100 | 112 | if AjaxDatatablesRails.config.db_adapter.in? %i[mysql2 sqlite3]
|
101 | 113 | context 'when db_adapter is mysql2' do
|
102 | 114 | it 'can call #to_sql on returned object' do
|
|
143 | 155 | expect(column.send(:typecast)).to eq('VARCHAR')
|
144 | 156 | end
|
145 | 157 |
|
146 |
| - it 'returns VARCHAR if :db_adapter is :postgre' do |
| 158 | + it 'returns VARCHAR if :db_adapter is :postgresql' do |
147 | 159 | allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgresql }
|
148 | 160 | expect(column.send(:typecast)).to eq('VARCHAR')
|
149 | 161 | end
|
150 | 162 |
|
| 163 | + it 'returns VARCHAR if :db_adapter is :oracle' do |
| 164 | + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracle } |
| 165 | + expect(column.send(:typecast)).to eq('VARCHAR2(4000)') |
| 166 | + end |
| 167 | + |
| 168 | + it 'returns VARCHAR if :db_adapter is :oracleenhanced' do |
| 169 | + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracleenhanced } |
| 170 | + expect(column.send(:typecast)).to eq('VARCHAR2(4000)') |
| 171 | + end |
| 172 | + |
151 | 173 | it 'returns CHAR if :db_adapter is :mysql2' do
|
152 | 174 | allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql2 }
|
153 | 175 | expect(column.send(:typecast)).to eq('CHAR')
|
|
260 | 282 | end
|
261 | 283 |
|
262 | 284 | it 'should filter records matching' do
|
263 |
| - datatable.params[:columns]['2'][:search][:value] = 'jo' |
| 285 | + datatable.params[:columns]['2'][:search][:value] = 'Jo' |
264 | 286 | expect(datatable.data.size).to eq 1
|
265 | 287 | item = datatable.data.first
|
266 | 288 | expect(item[:first_name]).to eq 'John'
|
|
269 | 291 |
|
270 | 292 | describe 'it can filter records with condition :end_with' do
|
271 | 293 | before(:each) do
|
272 |
| - create(:user, last_name: 'John') |
273 |
| - create(:user, last_name: 'Mary') |
| 294 | + create(:user, last_name: 'JOHN') |
| 295 | + create(:user, last_name: 'MARY') |
274 | 296 | end
|
275 | 297 |
|
276 | 298 | it 'should filter records matching' do
|
277 | 299 | datatable.params[:columns]['3'][:search][:value] = 'ry'
|
278 | 300 | expect(datatable.data.size).to eq 1
|
279 | 301 | item = datatable.data.first
|
280 |
| - expect(item[:last_name]).to eq 'Mary' |
| 302 | + expect(item[:last_name]).to eq 'MARY' |
281 | 303 | end
|
282 | 304 | end
|
283 | 305 |
|
|
0 commit comments