Skip to content

Commit c8619f4

Browse files
committed
Improve DB detection in spec
1 parent 75e0211 commit c8619f4

5 files changed

+28
-9
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
after { parent.nulls_last = false }
2222

2323
it 'sql query' do
24-
skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced'
24+
skip('unsupported database adapter') if RunningSpec.oracle?
2525

2626
expect(simple_order.query('email')).to eq(
2727
"email DESC #{nulls_last_sql(parent)}"

spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
expect(result).to be_a(Arel::Nodes::And)
169169
end
170170

171-
if ENV['DB_ADAPTER'] == 'postgresql'
171+
if RunningSpec.postgresql?
172172
context 'when db_adapter is postgresql' do
173173
it 'can call #to_sql on returned object' do
174174
result = datatable.build_conditions_for_selected_columns
@@ -180,7 +180,7 @@
180180
end
181181
end
182182

183-
if ENV['DB_ADAPTER'] == 'oracle_enhanced'
183+
if RunningSpec.oracle?
184184
context 'when db_adapter is oracle' do
185185
it 'can call #to_sql on returned object' do
186186
result = datatable.build_conditions_for_selected_columns
@@ -192,7 +192,7 @@
192192
end
193193
end
194194

195-
if ENV['DB_ADAPTER'] == 'mysql2'
195+
if RunningSpec.mysql?
196196
context 'when db_adapter is mysql2' do
197197
it 'can call #to_sql on returned object' do
198198
result = datatable.build_conditions_for_selected_columns
@@ -471,7 +471,7 @@
471471
create(:user, last_name: 'MARY')
472472
end
473473

474-
if ENV['DB_ADAPTER'] == 'oracle_enhanced'
474+
if RunningSpec.oracle?
475475
context 'when db_adapter is oracleenhanced' do
476476
it 'filters records matching' do
477477
datatable.params[:columns]['3'][:search][:value] = 'RY'

spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
end
1919

2020
it 'paginates records properly' do
21-
if ENV['DB_ADAPTER'] == 'oracle_enhanced'
21+
if RunningSpec.oracle?
2222
if Rails.version.in? %w[4.2.11]
2323
expect(datatable.paginate_records(records).to_sql).to include(
2424
'rownum <= 10'
@@ -36,7 +36,7 @@
3636

3737
datatable.params[:start] = '26'
3838
datatable.params[:length] = '25'
39-
if ENV['DB_ADAPTER'] == 'oracle_enhanced'
39+
if RunningSpec.oracle?
4040
if Rails.version.in? %w[4.2.11]
4141
expect(datatable.paginate_records(records).to_sql).to include(
4242
'rownum <= 51'

spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
after { datatable.nulls_last = false }
5252

5353
it 'can handle multiple sorting columns' do
54-
skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced'
54+
skip('unsupported database adapter') if RunningSpec.oracle?
5555

5656
# set to order by Users username in ascending order, and
5757
# by Users email in descending order
@@ -65,7 +65,7 @@
6565

6666
describe '#sort_records with nulls last using column config' do
6767
it 'can handle multiple sorting columns' do
68-
skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced'
68+
skip('unsupported database adapter') if RunningSpec.oracle?
6969

7070
# set to order by Users username in ascending order, and
7171
# by Users email in descending order

spec/spec_helper.rb

+19
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,27 @@
6161
end
6262
end
6363

64+
class RunningSpec
65+
def self.sqlite?
66+
ENV['DB_ADAPTER'] == 'sqlite3'
67+
end
68+
69+
def self.oracle?
70+
ENV['DB_ADAPTER'] == 'oracle_enhanced'
71+
end
72+
73+
def self.mysql?
74+
ENV['DB_ADAPTER'] == 'mysql2'
75+
end
76+
77+
def self.postgresql?
78+
ENV['DB_ADAPTER'] == 'postgresql'
79+
end
80+
end
81+
6482
# Configure ActiveRecord
6583
adapter = ENV.fetch('DB_ADAPTER', 'postgresql')
84+
ENV['DB_ADAPTER'] = adapter
6685

6786
options = {
6887
adapter: adapter,

0 commit comments

Comments
 (0)