From 518b0162588bccb6bcf4f64c82f1391e958bc826 Mon Sep 17 00:00:00 2001 From: Adrian Hooper Date: Fri, 9 Dec 2022 10:57:52 +0000 Subject: [PATCH] Add support for postgis adapter --- appraisal.yml | 9 +++++++++ gemfiles/rails_6.0.6.gemfile | 4 ++++ gemfiles/rails_6.1.7.gemfile | 4 ++++ gemfiles/rails_7.0.4.gemfile | 4 ++++ lib/ajax-datatables-rails/datatable/simple_order.rb | 2 +- spec/ajax-datatables-rails/datatable/column_spec.rb | 5 +++++ .../ajax-datatables-rails/datatable/simple_order_spec.rb | 8 ++++++++ spec/support/helpers/params.rb | 2 +- 8 files changed, 36 insertions(+), 2 deletions(-) diff --git a/appraisal.yml b/appraisal.yml index d0baf6e2..51610ce8 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -12,6 +12,9 @@ ruby-oci8: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + activerecord-postgis-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' 6.1.7: sqlite3: @@ -26,6 +29,9 @@ ruby-oci8: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + activerecord-postgis-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' 7.0.4: sqlite3: @@ -40,3 +46,6 @@ ruby-oci8: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + activerecord-postgis-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' diff --git a/gemfiles/rails_6.0.6.gemfile b/gemfiles/rails_6.0.6.gemfile index 0c23f5dd..71493716 100644 --- a/gemfiles/rails_6.0.6.gemfile +++ b/gemfiles/rails_6.0.6.gemfile @@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "ruby-oci8" end +install_if -> { ENV["DB_ADAPTER"] == "postgis" } do + gem "activerecord-postgis-adapter" +end + gemspec path: "../" diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile index 19b7fbd6..39ab3aad 100644 --- a/gemfiles/rails_6.1.7.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "ruby-oci8" end +install_if -> { ENV["DB_ADAPTER"] == "postgis" } do + gem "activerecord-postgis-adapter" +end + gemspec path: "../" diff --git a/gemfiles/rails_7.0.4.gemfile b/gemfiles/rails_7.0.4.gemfile index 0ec19b30..29c06cd1 100644 --- a/gemfiles/rails_7.0.4.gemfile +++ b/gemfiles/rails_7.0.4.gemfile @@ -18,4 +18,8 @@ install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "ruby-oci8" end +install_if -> { ENV["DB_ADAPTER"] == "postgis" } do + gem "activerecord-postgis-adapter" +end + gemspec path: "../" diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 69366e83..840a7a99 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -45,7 +45,7 @@ def nulls_last_sql return unless sort_nulls_last? case @adapter - when :pg, :postgresql, :postgres, :oracle + when :pg, :postgresql, :postgres, :oracle, :postgis 'NULLS LAST' when :mysql, :mysql2, :sqlite, :sqlite3 'IS NULL' diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 6239d891..ec3409d2 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -168,6 +168,11 @@ expect(column.send(:type_cast)).to eq('VARCHAR') end + it 'returns VARCHAR if :db_adapter is :postgis' do + expect(datatable).to receive(:db_adapter) { :postgis } + expect(column.send(:type_cast)).to eq('VARCHAR') + end + it 'returns VARCHAR2(4000) if :db_adapter is :oracle' do expect(datatable).to receive(:db_adapter) { :oracle } expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index c28bfe84..71de756d 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -42,6 +42,14 @@ end end + context 'with postgis database adapter' do + before { parent.db_adapter = :postgis } + + it 'sql query' do + expect(nulls_last_order.query('email')).to eq('email DESC NULLS LAST') + end + end + context 'with sqlite database adapter' do before { parent.db_adapter = :sqlite } diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index b127b779..0d85bb2c 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -70,7 +70,7 @@ def sample_params_json def nulls_last_sql(datatable) case datatable.db_adapter - when :pg, :postgresql, :postgres, :oracle + when :pg, :postgresql, :postgres, :oracle, :postgis 'NULLS LAST' when :mysql, :mysql2, :sqlite, :sqlite3 'IS NULL'