diff --git a/appraisal.yml b/appraisal.yml index d0baf6e..51610ce 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 0c23f5d..7149371 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 19b7fbd..39ab3aa 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 0ec19b3..29c06cd 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 69366e8..840a7a9 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 6239d89..ec3409d 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 c28bfe8..71de756 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 b127b77..0d85bb2 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'