Skip to content

Commit beb0f9c

Browse files
committed
Add support for postgis adapter
1 parent 8c906e4 commit beb0f9c

File tree

9 files changed

+43
-2
lines changed

9 files changed

+43
-2
lines changed

Diff for: appraisal.yml

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
ruby-oci8:
1313
version: ''
1414
install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }'
15+
activerecord-postgis-adapter:
16+
version: ''
17+
install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }'
1518

1619
6.0.4:
1720
sqlite3:
@@ -26,6 +29,9 @@
2629
ruby-oci8:
2730
version: ''
2831
install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }'
32+
activerecord-postgis-adapter:
33+
version: ''
34+
install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }'
2935

3036
6.1.4:
3137
sqlite3:
@@ -40,6 +46,9 @@
4046
ruby-oci8:
4147
version: ''
4248
install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }'
49+
activerecord-postgis-adapter:
50+
version: ''
51+
install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }'
4352

4453
7.0.1:
4554
sqlite3:
@@ -54,3 +63,6 @@
5463
ruby-oci8:
5564
version: ''
5665
install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }'
66+
activerecord-postgis-adapter:
67+
version: ''
68+
install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }'

Diff for: gemfiles/rails_5.2.6.gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do
1818
gem "ruby-oci8"
1919
end
2020

21+
install_if -> { ENV["DB_ADAPTER"] == "postgis" } do
22+
gem "activerecord-postgis-adapter"
23+
end
24+
2125
gemspec path: "../"

Diff for: gemfiles/rails_6.0.4.gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do
1818
gem "ruby-oci8"
1919
end
2020

21+
install_if -> { ENV["DB_ADAPTER"] == "postgis" } do
22+
gem "activerecord-postgis-adapter"
23+
end
24+
2125
gemspec path: "../"

Diff for: gemfiles/rails_6.1.4.gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do
1818
gem "ruby-oci8"
1919
end
2020

21+
install_if -> { ENV["DB_ADAPTER"] == "postgis" } do
22+
gem "activerecord-postgis-adapter"
23+
end
24+
2125
gemspec path: "../"

Diff for: gemfiles/rails_7.0.1.gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do
1818
gem "ruby-oci8"
1919
end
2020

21+
install_if -> { ENV["DB_ADAPTER"] == "postgis" } do
22+
gem "activerecord-postgis-adapter"
23+
end
24+
2125
gemspec path: "../"

Diff for: lib/ajax-datatables-rails/datatable/simple_order.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def nulls_last_sql
4545
return unless sort_nulls_last?
4646

4747
case @adapter
48-
when :pg, :postgresql, :postgres, :oracle
48+
when :pg, :postgresql, :postgres, :oracle, :postgis
4949
'NULLS LAST'
5050
when :mysql, :mysql2, :sqlite, :sqlite3
5151
'IS NULL'

Diff for: spec/ajax-datatables-rails/datatable/column_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
expect(column.send(:type_cast)).to eq('VARCHAR')
169169
end
170170

171+
it 'returns VARCHAR if :db_adapter is :postgis' do
172+
expect(datatable).to receive(:db_adapter) { :postgis }
173+
expect(column.send(:type_cast)).to eq('VARCHAR')
174+
end
175+
171176
it 'returns VARCHAR2(4000) if :db_adapter is :oracle' do
172177
expect(datatable).to receive(:db_adapter) { :oracle }
173178
expect(column.send(:type_cast)).to eq('VARCHAR2(4000)')

Diff for: spec/ajax-datatables-rails/datatable/simple_order_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
end
4343
end
4444

45+
context 'with postgis database adapter' do
46+
before { parent.db_adapter = :postgis }
47+
48+
it 'sql query' do
49+
expect(nulls_last_order.query('email')).to eq('email DESC NULLS LAST')
50+
end
51+
end
52+
4553
context 'with sqlite database adapter' do
4654
before { parent.db_adapter = :sqlite }
4755

Diff for: spec/support/helpers/params.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def sample_params_json
7070

7171
def nulls_last_sql(datatable)
7272
case datatable.db_adapter
73-
when :pg, :postgresql, :postgres, :oracle
73+
when :pg, :postgresql, :postgres, :oracle, :postgis
7474
'NULLS LAST'
7575
when :mysql, :mysql2, :sqlite, :sqlite3
7676
'IS NULL'

0 commit comments

Comments
 (0)