Skip to content

Commit d447c14

Browse files
author
Nicolas Rodriguez
committed
Test against MySQL and SQLite
1 parent d8c34b5 commit d447c14

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ after_success:
1414
- bundle exec codeclimate-test-reporter
1515
services:
1616
- postgresql
17+
- mysql
1718
addons:
1819
postgresql: '9.6'
20+
mariadb: '10.0'
1921
before_script:
22+
- mysql -e 'create database ajax_datatables_rails;'
2023
- psql -c 'create database ajax_datatables_rails;' -U postgres
24+
env:
25+
matrix:
26+
- DB_ADAPTER=postgresql
27+
- DB_ADAPTER=mysql2
28+
- DB_ADAPTER=sqlite3

ajax-datatables-rails.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
1818
s.add_development_dependency 'rails', '>= 4.2'
1919
s.add_development_dependency 'rake'
2020
s.add_development_dependency 'pg'
21+
s.add_development_dependency 'mysql2'
22+
s.add_development_dependency 'sqlite3'
2123
s.add_development_dependency 'rspec'
2224
s.add_development_dependency 'generator_spec'
2325
s.add_development_dependency 'pry'

ajax_datatables_rails

20 KB
Binary file not shown.

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,28 @@
8585
expect(result).to be_a(Arel::Nodes::And)
8686
end
8787

88-
it 'can call #to_sql on returned object' do
89-
result = datatable.send(:build_conditions_for_selected_columns)
90-
expect(result).to respond_to(:to_sql)
91-
expect(result.to_sql).to eq(
92-
"CAST(\"users\".\"username\" AS TEXT) ILIKE '%doe%' AND CAST(\"users\".\"email\" AS TEXT) ILIKE '%example%'"
93-
)
88+
if AjaxDatatablesRails.config.db_adapter == :postgresql
89+
context 'when db_adapter is postgresql' do
90+
it 'can call #to_sql on returned object' do
91+
result = datatable.send(:build_conditions_for_selected_columns)
92+
expect(result).to respond_to(:to_sql)
93+
expect(result.to_sql).to eq(
94+
"CAST(\"users\".\"username\" AS TEXT) ILIKE '%doe%' AND CAST(\"users\".\"email\" AS TEXT) ILIKE '%example%'"
95+
)
96+
end
97+
end
98+
end
99+
100+
if AjaxDatatablesRails.config.db_adapter.in? %i[mysql2 sqlite3]
101+
context 'when db_adapter is mysql2' 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 CHAR) LIKE '%doe%' AND CAST(`users`.`email` AS CHAR) LIKE '%example%'"
107+
)
108+
end
109+
end
94110
end
95111
end
96112

spec/spec_helper.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
FactoryGirl.find_definitions
2222
end
2323

24-
config.before(:each) do
24+
config.after(:each) do
2525
AjaxDatatablesRails.configure do |c|
26-
c.db_adapter = :sqlite
26+
c.db_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
2727
c.orm = :active_record
2828
end
2929
end
@@ -58,10 +58,15 @@
5858
require 'ajax-datatables-rails'
5959

6060
ActiveRecord::Base.establish_connection(
61-
adapter: 'postgresql',
61+
adapter: ENV.fetch('DB_ADAPTER', 'postgresql'),
6262
database: 'ajax_datatables_rails'
6363
)
6464

65+
AjaxDatatablesRails.configure do |c|
66+
c.db_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
67+
c.orm = :active_record
68+
end
69+
6570
load File.dirname(__FILE__) + '/support/schema.rb'
6671
load File.dirname(__FILE__) + '/support/test_helpers.rb'
6772
require File.dirname(__FILE__) + '/support/test_models.rb'

0 commit comments

Comments
 (0)