From 55b450c2fd25046769cff55e69afe9098441e89f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 07:04:15 +0200 Subject: [PATCH 001/290] Drop support of Rails 4.0.x, 4.1.x and Ruby 2.2.x --- .travis.yml | 43 +------ Appraisals | 8 -- CHANGELOG.md | 2 +- README.md | 4 +- ajax-datatables-rails.gemspec | 5 +- gemfiles/rails_4.0.13.gemfile | 14 --- gemfiles/rails_4.1.16.gemfile | 14 --- lib/ajax-datatables-rails/config.rb | 8 +- lib/ajax-datatables-rails/datatable/column.rb | 2 +- .../datatable/datatable.rb | 6 +- lib/ajax_datatables_rails.rb | 2 +- .../datatable/column_spec.rb | 8 +- .../orm/active_record_filter_records_spec.rb | 112 +++++++++--------- 13 files changed, 71 insertions(+), 157 deletions(-) delete mode 100644 gemfiles/rails_4.0.13.gemfile delete mode 100644 gemfiles/rails_4.1.16.gemfile diff --git a/.travis.yml b/.travis.yml index b05d792d..e095f961 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,53 +3,14 @@ language: ruby sudo: required cache: bundler rvm: - - 2.2.10 - 2.3.7 + - 2.4.4 + - 2.5.1 gemfile: - - gemfiles/rails_4.0.13.gemfile - - gemfiles/rails_4.1.16.gemfile - gemfiles/rails_4.2.10.gemfile - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.6.gemfile - gemfiles/rails_5.2.0.gemfile -matrix: - include: - - rvm: 2.4.4 - gemfile: gemfiles/rails_4.2.10.gemfile - env: DB_ADAPTER=postgresql - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.0.7.gemfile - env: DB_ADAPTER=postgresql - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.1.6.gemfile - env: DB_ADAPTER=postgresql - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.2.0.gemfile - env: DB_ADAPTER=postgresql - - rvm: 2.4.4 - gemfile: gemfiles/rails_4.2.10.gemfile - env: DB_ADAPTER=mysql2 - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.0.7.gemfile - env: DB_ADAPTER=mysql2 - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.1.6.gemfile - env: DB_ADAPTER=mysql2 - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.2.0.gemfile - env: DB_ADAPTER=mysql2 - - rvm: 2.4.4 - gemfile: gemfiles/rails_4.2.10.gemfile - env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.0.7.gemfile - env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.1.6.gemfile - env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.4 - gemfile: gemfiles/rails_5.2.0.gemfile - env: DB_ADAPTER=oracle_enhanced after_success: - bundle exec codeclimate-test-reporter services: diff --git a/Appraisals b/Appraisals index de10f668..96b05ec4 100644 --- a/Appraisals +++ b/Appraisals @@ -1,14 +1,6 @@ # frozen_string_literal: true RAILS_VERSIONS = { - '4.0.13' => { - 'mysql2' => '~> 0.3.18', - 'activerecord-oracle_enhanced-adapter' => '~> 1.5.0' - }, - '4.1.16' => { - 'mysql2' => '~> 0.3.18', - 'activerecord-oracle_enhanced-adapter' => '~> 1.5.0' - }, '4.2.10' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0' }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc97a6b..84961fdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ * Change: Add # frozen_string_literal: true pragma * Various improvements in internal API -**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x +**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x and Ruby 2.2.x. ## 0.4.0 (2017-05-21) diff --git a/README.md b/README.md index 64e354a0..401f43b7 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ It's tested against : -* Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.7 / 5.1.6 / 5.2.0 -* Ruby 2.2.10 / 2.3.7 / 2.4.4 / 2.5.1 +* Rails 4.2.10 / 5.0.7 / 5.1.6 / 5.2.0 +* Ruby 2.3.7 / 2.4.4 / 2.5.1 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 780b46b7..0d873283 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -1,5 +1,4 @@ # frozen_string_literal: true -# coding: utf-8 $LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'ajax-datatables-rails/version' @@ -15,9 +14,9 @@ Gem::Specification.new do |s| s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app" s.license = 'MIT' - s.add_dependency 'railties', '>= 4.0' + s.add_dependency 'railties', '>= 4.2' - s.add_development_dependency 'rails', '>= 4.0' + s.add_development_dependency 'rails', '>= 4.2' s.add_development_dependency 'rake' s.add_development_dependency 'pg', '< 1.0' s.add_development_dependency 'mysql2' diff --git a/gemfiles/rails_4.0.13.gemfile b/gemfiles/rails_4.0.13.gemfile deleted file mode 100644 index 8e751c3c..00000000 --- a/gemfiles/rails_4.0.13.gemfile +++ /dev/null @@ -1,14 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "4.0.13" -gem "mysql2", "~> 0.3.18" -gem "activerecord-oracle_enhanced-adapter", "~> 1.5.0" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" - -group :test do - gem "codeclimate-test-reporter", "~> 1.0.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_4.1.16.gemfile b/gemfiles/rails_4.1.16.gemfile deleted file mode 100644 index 8af0b017..00000000 --- a/gemfiles/rails_4.1.16.gemfile +++ /dev/null @@ -1,14 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "4.1.16" -gem "mysql2", "~> 0.3.18" -gem "activerecord-oracle_enhanced-adapter", "~> 1.5.0" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" - -group :test do - gem "codeclimate-test-reporter", "~> 1.0.0" -end - -gemspec path: "../" diff --git a/lib/ajax-datatables-rails/config.rb b/lib/ajax-datatables-rails/config.rb index bbcb3c4d..f481809e 100644 --- a/lib/ajax-datatables-rails/config.rb +++ b/lib/ajax-datatables-rails/config.rb @@ -4,10 +4,12 @@ module AjaxDatatablesRails - # configure AjaxDatatablesRails global settings + # Configure AjaxDatatablesRails global settings + # # AjaxDatatablesRails.configure do |config| # config.db_adapter = :postgresql # end + def self.configure yield @config ||= AjaxDatatablesRails::Configuration.new end @@ -17,10 +19,6 @@ def self.config @config ||= AjaxDatatablesRails::Configuration.new end - def self.old_rails? - Rails::VERSION::MAJOR == 4 && (Rails::VERSION::MINOR == 1 || Rails::VERSION::MINOR == 0) - end - class Configuration include ActiveSupport::Configurable diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 81ce4b77..50b2e13c 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -18,7 +18,7 @@ class Column include Search include Order - prepend DateFilter unless AjaxDatatablesRails.old_rails? + prepend DateFilter def initialize(datatable, index, options) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index c2db1d50..da2f74e8 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -70,11 +70,7 @@ def page end def get_param(param) - if AjaxDatatablesRails.old_rails? - options[param] - else - options[param].to_unsafe_h.with_indifferent_access - end + options[param].to_unsafe_h.with_indifferent_access end end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb index 49bc773d..5a6cb459 100644 --- a/lib/ajax_datatables_rails.rb +++ b/lib/ajax_datatables_rails.rb @@ -9,7 +9,7 @@ module AjaxDatatablesRails require 'ajax-datatables-rails/datatable/simple_order' require 'ajax-datatables-rails/datatable/column/search' require 'ajax-datatables-rails/datatable/column/order' - require 'ajax-datatables-rails/datatable/column/date_filter' unless AjaxDatatablesRails.old_rails? + require 'ajax-datatables-rails/datatable/column/date_filter' require 'ajax-datatables-rails/datatable/column' require 'ajax-datatables-rails/orm/active_record' end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 7e540d2a..38f85a10 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -121,11 +121,9 @@ end end - unless AjaxDatatablesRails.old_rails? - describe '#delimiter' do - it 'should be - by default' do - expect(column.delimiter).to eq('-') - end + describe '#delimiter' do + it 'should be - by default' do + expect(column.delimiter).to eq('-') end end end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 32ac59b3..32af9012 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -234,84 +234,82 @@ end describe 'filter conditions' do - unless AjaxDatatablesRails.old_rails? - describe 'it can filter records with condition :date_range' do - let(:datatable) { DatatableCondDate.new(view) } + describe 'it can filter records with condition :date_range' do + let(:datatable) { DatatableCondDate.new(view) } - before(:each) do - create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000') - create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000') + before(:each) do + create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000') + create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000') + end + + context 'when range is empty' do + it 'should not filter records' do + datatable.params[:columns]['5'][:search][:value] = '-' + expect(datatable.data.size).to eq 2 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' end + end + + context 'when start date is filled' do + it 'should filter records created after this date' do + datatable.params[:columns]['5'][:search][:value] = '31/12/1999-' + expect(datatable.data.size).to eq 2 + end + end + context 'when end date is filled' do + it 'should filter records created before this date' do + datatable.params[:columns]['5'][:search][:value] = '-31/12/1999' + expect(datatable.data.size).to eq 0 + end + end + + context 'when both date are filled' do + it 'should filter records created between the range' do + datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' + expect(datatable.data.size).to eq 1 + end + end + + context 'when another filter is active' do context 'when range is empty' do - it 'should not filter records' do + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['5'][:search][:value] = '-' - expect(datatable.data.size).to eq 2 + expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' end end context 'when start date is filled' do - it 'should filter records created after this date' do - datatable.params[:columns]['5'][:search][:value] = '31/12/1999-' - expect(datatable.data.size).to eq 2 + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' + datatable.params[:columns]['5'][:search][:value] = '01/12/1999-' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' end end context 'when end date is filled' do - it 'should filter records created before this date' do - datatable.params[:columns]['5'][:search][:value] = '-31/12/1999' - expect(datatable.data.size).to eq 0 + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' + datatable.params[:columns]['5'][:search][:value] = '-15/01/2000' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' end end context 'when both date are filled' do - it 'should filter records created between the range' do + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 - end - end - - context 'when another filter is active' do - context 'when range is empty' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '-' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' - end - end - - context 'when start date is filled' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' - end - end - - context 'when end date is filled' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '-15/01/2000' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' - end - end - - context 'when both date are filled' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' - end + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' end end end From b89e857c8d9523088a41bba33ebbcd9a4f47eb4f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 9 May 2018 01:08:40 +0200 Subject: [PATCH 002/290] Update README [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 401f43b7..dfc89c31 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ We assume here that you have already installed [jQuery DataTables](https://datat You can install jQuery DataTables : -* with the [`jquery-datatables-rails`](https://github.com/rweng/jquery-datatables-rails) gem (which is a bit outdated) +* with the [`jquery-datatables`](https://github.com/mkhairi/jquery-datatables) gem * by adding the assets manually (in `vendor/assets`) * with [Rails webpacker gem](https://github.com/rails/webpacker) (see [here](/doc/webpack.md) for more infos) From 15d93612d4bf8f2fb66fbbaff845b8109ba332cb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 9 May 2018 02:28:40 +0200 Subject: [PATCH 003/290] Update README [ci skip] --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dfc89c31..581354a9 100644 --- a/README.md +++ b/README.md @@ -690,6 +690,8 @@ You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277) +Use [has_scope](https://github.com/plataformatec/has_scope) gem with `ajax-datatables-rails` : [#280](https://github.com/jbox-web/ajax-datatables-rails/issues/280) + ## Contributing 1. Fork it From 9b2555ab100357c78f535239764cb8b92e598029 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 9 May 2018 05:51:05 +0200 Subject: [PATCH 004/290] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 581354a9..ef2eba51 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![Build Status](https://travis-ci.org/jbox-web/ajax-datatables-rails.svg?branch=master)](https://travis-ci.org/jbox-web/ajax-datatables-rails) [![Code Climate](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails) [![Test Coverage](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/coverage) -[![Dependency Status](https://gemnasium.com/jbox-web/ajax-datatables-rails.svg)](https://gemnasium.com/jbox-web/ajax-datatables-rails) **Important : This gem is targeted at DataTables version 1.10.x.** From 82f34450dadf9fb946b1a0a322bbf6dd29f0a5a4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 10 May 2018 05:36:05 +0200 Subject: [PATCH 005/290] Update README [ci skip] --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef2eba51..35dcc7c4 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,20 @@ end See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models. +You can customize or sanitize the search value passed to the DB by using the `:formater` option : + +```ruby +def view_columns + @view_columns ||= { + id: { source: "User.id" }, + first_name: { source: "User.first_name" }, + last_name: { source: "User.last_name" }, + email: { source: "User.email", formater: -> (o) { o.upcase } }, + bio: { source: "User.bio" }, + } +end +``` + #### b. Map data Then we need to map the records retrieved by the `get_raw_records` method to the real values we want to display : @@ -225,7 +239,7 @@ def data last_name: record.last_name, email: record.email, bio: record.bio, - DT_RowId: record.id, # This will set the id attribute on the corresponding in the datatable + DT_RowId: record.id, # This will automagically set the id attribute on the corresponding in the datatable } end end @@ -398,6 +412,8 @@ class MyCustomDatatable < AjaxDatatablesRails::Base end ``` +### Using view decorators + If you want to keep things tidy in the data mapping method, you could use [Draper](https://github.com/drapergem/draper) to define column mappings like below. @@ -640,7 +656,9 @@ In the end, it's up to the developer which model(s), scope(s), relationship(s) (or else) to employ inside the datatable class to retrieve records from the database. -### Creating indices for Postgresql +## Pro Tips + +### Create indices for Postgresql In order to speed up the `ILIKE` queries that are executed when using the default configuration, you might want to consider adding some indices. For postgresql, you are advised to use the [gin/gist index type](http://www.postgresql.org/docs/current/interactive/pgtrgm.html). @@ -683,6 +701,71 @@ $ bundle install That's all :) ([Automatically prefer Yajl or JSON backend over Yaml, if available](https://github.com/rails/rails/commit/63bb955a99eb46e257655c93dd64e86ebbf05651)) +### Use HTTP `POST` method + +Use HTTP `POST` method to avoid `414 Request-URI Too Large` error. See : [#278](https://github.com/jbox-web/ajax-datatables-rails/issues/278). + +You can easily define a route concern in `config/routes.rb` and reuse it when you need it : + +```ruby +Rails.application.routes.draw do + concern :with_datatable do + post 'datatable', on: :collection + end + + resources :posts, concerns: [:with_datatable] + resources :users, concerns: [:with_datatable] +end +``` + +then in your controllers : + +```ruby +# PostsController + def index + end + + def datatable + render json: PostDatatable.new(view_context) + end + +# UsersController + def index + end + + def datatable + render json: UserDatatable.new(view_context) + end +``` + +then in your views : + +```html +# posts/index.html.erb + + +# users/index.html.erb +
+``` + +then in your Coffee/JS : + +```coffee +$ -> + $('#posts-datatable').dataTable + ajax: + url: $('#posts-datatable').data('source') + type: 'POST' + # ...others options, see [here](#5-wire-up-the-javascript) + +$ -> + $('#users-datatable').dataTable + ajax: + url: $('#users-datatable').data('source') + type: 'POST' + # ...others options, see [here](#5-wire-up-the-javascript) +``` + ## Tutorial You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to). Its real world example. From cb8a3da504f4dcfda2fe3dfa2bc6afd5f2b4fa11 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 11 May 2018 00:26:42 +0200 Subject: [PATCH 006/290] Fix typo --- README.md | 4 ++-- lib/ajax-datatables-rails/datatable/column.rb | 8 ++++---- spec/ajax-datatables-rails/datatable/column_spec.rb | 4 ++-- spec/support/datatable_cond_string.rb | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 35dcc7c4..2691666e 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ end See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models. -You can customize or sanitize the search value passed to the DB by using the `:formater` option : +You can customize or sanitize the search value passed to the DB by using the `:formatter` option : ```ruby def view_columns @@ -220,7 +220,7 @@ def view_columns id: { source: "User.id" }, first_name: { source: "User.first_name" }, last_name: { source: "User.last_name" }, - email: { source: "User.email", formater: -> (o) { o.upcase } }, + email: { source: "User.email", formatter: -> (o) { o.upcase } }, bio: { source: "User.bio" }, } end diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 50b2e13c..5580dd11 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -52,14 +52,14 @@ def custom_field? !source.include?('.') end - # Add formater option to allow modification of the value + # Add formatter option to allow modification of the value # before passing it to the database - def formater - @view_column[:formater] + def formatter + @view_column[:formatter] end def formated_value - formater ? formater.call(search.value) : search.value + formatter ? formatter.call(search.value) : search.value end private diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 38f85a10..e702ba89 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -128,12 +128,12 @@ end end - describe '#formater' do + describe '#formatter' do let(:datatable) { DatatableWithFormater.new(view) } let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } } it 'should be a proc' do - expect(column.formater).to be_a(Proc) + expect(column.formatter).to be_a(Proc) end end diff --git a/spec/support/datatable_cond_string.rb b/spec/support/datatable_cond_string.rb index bc799701..8c479aab 100644 --- a/spec/support/datatable_cond_string.rb +++ b/spec/support/datatable_cond_string.rb @@ -18,6 +18,6 @@ def view_columns class DatatableWithFormater < ComplexDatatable def view_columns - super.deep_merge(last_name: { formater: -> (o) { o.upcase } }) + super.deep_merge(last_name: { formatter: -> (o) { o.upcase } }) end end From ec35c188d99bb9cd6956aa5da0fd3680df953e18 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 11 May 2018 00:33:28 +0200 Subject: [PATCH 007/290] Update README [ci skip] --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2691666e..240a2c11 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ end See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models. -You can customize or sanitize the search value passed to the DB by using the `:formatter` option : +You can customize or sanitize the search value passed to the DB by using the `:formatter` option with a lambda : ```ruby def view_columns @@ -226,6 +226,8 @@ def view_columns end ``` +The object passed to the lambda is the search value. + #### b. Map data Then we need to map the records retrieved by the `get_raw_records` method to the real values we want to display : From 192f5d3030e3dd021a4f5e3a5b124b516207f493 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 11 May 2018 01:12:40 +0200 Subject: [PATCH 008/290] Fix integer out of range --- .../datatable/column/search.rb | 26 +++++++++++++++++- .../orm/active_record_filter_records_spec.rb | 27 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index e3371134..a6280892 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -5,6 +5,9 @@ module Datatable class Column module Search + SMALLEST_PQ_INTEGER = -2147483648 + LARGEST_PQ_INTEGER = 2147483647 + def searchable? @view_column.fetch(:searchable, true) end @@ -54,7 +57,7 @@ def non_regex_search when Proc filter when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in - numeric_search + is_searchable_integer? ? numeric_search : empty_search when :null_value null_value_search when :start_with @@ -82,6 +85,27 @@ def numeric_search end end + def empty_search + casted_column.matches('') + end + + def is_searchable_integer? + if search.value.is_a?(Array) + valids = search.value.map { |v| is_integer?(v) && !is_out_of_range?(v) } + !valids.include?(false) + else + is_integer?(search.value) && !is_out_of_range?(search.value) + end + end + + def is_out_of_range?(search_value) + Integer(search_value) > LARGEST_PQ_INTEGER || Integer(search_value) < SMALLEST_PQ_INTEGER + end + + def is_integer?(string) + true if Integer(string) rescue false + end + end end end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 32af9012..8f658521 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -492,5 +492,32 @@ expect(item[:first_name]).to eq 'john' end end + + describe 'Integer overflows' do + let(:datatable) { DatatableCondEq.new(view) } + let(:largest_postgresql_integer_value) { 2147483647 } + let(:smallest_postgresql_integer_value) { -2147483648 } + + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value) + end + + it 'Returns an empty result if input value is too large' do + datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + 1 + expect(datatable.data.size).to eq 0 + end + + it 'Returns an empty result if input value is too small' do + datatable.params[:columns]['4'][:search][:value] = smallest_postgresql_integer_value - 1 + expect(datatable.data.size).to eq 0 + end + + it 'returns the matching user' do + datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + expect(datatable.data.size).to eq 1 + end + end end end From c7c6fa6487aca3937135443ae8d6968a89d83a02 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 11 May 2018 01:15:45 +0200 Subject: [PATCH 009/290] Bump to version 0.5.0 [ci skip] --- lib/ajax-datatables-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index f918a55a..2f322c78 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AjaxDatatablesRails - VERSION = '0.4.1' + VERSION = '0.5.0' end From acee9ccd92a422076704101fc17cccbeb4dbe351 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 11 May 2018 01:53:46 +0200 Subject: [PATCH 010/290] Update CHANGELOG [ci skip] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84961fdd..8af808ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.4.2 (2018-05-11) + +* Fix: Integer out of range [PR #289](https://github.com/jbox-web/ajax-datatables-rails/pull/289) from [PR #284](https://github.com/jbox-web/ajax-datatables-rails/pull/284) + ## 0.4.1 (2018-05-06) * Fix: Restore behavior of #filter method [Comment](https://github.com/jbox-web/ajax-datatables-rails/commit/07795fd26849ff1b3b567f4ce967f722907a45be#comments) From bd95e85ed13eea53db5a6832cb09c7abcc353a73 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 15 May 2018 06:50:57 +0200 Subject: [PATCH 011/290] Fix typo --- lib/ajax-datatables-rails/datatable/column.rb | 2 +- .../datatable/column/date_filter.rb | 6 +++--- .../datatable/column/search.rb | 16 ++++++++-------- .../datatable/column_spec.rb | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 5580dd11..6df8edf6 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -58,7 +58,7 @@ def formatter @view_column[:formatter] end - def formated_value + def formatted_value formatter ? formatter.call(search.value) : search.value end diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index 09296f4e..bb1b90f1 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -24,19 +24,19 @@ def delimiter end def empty_range_search? - (formated_value == delimiter) || (range_start.blank? && range_end.blank?) + (formatted_value == delimiter) || (range_start.blank? && range_end.blank?) end # A range value is in form '' # This returns def range_start - @range_start ||= formated_value.split(delimiter)[0] + @range_start ||= formatted_value.split(delimiter)[0] end # A range value is in form '' # This returns def range_end - @range_end ||= formated_value.split(delimiter)[1] + @range_end ||= formatted_value.split(delimiter)[1] end # Do a range search diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index a6280892..4cadc94b 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -17,7 +17,7 @@ def cond end def filter - @view_column[:cond].call(self, formated_value) + @view_column[:cond].call(self, formatted_value) end def search @@ -46,7 +46,7 @@ def use_regex? # The solution is to bypass regex_search and use non_regex_search with :in operator def regex_search if use_regex? - ::Arel::Nodes::Regexp.new((custom_field? ? field : table[field]), ::Arel::Nodes.build_quoted(formated_value)) + ::Arel::Nodes::Regexp.new((custom_field? ? field : table[field]), ::Arel::Nodes.build_quoted(formatted_value)) else non_regex_search end @@ -61,16 +61,16 @@ def non_regex_search when :null_value null_value_search when :start_with - casted_column.matches("#{formated_value}%") + casted_column.matches("#{formatted_value}%") when :end_with - casted_column.matches("%#{formated_value}") + casted_column.matches("%#{formatted_value}") when :like - casted_column.matches("%#{formated_value}%") + casted_column.matches("%#{formatted_value}%") end end def null_value_search - if formated_value == '!NULL' + if formatted_value == '!NULL' table[field].not_eq(nil) else table[field].eq(nil) @@ -79,9 +79,9 @@ def null_value_search def numeric_search if custom_field? - ::Arel::Nodes::SqlLiteral.new(field).eq(formated_value) + ::Arel::Nodes::SqlLiteral.new(field).eq(formatted_value) else - table[field].send(cond, formated_value) + table[field].send(cond, formatted_value) end end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index e702ba89..e0be5231 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -145,7 +145,7 @@ config = column.instance_variable_get('@view_column') filter = config[:cond] expect(filter).to be_a(Proc) - expect(filter).to receive(:call).with(column, column.formated_value) + expect(filter).to receive(:call).with(column, column.formatted_value) column.filter end end From 6bf3e586436d6177bf58e8fd02913c92d7ac934c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 15 May 2018 07:28:33 +0200 Subject: [PATCH 012/290] We should use formatted_value when checking for searchable integers --- .../datatable/column/search.rb | 6 +++--- .../orm/active_record_filter_records_spec.rb | 16 ++++++++++++++++ spec/support/datatable_cond_numeric.rb | 10 ++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 4cadc94b..c0fd8ddc 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -90,11 +90,11 @@ def empty_search end def is_searchable_integer? - if search.value.is_a?(Array) - valids = search.value.map { |v| is_integer?(v) && !is_out_of_range?(v) } + if formatted_value.is_a?(Array) + valids = formatted_value.map { |v| is_integer?(v) && !is_out_of_range?(v) } !valids.include?(false) else - is_integer?(search.value) && !is_out_of_range?(search.value) + is_integer?(formatted_value) && !is_out_of_range?(formatted_value) end end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 8f658521..b1b53e9d 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -493,6 +493,22 @@ end end + describe 'it can filter records with condition :in with regex' do + let(:datatable) { DatatableCondInWithRegex.new(view) } + + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end + + it 'should filter records matching' do + datatable.params[:columns]['4'][:search][:value] = '1|2' + expect(datatable.data.size).to eq 2 + item = datatable.data.first + expect(item[:first_name]).to eq 'john' + end + end + describe 'Integer overflows' do let(:datatable) { DatatableCondEq.new(view) } let(:largest_postgresql_integer_value) { 2147483647 } diff --git a/spec/support/datatable_cond_numeric.rb b/spec/support/datatable_cond_numeric.rb index 7832bc11..4c5e2f47 100644 --- a/spec/support/datatable_cond_numeric.rb +++ b/spec/support/datatable_cond_numeric.rb @@ -39,3 +39,13 @@ def view_columns super.deep_merge(post_id: { cond: :in }) end end + +class DatatableCondInWithRegex < DatatableCondIn + def view_columns + super.deep_merge(post_id: { cond: :in, use_regex: false, formatter: ->(str) { cast_regex_value(str) } }) + end + + def cast_regex_value(value) + value.split('|').map(&:to_i) + end +end From 56b13df34e3602b03749158b6de7d05d5fb0c649 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 15 May 2018 07:33:27 +0200 Subject: [PATCH 013/290] Update CHANGELOG [ci skip] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8af808ec..acc1704e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 0.4.2 (2018-05-11) +## 0.4.2 (2018-05-15) * Fix: Integer out of range [PR #289](https://github.com/jbox-web/ajax-datatables-rails/pull/289) from [PR #284](https://github.com/jbox-web/ajax-datatables-rails/pull/284) From 6a8e53d518b8b27599f377b742cf0d871d250b93 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 15 May 2018 07:51:11 +0200 Subject: [PATCH 014/290] Fix bug in ordering on Travis --- .../orm/active_record_filter_records_spec.rb | 1 + spec/support/datatable_cond_numeric.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index b1b53e9d..cfb5b7af 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -503,6 +503,7 @@ it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = '1|2' + datatable.params[:order]['0'] = { column: '4', dir: 'asc' } expect(datatable.data.size).to eq 2 item = datatable.data.first expect(item[:first_name]).to eq 'john' diff --git a/spec/support/datatable_cond_numeric.rb b/spec/support/datatable_cond_numeric.rb index 4c5e2f47..c42109fe 100644 --- a/spec/support/datatable_cond_numeric.rb +++ b/spec/support/datatable_cond_numeric.rb @@ -42,7 +42,7 @@ def view_columns class DatatableCondInWithRegex < DatatableCondIn def view_columns - super.deep_merge(post_id: { cond: :in, use_regex: false, formatter: ->(str) { cast_regex_value(str) } }) + super.deep_merge(post_id: { cond: :in, use_regex: false, orderable: true, formatter: ->(str) { cast_regex_value(str) } }) end def cast_regex_value(value) From 5035718dd44445ca24115fcf70c66fc8d4fe822b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jun 2018 23:54:15 +0200 Subject: [PATCH 015/290] Add :string_eq condition. Fix https://github.com/jbox-web/ajax-datatables-rails/issues/291 --- README.md | 2 +- .../datatable/column/search.rb | 6 ++-- .../orm/active_record_filter_records_spec.rb | 32 +++++++++++++++++++ spec/support/datatable_cond_string.rb | 12 +++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 240a2c11..53f5125b 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ end `cond` can be : -* `:like`, `:start_with`, `:end_with` for string or full text search +* `:like`, `:start_with`, `:end_with`, `:string_eq` for string or full text search * `:eq`, `:not_eq`, `:lt`, `:gt`, `:lteq`, `:gteq`, `:in` for numeric * `:date_range` for date range (only for Rails > 4.2.x, see [here](#daterange-search)) * `:null_value` for nil field diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index c0fd8ddc..e853e7b8 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -57,7 +57,7 @@ def non_regex_search when Proc filter when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in - is_searchable_integer? ? numeric_search : empty_search + is_searchable_integer? ? raw_search(cond) : empty_search when :null_value null_value_search when :start_with @@ -66,6 +66,8 @@ def non_regex_search casted_column.matches("%#{formatted_value}") when :like casted_column.matches("%#{formatted_value}%") + when :string_eq + raw_search(:eq) end end @@ -77,7 +79,7 @@ def null_value_search end end - def numeric_search + def raw_search(cond) if custom_field? ::Arel::Nodes::SqlLiteral.new(field).eq(formatted_value) else diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index cfb5b7af..ed8cad48 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -358,6 +358,38 @@ end end + describe 'it can filter records with condition :like' do + let(:datatable) { DatatableCondLike.new(view) } + + before(:each) do + create(:user, email: 'john@foo.com') + create(:user, email: 'mary@bar.com') + end + + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'foo' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end + end + + describe 'it can filter records with condition :string_eq' do + let(:datatable) { DatatableCondStringEq.new(view) } + + before(:each) do + create(:user, email: 'john@foo.com') + create(:user, email: 'mary@bar.com') + end + + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end + end + describe 'it can filter records with condition :null_value' do let(:datatable) { DatatableCondNullValue.new(view) } diff --git a/spec/support/datatable_cond_string.rb b/spec/support/datatable_cond_string.rb index 8c479aab..5aef02fc 100644 --- a/spec/support/datatable_cond_string.rb +++ b/spec/support/datatable_cond_string.rb @@ -10,6 +10,18 @@ def view_columns end end +class DatatableCondLike < ComplexDatatable + def view_columns + super.deep_merge(email: { cond: :like }) + end +end + +class DatatableCondStringEq < ComplexDatatable + def view_columns + super.deep_merge(email: { cond: :string_eq }) + end +end + class DatatableCondNullValue < ComplexDatatable def view_columns super.deep_merge(email: { cond: :null_value }) From 5e3ac4df4656ab94a932d4dfeaf3cc3f12bec470 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 00:27:44 +0200 Subject: [PATCH 016/290] Update CHANGELOG --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acc1704e..91d2fcec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 0.4.3 (2018-06-05) + +* Add: Add `:string_eq` condition on columns filter [Issue #291](https://github.com/jbox-web/ajax-datatables-rails/issues/291) + +**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x + ## 0.4.2 (2018-05-15) * Fix: Integer out of range [PR #289](https://github.com/jbox-web/ajax-datatables-rails/pull/289) from [PR #284](https://github.com/jbox-web/ajax-datatables-rails/pull/284) @@ -16,9 +22,6 @@ * Change: Add # frozen_string_literal: true pragma * Various improvements in internal API -**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x and Ruby 2.2.x. - - ## 0.4.0 (2017-05-21) **Warning:** this version is a **major break** from v0.3. The core has been rewriten to remove dependency on Kaminari (or WillPaginate). From bfd245aa07f64be5eca16fdf4b50f5a283e6372f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 00:51:32 +0200 Subject: [PATCH 017/290] Now that Rails 4.0 support is dropped we can replace prepend by include --- lib/ajax-datatables-rails/datatable/column.rb | 2 +- lib/ajax-datatables-rails/datatable/column/date_filter.rb | 8 -------- lib/ajax-datatables-rails/datatable/column/search.rb | 2 ++ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 6df8edf6..7515c4d5 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -18,7 +18,7 @@ class Column include Search include Order - prepend DateFilter + include DateFilter def initialize(datatable, index, options) diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index bb1b90f1..3d6f8223 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -47,14 +47,6 @@ def date_range_search private - def non_regex_search - if cond == :date_range - date_range_search - else - super - end - end - def range_start_casted range_start.blank? ? parse_date('01/01/1970') : parse_date(range_start) end diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index e853e7b8..42a6d741 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -68,6 +68,8 @@ def non_regex_search casted_column.matches("%#{formatted_value}%") when :string_eq raw_search(:eq) + when :date_range + date_range_search end end From 2962d4505f9dc42376254ac9d454e28afc979473 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 00:55:26 +0200 Subject: [PATCH 018/290] Use Hash#fetch with default value (more Rubyish) --- lib/ajax-datatables-rails/datatable/column/order.rb | 2 +- lib/ajax-datatables-rails/datatable/column/search.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/order.rb b/lib/ajax-datatables-rails/datatable/column/order.rb index 2c784781..3806e494 100644 --- a/lib/ajax-datatables-rails/datatable/column/order.rb +++ b/lib/ajax-datatables-rails/datatable/column/order.rb @@ -11,7 +11,7 @@ def orderable? # Add sort_field option to allow overriding of sort field def sort_field - @view_column[:sort_field] || field + @view_column.fetch(:sort_field, field) end def sort_query diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 42a6d741..22204925 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -13,7 +13,7 @@ def searchable? end def cond - @view_column[:cond] || :like + @view_column.fetch(:cond, :like) end def filter From 5862ca91bf1283fa5e22304d6cbd00d981619e70 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 01:11:17 +0200 Subject: [PATCH 019/290] Do some micro optimizations on strings --- lib/ajax-datatables-rails/datatable/column.rb | 19 ++++++++++++------- .../datatable/column/search.rb | 8 +++++--- .../datatable/datatable.rb | 2 -- .../datatable/simple_order.rb | 6 ++++-- .../datatable/simple_search.rb | 2 ++ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 7515c4d5..7a181ac5 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -4,13 +4,18 @@ module AjaxDatatablesRails module Datatable class Column + TYPE_CAST_DEFAULT = 'VARCHAR' + TYPE_CAST_MYSQL = 'CHAR' + TYPE_CAST_SQLITE = 'TEXT' + TYPE_CAST_ORACLE = 'VARCHAR2(4000)' + DB_ADAPTER_TYPE_CAST = { - mysql: 'CHAR', - mysql2: 'CHAR', - sqlite: 'TEXT', - sqlite3: 'TEXT', - oracle: 'VARCHAR2(4000)', - oracleenhanced: 'VARCHAR2(4000)' + mysql: TYPE_CAST_MYSQL, + mysql2: TYPE_CAST_MYSQL, + sqlite: TYPE_CAST_SQLITE, + sqlite3: TYPE_CAST_SQLITE, + oracle: TYPE_CAST_ORACLE, + oracleenhanced: TYPE_CAST_ORACLE }.freeze attr_reader :datatable, :index, :options @@ -65,7 +70,7 @@ def formatted_value private def type_cast - @type_cast ||= (DB_ADAPTER_TYPE_CAST[AjaxDatatablesRails.config.db_adapter] || 'VARCHAR') + @type_cast ||= DB_ADAPTER_TYPE_CAST.fetch(AjaxDatatablesRails.config.db_adapter, TYPE_CAST_DEFAULT) end def casted_column diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 22204925..2440ed66 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -6,7 +6,9 @@ class Column module Search SMALLEST_PQ_INTEGER = -2147483648 - LARGEST_PQ_INTEGER = 2147483647 + LARGEST_PQ_INTEGER = 2147483647 + NOT_NULL_VALUE = '!NULL' + EMPTY_VALUE = '' def searchable? @view_column.fetch(:searchable, true) @@ -74,7 +76,7 @@ def non_regex_search end def null_value_search - if formatted_value == '!NULL' + if formatted_value == NOT_NULL_VALUE table[field].not_eq(nil) else table[field].eq(nil) @@ -90,7 +92,7 @@ def raw_search(cond) end def empty_search - casted_column.matches('') + casted_column.matches(EMPTY_VALUE) end def is_searchable_integer? diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index da2f74e8..f5ad555a 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -3,8 +3,6 @@ module AjaxDatatablesRails module Datatable - TRUE_VALUE = 'true' - class Datatable attr_reader :datatable, :options diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 41e8b934..0faf63a7 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -4,7 +4,9 @@ module AjaxDatatablesRails module Datatable class SimpleOrder - DIRECTIONS = %w[DESC ASC].freeze + DIRECTION_ASC = 'ASC' + DIRECTION_DESC = 'DESC' + DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC].freeze def initialize(datatable, options = {}) @datatable = datatable @@ -24,7 +26,7 @@ def column end def direction - DIRECTIONS.find { |dir| dir == column_direction } || 'ASC' + DIRECTIONS.find { |dir| dir == column_direction } || DIRECTION_ASC end private diff --git a/lib/ajax-datatables-rails/datatable/simple_search.rb b/lib/ajax-datatables-rails/datatable/simple_search.rb index a2ccd233..70bee016 100644 --- a/lib/ajax-datatables-rails/datatable/simple_search.rb +++ b/lib/ajax-datatables-rails/datatable/simple_search.rb @@ -4,6 +4,8 @@ module AjaxDatatablesRails module Datatable class SimpleSearch + TRUE_VALUE = 'true' + def initialize(options = {}) @options = options end From 79ba03c1893c5c9ba92b4b6db1fc8826e9cf5c61 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 5 May 2018 08:55:35 +0200 Subject: [PATCH 020/290] Remove dependency on view_context module, only inject request params --- README.md | 32 ++++++++++------ lib/ajax-datatables-rails/base.rb | 8 ++-- spec/ajax-datatables-rails/base_spec.rb | 38 ++++++++----------- .../datatable/column_spec.rb | 7 ++-- .../datatable/datatable_spec.rb | 3 +- .../datatable/simple_order_spec.rb | 5 +-- spec/ajax-datatables-rails/extended_spec.rb | 3 +- .../orm/active_record_filter_records_spec.rb | 36 +++++++++--------- .../active_record_paginate_records_spec.rb | 3 +- .../orm/active_record_sort_records_spec.rb | 9 ++--- .../orm/active_record_spec.rb | 3 +- 11 files changed, 69 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 53f5125b..1618ff19 100644 --- a/README.md +++ b/README.md @@ -317,7 +317,7 @@ Set the controller to respond to JSON def index respond_to do |format| format.html - format.json { render json: UserDatatable.new(view_context) } + format.json { render json: UserDatatable.new(params) } end end ``` @@ -386,7 +386,9 @@ Sometimes you'll need to use view helper methods like `link_to`, `mail_to`, To have these methods available to be used, this is the way to go: ```ruby -class MyCustomDatatable < AjaxDatatablesRails::Base +class UserDatatable < AjaxDatatablesRails::Base + extend Forwardable + # either define them one-by-one def_delegator :@view, :check_box_tag def_delegator :@view, :link_to @@ -398,6 +400,11 @@ class MyCustomDatatable < AjaxDatatablesRails::Base # ... other methods (view_columns, get_raw_records...) + def initialize(params, opts = {}) + @view = opts[:view_context] + super + end + # now, you'll have these methods available to be used anywhere def data records.map do |record| @@ -412,6 +419,14 @@ class MyCustomDatatable < AjaxDatatablesRails::Base end end end + +# and in your controller: +def index + respond_to do |format| + format.html + format.json { render json: UserDatatable.new(params, view_context: view_context) } + end +end ``` ### Using view decorators @@ -464,12 +479,7 @@ class UserDecorator < ApplicationDecorator end ``` -**Note :** On the long term it's much more cleaner than using `def_delegator` since decorators are reusable everywhere in your application :) - -So we **strongly recommand you to use Draper decorators.** It will help keeping your DataTables class small and clean and keep focused on what they should do (mostly) : filtering records ;) - -**Note 2 :** The `def_delegator` might disappear in a near future : [#288 [RFC] Remove dependency on view_context](https://github.com/jbox-web/ajax-datatables-rails/issues/288). -You're invited to give your opinion :) +This way you don't need to inject the `view_context` in the Datatable object to access helpers methods. ### Pass options to the datatable class @@ -482,7 +492,7 @@ Example: def index respond_to do |format| format.html - format.json { render json: UserDatatable.new(view_context, user: current_user, from: 1.month.ago) } + format.json { render json: UserDatatable.new(params, user: current_user, from: 1.month.ago) } end end @@ -728,7 +738,7 @@ then in your controllers : end def datatable - render json: PostDatatable.new(view_context) + render json: PostDatatable.new(params) end # UsersController @@ -736,7 +746,7 @@ then in your controllers : end def datatable - render json: UserDatatable.new(view_context) + render json: UserDatatable.new(params) end ``` diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 71cb674a..f6083478 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -2,15 +2,13 @@ module AjaxDatatablesRails class Base - extend Forwardable - attr_reader :view, :options - def_delegator :@view, :params + attr_reader :params, :options GLOBAL_SEARCH_DELIMITER = ' ' - def initialize(view, options = {}) - @view = view + def initialize(params, options = {}) + @params = params @options = options load_orm_extension end diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 55020345..db7e6b15 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -3,30 +3,26 @@ describe AjaxDatatablesRails::Base do describe 'an instance' do - let(:view) { double('view', params: sample_params) } - - it 'requires a view_context' do + it 'requires a hash of params' do expect { described_class.new }.to raise_error ArgumentError end it 'accepts an options hash' do - datatable = described_class.new(view, foo: 'bar') + datatable = described_class.new(sample_params, foo: 'bar') expect(datatable.options).to eq(foo: 'bar') end end context 'Public API' do - let(:view) { double('view', params: sample_params) } - describe '#view_columns' do it 'raises an error if not defined by the user' do - datatable = described_class.new(view) + datatable = described_class.new(sample_params) expect { datatable.view_columns }.to raise_error NotImplementedError end context 'child class implements view_columns' do it 'expects a hash based defining columns' do - datatable = ComplexDatatable.new(view) + datatable = ComplexDatatable.new(sample_params) expect(datatable.view_columns).to be_a(Hash) end end @@ -34,19 +30,19 @@ describe '#get_raw_records' do it 'raises an error if not defined by the user' do - datatable = described_class.new(view) + datatable = described_class.new(sample_params) expect { datatable.get_raw_records }.to raise_error NotImplementedError end end describe '#data' do it 'raises an error if not defined by the user' do - datatable = described_class.new(view) + datatable = described_class.new(sample_params) expect { datatable.data }.to raise_error NotImplementedError end context 'when data is defined as a hash' do - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } it 'should return an array of hashes' do create_list(:user, 5) @@ -66,7 +62,7 @@ end context 'when data is defined as a array' do - let(:datatable) { ComplexDatatableArray.new(view) } + let(:datatable) { ComplexDatatableArray.new(sample_params) } it 'should return an array of arrays' do create_list(:user, 5) @@ -87,7 +83,7 @@ end describe '#as_json' do - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } it 'should return a hash' do create_list(:user, 5) @@ -116,8 +112,7 @@ context 'Private API' do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } before(:each) do allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:orm) { nil } @@ -150,34 +145,31 @@ describe 'helper methods' do describe '#offset' do it 'defaults to 0' do - default_view = double('view', params: {}) - datatable = described_class.new(default_view) + datatable = described_class.new({}) expect(datatable.datatable.send(:offset)).to eq(0) end it 'matches the value on view params[:start]' do - paginated_view = double('view', params: { start: '11' }) - datatable = described_class.new(paginated_view) + datatable = described_class.new({ start: '11' }) expect(datatable.datatable.send(:offset)).to eq(11) end end describe '#page' do it 'calculates page number from params[:start] and #per_page' do - paginated_view = double('view', params: { start: '11' }) - datatable = described_class.new(paginated_view) + datatable = described_class.new({ start: '11' }) expect(datatable.datatable.send(:page)).to eq(2) end end describe '#per_page' do it 'defaults to 10' do - datatable = described_class.new(view) + datatable = described_class.new(sample_params) expect(datatable.datatable.send(:per_page)).to eq(10) end it 'matches the value on view params[:length]' do - other_view = double('view', params: { length: 20 }) + other_view = { length: 20 } datatable = described_class.new(other_view) expect(datatable.datatable.send(:per_page)).to eq(20) end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index e0be5231..fcbdf660 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::Datatable::Column do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } describe 'username column' do @@ -129,7 +128,7 @@ end describe '#formatter' do - let(:datatable) { DatatableWithFormater.new(view) } + let(:datatable) { DatatableWithFormater.new(sample_params) } let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } } it 'should be a proc' do @@ -138,7 +137,7 @@ end describe '#filter' do - let(:datatable) { DatatableCondProc.new(view) } + let(:datatable) { DatatableCondProc.new(sample_params) } let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } } it 'should be a proc' do diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index de530e5d..aa8a5185 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::Datatable::Datatable do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view).datatable } + let(:datatable) { ComplexDatatable.new(sample_params).datatable } let(:order_option) { {'0'=>{'column'=>'0', 'dir'=>'asc'}, '1'=>{'column'=>'1', 'dir'=>'desc'}} } describe 'order methods' do diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 9c851eb0..7dfb5c2d 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::Datatable::SimpleOrder do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view).datatable } + let(:datatable) { ComplexDatatable.new(sample_params).datatable } let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'column' => '1', 'dir' => 'desc'}) } let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) } @@ -26,7 +25,7 @@ end describe 'using column option' do - let(:sorted_datatable) { DatatableOrderNullsLast.new(view).datatable } + let(:sorted_datatable) { DatatableOrderNullsLast.new(sample_params).datatable } let(:nulls_last_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(sorted_datatable, options) } it 'sql query' do diff --git a/spec/ajax-datatables-rails/extended_spec.rb b/spec/ajax-datatables-rails/extended_spec.rb index de023fc1..c5d35284 100644 --- a/spec/ajax-datatables-rails/extended_spec.rb +++ b/spec/ajax-datatables-rails/extended_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::Base do describe 'it can transform search value before asking the database' do - let(:view) { double('view', params: sample_params) } - let(:datatable) { DatatableWithFormater.new(view) } + let(:datatable) { DatatableWithFormater.new(sample_params) } before(:each) do create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'DOE') diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index ed8cad48..971403cd 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } let(:records) { User.all } describe '#filter_records' do @@ -184,8 +183,7 @@ end describe '#type_cast helper method' do - let(:view) { double('view', params: sample_params) } - let(:column) { ComplexDatatable.new(view).datatable.columns.first } + let(:column) { ComplexDatatable.new(sample_params).datatable.columns.first } it 'returns VARCHAR if :db_adapter is :pg' do allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :pg } @@ -235,7 +233,7 @@ describe 'filter conditions' do describe 'it can filter records with condition :date_range' do - let(:datatable) { DatatableCondDate.new(view) } + let(:datatable) { DatatableCondDate.new(sample_params) } before(:each) do create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000') @@ -316,7 +314,7 @@ end describe 'it can filter records with condition :start_with' do - let(:datatable) { DatatableCondStartWith.new(view) } + let(:datatable) { DatatableCondStartWith.new(sample_params) } before(:each) do create(:user, first_name: 'John') @@ -332,7 +330,7 @@ end describe 'it can filter records with condition :end_with' do - let(:datatable) { DatatableCondEndWith.new(view) } + let(:datatable) { DatatableCondEndWith.new(sample_params) } before(:each) do create(:user, last_name: 'JOHN') @@ -359,7 +357,7 @@ end describe 'it can filter records with condition :like' do - let(:datatable) { DatatableCondLike.new(view) } + let(:datatable) { DatatableCondLike.new(sample_params) } before(:each) do create(:user, email: 'john@foo.com') @@ -375,7 +373,7 @@ end describe 'it can filter records with condition :string_eq' do - let(:datatable) { DatatableCondStringEq.new(view) } + let(:datatable) { DatatableCondStringEq.new(sample_params) } before(:each) do create(:user, email: 'john@foo.com') @@ -391,7 +389,7 @@ end describe 'it can filter records with condition :null_value' do - let(:datatable) { DatatableCondNullValue.new(view) } + let(:datatable) { DatatableCondNullValue.new(sample_params) } before(:each) do create(:user, first_name: 'john', email: 'foo@bar.com') @@ -418,7 +416,7 @@ end describe 'it can filter records with condition :eq' do - let(:datatable) { DatatableCondEq.new(view) } + let(:datatable) { DatatableCondEq.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -434,7 +432,7 @@ end describe 'it can filter records with condition :not_eq' do - let(:datatable) { DatatableCondNotEq.new(view) } + let(:datatable) { DatatableCondNotEq.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -450,7 +448,7 @@ end describe 'it can filter records with condition :lt' do - let(:datatable) { DatatableCondLt.new(view) } + let(:datatable) { DatatableCondLt.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -466,7 +464,7 @@ end describe 'it can filter records with condition :gt' do - let(:datatable) { DatatableCondGt.new(view) } + let(:datatable) { DatatableCondGt.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -482,7 +480,7 @@ end describe 'it can filter records with condition :lteq' do - let(:datatable) { DatatableCondLteq.new(view) } + let(:datatable) { DatatableCondLteq.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -496,7 +494,7 @@ end describe 'it can filter records with condition :gteq' do - let(:datatable) { DatatableCondGteq.new(view) } + let(:datatable) { DatatableCondGteq.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -510,7 +508,7 @@ end describe 'it can filter records with condition :in' do - let(:datatable) { DatatableCondIn.new(view) } + let(:datatable) { DatatableCondIn.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -526,7 +524,7 @@ end describe 'it can filter records with condition :in with regex' do - let(:datatable) { DatatableCondInWithRegex.new(view) } + let(:datatable) { DatatableCondInWithRegex.new(sample_params) } before(:each) do create(:user, first_name: 'john', post_id: 1) @@ -543,7 +541,7 @@ end describe 'Integer overflows' do - let(:datatable) { DatatableCondEq.new(view) } + let(:datatable) { DatatableCondEq.new(sample_params) } let(:largest_postgresql_integer_value) { 2147483647 } let(:smallest_postgresql_integer_value) { -2147483648 } diff --git a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb index d373d8fc..d4964178 100644 --- a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } let(:records) { User.all } before(:each) do diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index 128fceb8..765f173d 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -2,9 +2,8 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view) } - let(:nulls_last_datatable) { DatatableOrderNullsLast.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } + let(:nulls_last_datatable) { DatatableOrderNullsLast.new(sample_params) } let(:records) { User.all } before(:each) do @@ -48,7 +47,7 @@ describe '#sort_records with nulls last using global config' do before { AjaxDatatablesRails.config.nulls_last = true } after { AjaxDatatablesRails.config.nulls_last = false } - + it 'can handle multiple sorting columns' do # set to order by Users username in ascending order, and # by Users email in descending order @@ -60,7 +59,7 @@ ) end end - + describe '#sort_records with nulls last using column config' do it 'can handle multiple sorting columns' do # set to order by Users username in ascending order, and diff --git a/spec/ajax-datatables-rails/orm/active_record_spec.rb b/spec/ajax-datatables-rails/orm/active_record_spec.rb index 332a10ce..9c6c8db8 100644 --- a/spec/ajax-datatables-rails/orm/active_record_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_spec.rb @@ -2,8 +2,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do context 'Private API' do - let(:view) { double('view', params: sample_params) } - let(:datatable) { ComplexDatatable.new(view) } + let(:datatable) { ComplexDatatable.new(sample_params) } before(:each) do create(:user, username: 'johndoe', email: 'johndoe@example.com') From 73738487494eae251b92f1758ff815b25f4f717c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 03:27:28 +0200 Subject: [PATCH 021/290] Instantiate Datatable object in AjaxDatatablesRails::Base.initialize --- lib/ajax-datatables-rails/base.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index f6083478..b68c1896 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -3,7 +3,7 @@ module AjaxDatatablesRails class Base - attr_reader :params, :options + attr_reader :params, :options, :datatable GLOBAL_SEARCH_DELIMITER = ' ' @@ -11,10 +11,7 @@ def initialize(params, options = {}) @params = params @options = options load_orm_extension - end - - def datatable - @datatable ||= Datatable::Datatable.new(self) + @datatable = Datatable::Datatable.new(self) end def view_columns From 157cc954c15f0b6cdab6c16e65874bb062da3cc3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 03:45:20 +0200 Subject: [PATCH 022/290] Coding style --- .rubocop.yml | 1 + ajax-datatables-rails.gemspec | 2 +- lib/ajax-datatables-rails/base.rb | 4 ++-- .../datatable/column/search.rb | 23 +++++++++++-------- lib/generators/datatable/config_generator.rb | 8 +++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5786d29b..a124ba93 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: TargetRubyVersion: 2.5 Exclude: + - gemfiles/* - spec/**/*.rb - lib/ajax-datatables-rails.rb - lib/generators/rails/templates/*.rb diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 0d873283..5f992c35 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -$LOAD_PATH.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path('lib', __dir__) require 'ajax-datatables-rails/version' Gem::Specification.new do |s| diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index b68c1896..ceb44cb1 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -32,9 +32,9 @@ def additional_data def as_json(*) { - recordsTotal: records_total_count, + recordsTotal: records_total_count, recordsFiltered: records_filtered_count, - data: sanitize(data) + data: sanitize(data) }.merge(get_additional_data) end diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 2440ed66..ce5c2f5d 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -5,8 +5,8 @@ module Datatable class Column module Search - SMALLEST_PQ_INTEGER = -2147483648 - LARGEST_PQ_INTEGER = 2147483647 + SMALLEST_PQ_INTEGER = -2_147_483_648 + LARGEST_PQ_INTEGER = 2_147_483_647 NOT_NULL_VALUE = '!NULL' EMPTY_VALUE = '' @@ -54,12 +54,13 @@ def regex_search end end + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity def non_regex_search case cond when Proc filter when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in - is_searchable_integer? ? raw_search(cond) : empty_search + searchable_integer? ? raw_search(cond) : empty_search when :null_value null_value_search when :start_with @@ -74,6 +75,7 @@ def non_regex_search date_range_search end end + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity def null_value_search if formatted_value == NOT_NULL_VALUE @@ -95,21 +97,24 @@ def empty_search casted_column.matches(EMPTY_VALUE) end - def is_searchable_integer? + def searchable_integer? if formatted_value.is_a?(Array) - valids = formatted_value.map { |v| is_integer?(v) && !is_out_of_range?(v) } + valids = formatted_value.map { |v| integer?(v) && !out_of_range?(v) } !valids.include?(false) else - is_integer?(formatted_value) && !is_out_of_range?(formatted_value) + integer?(formatted_value) && !out_of_range?(formatted_value) end end - def is_out_of_range?(search_value) + def out_of_range?(search_value) Integer(search_value) > LARGEST_PQ_INTEGER || Integer(search_value) < SMALLEST_PQ_INTEGER end - def is_integer?(string) - true if Integer(string) rescue false + def integer?(string) + Integer(string) + true + rescue ArgumentError + false end end diff --git a/lib/generators/datatable/config_generator.rb b/lib/generators/datatable/config_generator.rb index 2df3f2d8..33558cb1 100644 --- a/lib/generators/datatable/config_generator.rb +++ b/lib/generators/datatable/config_generator.rb @@ -6,10 +6,10 @@ module Datatable module Generators class ConfigGenerator < ::Rails::Generators::Base source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates')) - desc < Date: Tue, 5 Jun 2018 04:00:30 +0200 Subject: [PATCH 023/290] Do some micro optimizations, coding style --- .../datatable/column/date_filter.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index 3d6f8223..8a4c4dde 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -5,6 +5,8 @@ module Datatable class Column module DateFilter + RANGE_DELIMITER = '-' + class DateRange attr_reader :begin, :end @@ -20,11 +22,7 @@ def exclude_end? # Add delimiter option to handle range search def delimiter - @view_column[:delimiter] || '-' - end - - def empty_range_search? - (formatted_value == delimiter) || (range_start.blank? && range_end.blank?) + @delimiter ||= @view_column.fetch(:delimiter, RANGE_DELIMITER) end # A range value is in form '' @@ -39,6 +37,10 @@ def range_end @range_end ||= formatted_value.split(delimiter)[1] end + def empty_range_search? + (formatted_value == delimiter) || (range_start.blank? && range_end.blank?) + end + # Do a range search def date_range_search return nil if empty_range_search? @@ -56,11 +58,7 @@ def range_end_casted end def parse_date(date) - if Time.zone - Time.zone.parse(date) - else - Time.parse(date) - end + Time.zone ? Time.zone.parse(date) : Time.parse(date) end end From 8c34d61ceca787ccef103a2aa0002619be7bccba Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 04:13:14 +0200 Subject: [PATCH 024/290] Wrap ORM tests in context --- spec/ajax-datatables-rails/base_spec.rb | 40 +++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index db7e6b15..6dbd950b 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -112,33 +112,35 @@ context 'Private API' do - let(:datatable) { ComplexDatatable.new(sample_params) } + context 'when orm is not implemented' do + before do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:orm) { nil } + end - before(:each) do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:orm) { nil } - end + let(:datatable) { ComplexDatatable.new(sample_params) } - describe '#fetch_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:fetch_records) }.to raise_error NoMethodError + describe '#fetch_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.send(:fetch_records) }.to raise_error NoMethodError + end end - end - describe '#filter_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:filter_records) }.to raise_error NoMethodError + describe '#filter_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.send(:filter_records) }.to raise_error NoMethodError + end end - end - describe '#sort_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:sort_records) }.to raise_error NoMethodError + describe '#sort_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.send(:sort_records) }.to raise_error NoMethodError + end end - end - describe '#paginate_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:paginate_records) }.to raise_error NoMethodError + describe '#paginate_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.send(:paginate_records) }.to raise_error NoMethodError + end end end From b1603fc2142c311f16efa4ea049471b6a508ae2b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 04:17:55 +0200 Subject: [PATCH 025/290] Update CHANGELOG [ci skip] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91d2fcec..4ecd4899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.5.0 (to come) + +* Breaking change: Remove dependency on view_context [Issue #288](https://github.com/jbox-web/ajax-datatables-rails/issues/288) + ## 0.4.3 (2018-06-05) * Add: Add `:string_eq` condition on columns filter [Issue #291](https://github.com/jbox-web/ajax-datatables-rails/issues/291) From d2faa45188b0e7500f5028a905083dffab8043e1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 04:30:39 +0200 Subject: [PATCH 026/290] Minor change [ci skip] --- spec/ajax-datatables-rails/base_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 6dbd950b..b0bdadea 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -111,7 +111,6 @@ context 'Private API' do - context 'when orm is not implemented' do before do allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:orm) { nil } From 77d5185d70888f0ef7fe7812802a2af17df5eae8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 04:46:36 +0200 Subject: [PATCH 027/290] Don't use send to test public methods, move tests --- spec/ajax-datatables-rails/base_spec.rb | 8 +- .../datatable/column_spec.rb | 49 +++++++++++ .../orm/active_record_filter_records_spec.rb | 83 ++++--------------- .../orm/active_record_spec.rb | 4 +- 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index b0bdadea..fb763c31 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -120,25 +120,25 @@ describe '#fetch_records' do it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:fetch_records) }.to raise_error NoMethodError + expect { datatable.fetch_records }.to raise_error NoMethodError end end describe '#filter_records' do it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:filter_records) }.to raise_error NoMethodError + expect { datatable.filter_records }.to raise_error NoMethodError end end describe '#sort_records' do it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:sort_records) }.to raise_error NoMethodError + expect { datatable.sort_records }.to raise_error NoMethodError end end describe '#paginate_records' do it 'raises an error if it does not include an ORM module' do - expect { datatable.send(:paginate_records) }.to raise_error NoMethodError + expect { datatable.paginate_records }.to raise_error NoMethodError end end end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index fcbdf660..9687046e 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -148,4 +148,53 @@ column.filter end end + + describe '#type_cast' do + let(:column) { datatable.datatable.columns.first } + + it 'returns VARCHAR if :db_adapter is :pg' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :pg } + expect(column.send(:type_cast)).to eq('VARCHAR') + end + + it 'returns VARCHAR if :db_adapter is :postgre' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgre } + expect(column.send(:type_cast)).to eq('VARCHAR') + end + + it 'returns VARCHAR if :db_adapter is :postgresql' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgresql } + expect(column.send(:type_cast)).to eq('VARCHAR') + end + + it 'returns VARCHAR if :db_adapter is :oracle' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracle } + expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') + end + + it 'returns VARCHAR if :db_adapter is :oracleenhanced' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracleenhanced } + expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') + end + + it 'returns CHAR if :db_adapter is :mysql2' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql2 } + expect(column.send(:type_cast)).to eq('CHAR') + end + + it 'returns CHAR if :db_adapter is :mysql' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql } + expect(column.send(:type_cast)).to eq('CHAR') + end + + it 'returns TEXT if :db_adapter is :sqlite' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite } + expect(column.send(:type_cast)).to eq('TEXT') + end + + it 'returns TEXT if :db_adapter is :sqlite3' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite3 } + expect(column.send(:type_cast)).to eq('TEXT') + end + end end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 971403cd..0afa5557 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -7,19 +7,19 @@ describe '#filter_records' do it 'requires a records collection as argument' do - expect { datatable.send(:filter_records) }.to raise_error(ArgumentError) + expect { datatable.filter_records() }.to raise_error(ArgumentError) end it 'performs a simple search first' do datatable.params[:search] = { value: 'msmith' } expect(datatable).to receive(:build_conditions_for_datatable) - datatable.send(:filter_records, records) + datatable.filter_records(records) end it 'performs a composite search second' do datatable.params[:search] = { value: '' } expect(datatable).to receive(:build_conditions_for_selected_columns) - datatable.send(:filter_records, records) + datatable.filter_records(records) end end @@ -31,14 +31,14 @@ it 'returns an Arel object' do datatable.params[:search] = { value: 'msmith' } - result = datatable.send(:build_conditions_for_datatable) + result = datatable.build_conditions_for_datatable expect(result).to be_a(Arel::Nodes::Grouping) end context 'no search query' do it 'returns empty query' do datatable.params[:search] = { value: '' } - expect(datatable.send(:build_conditions_for_datatable)).to be_blank + expect(datatable.build_conditions_for_datatable).to be_blank end end @@ -53,11 +53,11 @@ end it 'returns empty query result' do - expect(datatable.send(:build_conditions_for_datatable)).to be_blank + expect(datatable.build_conditions_for_datatable).to be_blank end it 'returns filtered results' do - query = datatable.send(:build_conditions_for_datatable) + query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) expect(results).to eq ['johndoe', 'msmith'] end @@ -69,11 +69,11 @@ end it 'returns empty query result' do - expect(datatable.send(:build_conditions_for_datatable)).to be_blank + expect(datatable.build_conditions_for_datatable).to be_blank end it 'returns filtered results' do - query = datatable.send(:build_conditions_for_datatable) + query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) expect(results).to eq ['johndoe', 'msmith'] end @@ -87,7 +87,7 @@ end it 'returns a filtering query' do - query = datatable.send(:build_conditions_for_datatable) + query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) expect(results).to include('johndoe') expect(results).not_to include('msmith') @@ -100,7 +100,7 @@ end it 'returns a filtering query' do - query = datatable.send(:build_conditions_for_datatable) + query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) expect(results).to eq ['johndoe'] expect(results).not_to include('msmith') @@ -122,14 +122,14 @@ end it 'returns an Arel object' do - result = datatable.send(:build_conditions_for_selected_columns) + result = datatable.build_conditions_for_selected_columns expect(result).to be_a(Arel::Nodes::And) end if AjaxDatatablesRails.config.db_adapter == :postgresql context 'when db_adapter is postgresql' do it 'can call #to_sql on returned object' do - result = datatable.send(:build_conditions_for_selected_columns) + result = datatable.build_conditions_for_selected_columns expect(result).to respond_to(:to_sql) expect(result.to_sql).to eq( "CAST(\"users\".\"username\" AS VARCHAR) ILIKE '%doe%' AND CAST(\"users\".\"email\" AS VARCHAR) ILIKE '%example%'" @@ -141,7 +141,7 @@ if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] context 'when db_adapter is oracle' do it 'can call #to_sql on returned object' do - result = datatable.send(:build_conditions_for_selected_columns) + result = datatable.build_conditions_for_selected_columns expect(result).to respond_to(:to_sql) expect(result.to_sql).to eq( "CAST(\"USERS\".\"USERNAME\" AS VARCHAR2(4000)) LIKE '%doe%' AND CAST(\"USERS\".\"EMAIL\" AS VARCHAR2(4000)) LIKE '%example%'" @@ -153,7 +153,7 @@ if AjaxDatatablesRails.config.db_adapter.in? %i[mysql2 sqlite3] context 'when db_adapter is mysql2' do it 'can call #to_sql on returned object' do - result = datatable.send(:build_conditions_for_selected_columns) + result = datatable.build_conditions_for_selected_columns expect(result).to respond_to(:to_sql) expect(result.to_sql).to eq( "CAST(`users`.`username` AS CHAR) LIKE '%doe%' AND CAST(`users`.`email` AS CHAR) LIKE '%example%'" @@ -165,7 +165,7 @@ it 'calls #build_conditions_for_selected_columns' do expect(datatable).to receive(:build_conditions_for_selected_columns) - datatable.send(:build_conditions) + datatable.build_conditions end context 'with search values in columns' do @@ -174,7 +174,7 @@ end it 'returns a filtered set of records' do - query = datatable.send(:build_conditions_for_selected_columns) + query = datatable.build_conditions_for_selected_columns results = records.where(query).map(&:username) expect(results).to include('johndoe') expect(results).not_to include('msmith') @@ -182,55 +182,6 @@ end end - describe '#type_cast helper method' do - let(:column) { ComplexDatatable.new(sample_params).datatable.columns.first } - - it 'returns VARCHAR if :db_adapter is :pg' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :pg } - expect(column.send(:type_cast)).to eq('VARCHAR') - end - - it 'returns VARCHAR if :db_adapter is :postgre' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgre } - expect(column.send(:type_cast)).to eq('VARCHAR') - end - - it 'returns VARCHAR if :db_adapter is :postgresql' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgresql } - expect(column.send(:type_cast)).to eq('VARCHAR') - end - - it 'returns VARCHAR if :db_adapter is :oracle' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracle } - expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') - end - - it 'returns VARCHAR if :db_adapter is :oracleenhanced' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracleenhanced } - expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') - end - - it 'returns CHAR if :db_adapter is :mysql2' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql2 } - expect(column.send(:type_cast)).to eq('CHAR') - end - - it 'returns CHAR if :db_adapter is :mysql' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql } - expect(column.send(:type_cast)).to eq('CHAR') - end - - it 'returns TEXT if :db_adapter is :sqlite' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite } - expect(column.send(:type_cast)).to eq('TEXT') - end - - it 'returns TEXT if :db_adapter is :sqlite3' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite3 } - expect(column.send(:type_cast)).to eq('TEXT') - end - end - describe 'filter conditions' do describe 'it can filter records with condition :date_range' do let(:datatable) { DatatableCondDate.new(sample_params) } diff --git a/spec/ajax-datatables-rails/orm/active_record_spec.rb b/spec/ajax-datatables-rails/orm/active_record_spec.rb index 9c6c8db8..89792adf 100644 --- a/spec/ajax-datatables-rails/orm/active_record_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_spec.rb @@ -12,12 +12,12 @@ describe '#fetch_records' do it 'calls #get_raw_records' do expect(datatable).to receive(:get_raw_records) { User.all } - datatable.send(:fetch_records) + datatable.fetch_records end it 'returns a collection of records' do expect(datatable).to receive(:get_raw_records) { User.all } - expect(datatable.send(:fetch_records)).to be_a(ActiveRecord::Relation) + expect(datatable.fetch_records).to be_a(ActiveRecord::Relation) end end end From 719d6231e1612b995bd93cb773f4841d8e9fc7c0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Jun 2018 02:22:34 +0200 Subject: [PATCH 028/290] Add AjaxDatatablesRails::ActiveRecord class --- CHANGELOG.md | 1 + README.md | 13 ++--- lib/ajax-datatables-rails/active_record.rb | 7 +++ lib/ajax-datatables-rails/base.rb | 15 +---- lib/ajax-datatables-rails/config.rb | 1 - lib/ajax_datatables_rails.rb | 1 + .../templates/ajax_datatables_rails_config.rb | 3 - lib/generators/rails/templates/datatable.rb | 2 +- spec/ajax-datatables-rails/base_spec.rb | 57 +++++++++++++++++-- .../configuration_spec.rb | 9 --- spec/spec_helper.rb | 2 - spec/support/test_helpers.rb | 2 +- 12 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 lib/ajax-datatables-rails/active_record.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ecd4899..5947382b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.5.0 (to come) * Breaking change: Remove dependency on view_context [Issue #288](https://github.com/jbox-web/ajax-datatables-rails/issues/288) +* Breaking change: Replace `config.orm = :active_record` by a class : `AjaxDatatablesRails::ActiveRecord` ## 0.4.3 (2018-06-05) diff --git a/README.md b/README.md index 1618ff19..be80fecf 100644 --- a/README.md +++ b/README.md @@ -96,16 +96,11 @@ AjaxDatatablesRails.configure do |config| # Or you can use your rails environment adapter if you want a generic dev and production # config.db_adapter = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym - - # available options for orm are: :active_record, :mongoid - # config.orm = :active_record end ``` Uncomment the `config.db_adapter` line and set the corresponding value to your database and gem. This is all you need. -Uncomment the `config.orm` line to set `active_record or mongoid` if included in your project. It defaults to `active_record`. - #### Note Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for performing database queries. @@ -386,7 +381,7 @@ Sometimes you'll need to use view helper methods like `link_to`, `mail_to`, To have these methods available to be used, this is the way to go: ```ruby -class UserDatatable < AjaxDatatablesRails::Base +class UserDatatable < AjaxDatatablesRails::ActiveRecord extend Forwardable # either define them one-by-one @@ -483,7 +478,7 @@ This way you don't need to inject the `view_context` in the Datatable object to ### Pass options to the datatable class -An `AjaxDatatablesRails::Base` inherited class can accept an options hash at initialization. This provides room for flexibility when required. +An `AjaxDatatablesRails::ActiveRecord` inherited class can accept an options hash at initialization. This provides room for flexibility when required. Example: @@ -497,7 +492,7 @@ def index end # The datatable class -class UnrespondedMessagesDatatable < AjaxDatatablesRails::Base +class UnrespondedMessagesDatatable < AjaxDatatablesRails::ActiveRecord # ... other methods (view_columns, data...) @@ -648,7 +643,7 @@ To enable the date range search, for example `created_at` : ### Generator Syntax -Also, a class that inherits from `AjaxDatatablesRails::Base` is not tied to an +Also, a class that inherits from `AjaxDatatablesRails::ActiveRecord` is not tied to an existing model, module, constant or any type of class in your Rails app. You can pass a name to your datatable class like this: diff --git a/lib/ajax-datatables-rails/active_record.rb b/lib/ajax-datatables-rails/active_record.rb new file mode 100644 index 00000000..2f062e07 --- /dev/null +++ b/lib/ajax-datatables-rails/active_record.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + class ActiveRecord < AjaxDatatablesRails::Base + include AjaxDatatablesRails::ORM::ActiveRecord + end +end diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index ceb44cb1..0b45e7a8 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -8,9 +8,8 @@ class Base GLOBAL_SEARCH_DELIMITER = ' ' def initialize(params, options = {}) - @params = params - @options = options - load_orm_extension + @params = params + @options = options @datatable = Datatable::Datatable.new(self) end @@ -108,16 +107,6 @@ def records_filtered_count filter_records(fetch_records).count(:all) end - # Private helper methods - def load_orm_extension - case AjaxDatatablesRails.config.orm - when :active_record - extend ORM::ActiveRecord - when :mongoid - nil - end - end - def global_search_delimiter GLOBAL_SEARCH_DELIMITER end diff --git a/lib/ajax-datatables-rails/config.rb b/lib/ajax-datatables-rails/config.rb index f481809e..a95532e1 100644 --- a/lib/ajax-datatables-rails/config.rb +++ b/lib/ajax-datatables-rails/config.rb @@ -22,7 +22,6 @@ def self.config class Configuration include ActiveSupport::Configurable - config_accessor(:orm) { :active_record } config_accessor(:db_adapter) { :postgresql } config_accessor(:nulls_last) { false } end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb index 5a6cb459..6c8edc6b 100644 --- a/lib/ajax_datatables_rails.rb +++ b/lib/ajax_datatables_rails.rb @@ -12,4 +12,5 @@ module AjaxDatatablesRails require 'ajax-datatables-rails/datatable/column/date_filter' require 'ajax-datatables-rails/datatable/column' require 'ajax-datatables-rails/orm/active_record' + require 'ajax-datatables-rails/active_record' end diff --git a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb index 321f7d6b..aa2544fd 100644 --- a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +++ b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb @@ -6,7 +6,4 @@ # Or you can use your rails environment adapter if you want a generic dev and production # config.db_adapter = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym - - # available options for orm are: :active_record, :mongoid - # config.orm = :active_record end diff --git a/lib/generators/rails/templates/datatable.rb b/lib/generators/rails/templates/datatable.rb index dfa1ead6..a6b0c922 100644 --- a/lib/generators/rails/templates/datatable.rb +++ b/lib/generators/rails/templates/datatable.rb @@ -1,4 +1,4 @@ -class <%= datatable_name %> < AjaxDatatablesRails::Base +class <%= datatable_name %> < AjaxDatatablesRails::ActiveRecord def view_columns # Declare strings in this format: ModelName.column_name diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index fb763c31..e987cb12 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -107,16 +107,63 @@ end end end + + describe '#filter_records' do + let(:records) { User.all } + + let(:datatable) do + datatable = Class.new(ComplexDatatable) do + def filter_records(records) + raise NotImplementedError + end + end + datatable.new(sample_params) + end + + it 'should allow method override' do + expect { datatable.filter_records(records) }.to raise_error(NotImplementedError) + end + end + + describe '#sort_records' do + let(:records) { User.all } + + let(:datatable) do + datatable = Class.new(ComplexDatatable) do + def sort_records(records) + raise NotImplementedError + end + end + datatable.new(sample_params) + end + + it 'should allow method override' do + expect { datatable.sort_records(records) }.to raise_error(NotImplementedError) + end + end + + describe '#paginate_records' do + let(:records) { User.all } + + let(:datatable) do + datatable = Class.new(ComplexDatatable) do + def paginate_records(records) + raise NotImplementedError + end + end + datatable.new(sample_params) + end + + it 'should allow method override' do + expect { datatable.paginate_records(records) }.to raise_error(NotImplementedError) + end + end end context 'Private API' do context 'when orm is not implemented' do - before do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:orm) { nil } - end - - let(:datatable) { ComplexDatatable.new(sample_params) } + let(:datatable) { AjaxDatatablesRails::Base.new(sample_params) } describe '#fetch_records' do it 'raises an error if it does not include an ORM module' do diff --git a/spec/ajax-datatables-rails/configuration_spec.rb b/spec/ajax-datatables-rails/configuration_spec.rb index 0e11d68b..df547c95 100644 --- a/spec/ajax-datatables-rails/configuration_spec.rb +++ b/spec/ajax-datatables-rails/configuration_spec.rb @@ -20,10 +20,6 @@ let(:config) { AjaxDatatablesRails::Configuration.new } describe 'default config' do - it 'default orm should :active_record' do - expect(config.orm).to eq(:active_record) - end - it 'default db_adapter should :postgresql' do expect(config.db_adapter).to eq(:postgresql) end @@ -34,10 +30,5 @@ config.db_adapter = :mysql expect(config.db_adapter).to eq(:mysql) end - - it 'accepts a custom orm value' do - config.orm = :mongoid - expect(config.orm).to eq(:mongoid) - end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aafab47d..d8409949 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,7 +24,6 @@ config.after(:each) do AjaxDatatablesRails.configure do |c| c.db_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym - c.orm = :active_record end end @@ -73,7 +72,6 @@ AjaxDatatablesRails.configure do |c| c.db_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym - c.orm = :active_record end load File.dirname(__FILE__) + '/support/schema.rb' diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index ffe760e8..2eeed31b 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -53,7 +53,7 @@ def sample_params end # rubocop:enable Metrics/MethodLength -class ComplexDatatable < AjaxDatatablesRails::Base +class ComplexDatatable < AjaxDatatablesRails::ActiveRecord def view_columns @view_columns ||= { username: { source: 'User.username' }, From faa277935875da5121de1ae44ccfe4cc799dd741 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 17:40:26 +0200 Subject: [PATCH 029/290] Update README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index be80fecf..ebd9e9ee 100644 --- a/README.md +++ b/README.md @@ -665,6 +665,22 @@ database. ## Pro Tips +### Create a master parent class + +In the same spirit of Rails `ApplicationController` and `ApplicationRecord`, you can create an `ApplicationDatatable` class (in `app/datatables/application_datatable.rb`) +that will be inherited from other classes : + +```ruby +class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord + # puts commonly used methods here +end + +class PostDatatable < ApplicationDatatable +end +``` + +This way it will be easier to DRY you datatables. + ### Create indices for Postgresql In order to speed up the `ILIKE` queries that are executed when using the default configuration, you might want to consider adding some indices. From 4d83d01817bb62e7ab1df9478996109112e548d4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 17:40:37 +0200 Subject: [PATCH 030/290] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5947382b..d2b3223f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 0.5.0 (to come) +## 1.0.0 (to come) * Breaking change: Remove dependency on view_context [Issue #288](https://github.com/jbox-web/ajax-datatables-rails/issues/288) * Breaking change: Replace `config.orm = :active_record` by a class : `AjaxDatatablesRails::ActiveRecord` From 850fdaea661b85a26455f6f336db773d13eb0700 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 17:40:45 +0200 Subject: [PATCH 031/290] Bump to version 1.0.0 --- lib/ajax-datatables-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 2f322c78..2e6960f8 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AjaxDatatablesRails - VERSION = '0.5.0' + VERSION = '1.0.0' end From 31cd706b1da068c7937c53d1d4f061b3c93dfbdb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:03:45 +0200 Subject: [PATCH 032/290] Update README --- README.md | 9 ++++++++- doc/migrate.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 doc/migrate.md diff --git a/README.md b/README.md index ebd9e9ee..c5e59c31 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,14 @@ All the datatable customizations (header, tr, td, css classes, width, height, bu jQuery DataTables is a very powerful tool with a lot of customizations available. Take the time to [read the doc](https://datatables.net/reference/option/). -## Warning +## Warnings + +**Breaking changes :** the *v1.0.0* version is a **major break** from *v0.4*. + +* Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228)) +* The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods. + +To mitigate this 2 changes see the [migration doc](/doc/migrate.md). **Breaking changes :** the *v0.4* version is a **major break** from *v0.3*. diff --git a/doc/migrate.md b/doc/migrate.md new file mode 100644 index 00000000..ede44283 --- /dev/null +++ b/doc/migrate.md @@ -0,0 +1,40 @@ +## To migrate from `v0.4.x` to `v1.0.0` + +1) To mitigate the first change (Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord`) + +Create a new `ApplicationDatatable` class and make all your classes inherits from it : + +```ruby +class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord +end + +class PostDatatable < ApplicationDatatable +end +``` + +2) To mitigate the second change (The `view_context` is no longer injected in Datatables) + +Update the `ApplicationDatatable` class : + +```ruby +class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord + extend Forwardable + attr_reader :view + def initialize(params, opts = {}) + @view = opts[:view_context] + super + end +end +``` + +and update your controllers : + +```ruby +respond_to do |format| + format.json { render json: UserDatatable.new(params, view_context: view_context) } +end +``` + +This way, you can still use `def_delegators` in your datatables [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-helpers). + +Note that the recommanded way is to use [Draper gem](https://github.com/drapergem/draper) to separate filtering logic from view/presentation logic [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-decorators). From 013cb1f2d7916aa10c654e85087b74d8e0a7b2d3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:05:33 +0200 Subject: [PATCH 033/290] Allow failures for Oracle adapter --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e095f961..fdba0066 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,4 +38,6 @@ env: matrix: - DB_ADAPTER=postgresql - DB_ADAPTER=mysql2 +matrix: + allow_failures: - DB_ADAPTER=oracle_enhanced From cdb8d672e8a95596062c764b4c7251d4febe6d30 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:07:22 +0200 Subject: [PATCH 034/290] Update README [ci skip] --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5e59c31..ffed4ef7 100644 --- a/README.md +++ b/README.md @@ -41,14 +41,16 @@ jQuery DataTables is a very powerful tool with a lot of customizations available ## Warnings -**Breaking changes :** the *v1.0.0* version is a **major break** from *v0.4*. +**Breaking changes :** + +1) the *v1.0.0* version is a **major break** from *v0.4*. * Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228)) * The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods. To mitigate this 2 changes see the [migration doc](/doc/migrate.md). -**Breaking changes :** the *v0.4* version is a **major break** from *v0.3*. +2) the *v0.4* version is a **major break** from *v0.3*. The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). From 8e694c96dd07588dc6640297a33d0560c8b5f7dc Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:11:17 +0200 Subject: [PATCH 035/290] Fix Travis allow_failures for Oracle, add sqlite adapter --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fdba0066..ae6c6b3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,8 @@ env: matrix: - DB_ADAPTER=postgresql - DB_ADAPTER=mysql2 + - DB_ADAPTER=sqlite3 + - DB_ADAPTER=oracle_enhanced matrix: allow_failures: - - DB_ADAPTER=oracle_enhanced + - env: DB_ADAPTER=oracle_enhanced From bd9e163a25efab0d618626fc973671f88aa3195a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:21:16 +0200 Subject: [PATCH 036/290] Update README [ci skip] --- README.md | 2 +- doc/migrate.md | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffed4ef7..020e6e76 100644 --- a/README.md +++ b/README.md @@ -672,7 +672,7 @@ In the end, it's up to the developer which model(s), scope(s), relationship(s) (or else) to employ inside the datatable class to retrieve records from the database. -## Pro Tips +## ProTipsâ„¢ ### Create a master parent class diff --git a/doc/migrate.md b/doc/migrate.md index ede44283..bad82db0 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -12,6 +12,8 @@ class PostDatatable < ApplicationDatatable end ``` +**Note :** This is now in the [ProTipsâ„¢](https://github.com/jbox-web/ajax-datatables-rails#protips) section of the documentation. + 2) To mitigate the second change (The `view_context` is no longer injected in Datatables) Update the `ApplicationDatatable` class : @@ -30,9 +32,20 @@ end and update your controllers : ```ruby +# before +respond_to do |format| + format.json { render json: UserDatatable.new(view_context) } +end + +# after respond_to do |format| format.json { render json: UserDatatable.new(params, view_context: view_context) } end + +# if you need to inject some options +respond_to do |format| + format.json { render json: UserDatatable.new(params, view_context: view_context, my: 'options') } +end ``` This way, you can still use `def_delegators` in your datatables [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-helpers). From 67d7581c2efc687ab296e4ff5594de9c6d4f006a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:30:09 +0200 Subject: [PATCH 037/290] Update README [ci skip] --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 020e6e76..0a88ecbc 100644 --- a/README.md +++ b/README.md @@ -438,6 +438,9 @@ end If you want to keep things tidy in the data mapping method, you could use [Draper](https://github.com/drapergem/draper) to define column mappings like below. +**Note :** This is the recommanded way as you don't need to inject the `view_context` in the Datatable object to access helpers methods. +It also helps in separating view/presentation logic from filtering logic (the only one that really matters in a datatable class). + Example : ```ruby @@ -483,8 +486,6 @@ class UserDecorator < ApplicationDecorator end ``` -This way you don't need to inject the `view_context` in the Datatable object to access helpers methods. - ### Pass options to the datatable class An `AjaxDatatablesRails::ActiveRecord` inherited class can accept an options hash at initialization. This provides room for flexibility when required. From e0f163ca37d6789765f95e94ce804b9b5ff3d447 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:44:13 +0200 Subject: [PATCH 038/290] Update CHANGELOG [ci skip] --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b3223f..6c19fc0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ # CHANGELOG -## 1.0.0 (to come) +## 1.0.0 (2018-08-28) * Breaking change: Remove dependency on view_context [Issue #288](https://github.com/jbox-web/ajax-datatables-rails/issues/288) -* Breaking change: Replace `config.orm = :active_record` by a class : `AjaxDatatablesRails::ActiveRecord` +* Breaking change: Replace `config.orm = :active_record` by a class : `AjaxDatatablesRails::ActiveRecord` [Fix #228](https://github.com/jbox-web/ajax-datatables-rails/issues/228) + +To mitigate this 2 changes see the [migration doc](/doc/migrate.md). ## 0.4.3 (2018-06-05) From ac9746bd310c96f5c1d938e02c4dfb4b4e9a846d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:50:34 +0200 Subject: [PATCH 039/290] Update README [ci skip] --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0a88ecbc..fcbfdbf2 100644 --- a/README.md +++ b/README.md @@ -807,6 +807,8 @@ Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datat Use [has_scope](https://github.com/plataformatec/has_scope) gem with `ajax-datatables-rails` : [#280](https://github.com/jbox-web/ajax-datatables-rails/issues/280) +Use [Datatable orthogonal data](https://datatables.net/manual/data/orthogonal-data) : see [#269](https://github.com/jbox-web/ajax-datatables-rails/issues/269#issuecomment-387940478) + ## Contributing 1. Fork it From b27df187692961e9fe94b80d457ef5e36b3bd4ee Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 18:57:22 +0200 Subject: [PATCH 040/290] Update README [ci skip] --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index fcbfdbf2..fd9aa435 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,13 @@ To migrate on the v0.4 you'll need to : * update your views to declare your columns bindings ([See here](#5-wire-up-the-javascript)) +## Documentation version + +This documentation is about the `v1.x.x` release (master branch) of this gem. + +You can still have access to the `v0.4.x` documentation on the [v0.4.x branch](https://github.com/jbox-web/ajax-datatables-rails/tree/v0.4.x). + + ## Installation Add these lines to your application's Gemfile: From 66e81baa3ca373248e706cc964f9adcc748e938d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 25 Aug 2018 22:04:43 +0200 Subject: [PATCH 041/290] Update README [ci skip] --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd9aa435..51eb70c6 100644 --- a/README.md +++ b/README.md @@ -451,7 +451,8 @@ It also helps in separating view/presentation logic from filtering logic (the on Example : ```ruby -... +class UserDatatable < AjaxDatatablesRails::ActiveRecord + ... def data records.map do |record| { @@ -464,7 +465,8 @@ Example : } end end -... + ... +end class UserDecorator < ApplicationDecorator delegate :last_name, :bio From fc02268d173aae3b2dddcd35fac28ca591ecccc8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 25 Sep 2018 22:14:10 +0200 Subject: [PATCH 042/290] Add Rudimentary support for Microsoft SQL Server See: https://github.com/jbox-web/ajax-datatables-rails/issues/306 --- lib/ajax-datatables-rails/datatable/column.rb | 12 +++++++----- spec/ajax-datatables-rails/datatable/column_spec.rb | 9 +++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 7a181ac5..10544d01 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -4,10 +4,11 @@ module AjaxDatatablesRails module Datatable class Column - TYPE_CAST_DEFAULT = 'VARCHAR' - TYPE_CAST_MYSQL = 'CHAR' - TYPE_CAST_SQLITE = 'TEXT' - TYPE_CAST_ORACLE = 'VARCHAR2(4000)' + TYPE_CAST_DEFAULT = 'VARCHAR' + TYPE_CAST_MYSQL = 'CHAR' + TYPE_CAST_SQLITE = 'TEXT' + TYPE_CAST_ORACLE = 'VARCHAR2(4000)' + TYPE_CAST_SQLSERVER = 'VARCHAR(4000)' DB_ADAPTER_TYPE_CAST = { mysql: TYPE_CAST_MYSQL, @@ -15,7 +16,8 @@ class Column sqlite: TYPE_CAST_SQLITE, sqlite3: TYPE_CAST_SQLITE, oracle: TYPE_CAST_ORACLE, - oracleenhanced: TYPE_CAST_ORACLE + oracleenhanced: TYPE_CAST_ORACLE, + sqlserver: TYPE_CAST_SQLSERVER, }.freeze attr_reader :datatable, :index, :options diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 9687046e..472bbc52 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -167,12 +167,12 @@ expect(column.send(:type_cast)).to eq('VARCHAR') end - it 'returns VARCHAR if :db_adapter is :oracle' do + it 'returns VARCHAR2(4000) if :db_adapter is :oracle' do allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracle } expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') end - it 'returns VARCHAR if :db_adapter is :oracleenhanced' do + it 'returns VARCHAR2(4000) if :db_adapter is :oracleenhanced' do allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracleenhanced } expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') end @@ -196,5 +196,10 @@ allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite3 } expect(column.send(:type_cast)).to eq('TEXT') end + + it 'returns VARCHAR(4000) if :db_adapter is :sqlserver' do + allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlserver } + expect(column.send(:type_cast)).to eq('VARCHAR(4000)') + end end end From 4ea846069b2839cd9286fa64ac173a61a91ead32 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 27 Sep 2018 01:24:22 +0200 Subject: [PATCH 043/290] Update README [ci skip] --- README.md | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 51eb70c6..1f4907e0 100644 --- a/README.md +++ b/README.md @@ -684,7 +684,7 @@ database. ## ProTipsâ„¢ -### Create a master parent class +### Create a master parent class (Easy) In the same spirit of Rails `ApplicationController` and `ApplicationRecord`, you can create an `ApplicationDatatable` class (in `app/datatables/application_datatable.rb`) that will be inherited from other classes : @@ -700,34 +700,7 @@ end This way it will be easier to DRY you datatables. -### Create indices for Postgresql - -In order to speed up the `ILIKE` queries that are executed when using the default configuration, you might want to consider adding some indices. -For postgresql, you are advised to use the [gin/gist index type](http://www.postgresql.org/docs/current/interactive/pgtrgm.html). -This makes it necessary to enable the postgrsql extension `pg_trgm`. Double check that you have this extension installed before trying to enable it. -A migration for enabling the extension and creating the indices could look like this: - -```ruby -def change - enable_extension :pg_trgm - TEXT_SEARCH_ATTRIBUTES = ['your', 'attributes'] - TABLE = 'your_table' - - TEXT_SEARCH_ATTRIBUTES.each do |attr| - reversible do |dir| - dir.up do - execute "CREATE INDEX #{TABLE}_#{attr}_gin ON #{TABLE} USING gin(#{attr} gin_trgm_ops)" - end - - dir.down do - remove_index TABLE.to_sym, name: "#{TABLE}_#{attr}_gin" - end - end - end -end -``` - -### Speedup JSON rendering +### Speedup JSON rendering (Easy) Install [yajl-ruby](https://github.com/brianmario/yajl-ruby), basically : @@ -743,9 +716,9 @@ $ bundle install That's all :) ([Automatically prefer Yajl or JSON backend over Yaml, if available](https://github.com/rails/rails/commit/63bb955a99eb46e257655c93dd64e86ebbf05651)) -### Use HTTP `POST` method +### Use HTTP `POST` method (Medium) -Use HTTP `POST` method to avoid `414 Request-URI Too Large` error. See : [#278](https://github.com/jbox-web/ajax-datatables-rails/issues/278). +Use HTTP `POST` method to avoid `414 Request-URI Too Large` error. See : [#278](https://github.com/jbox-web/ajax-datatables-rails/issues/278) and [#308](https://github.com/jbox-web/ajax-datatables-rails/issues/308#issuecomment-424897335). You can easily define a route concern in `config/routes.rb` and reuse it when you need it : @@ -808,6 +781,33 @@ $ -> # ...others options, see [here](#5-wire-up-the-javascript) ``` +### Create indices for Postgresql (Expert) + +In order to speed up the `ILIKE` queries that are executed when using the default configuration, you might want to consider adding some indices. +For postgresql, you are advised to use the [gin/gist index type](http://www.postgresql.org/docs/current/interactive/pgtrgm.html). +This makes it necessary to enable the postgrsql extension `pg_trgm`. Double check that you have this extension installed before trying to enable it. +A migration for enabling the extension and creating the indices could look like this: + +```ruby +def change + enable_extension :pg_trgm + TEXT_SEARCH_ATTRIBUTES = ['your', 'attributes'] + TABLE = 'your_table' + + TEXT_SEARCH_ATTRIBUTES.each do |attr| + reversible do |dir| + dir.up do + execute "CREATE INDEX #{TABLE}_#{attr}_gin ON #{TABLE} USING gin(#{attr} gin_trgm_ops)" + end + + dir.down do + remove_index TABLE.to_sym, name: "#{TABLE}_#{attr}_gin" + end + end + end +end +``` + ## Tutorial You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to). Its real world example. From 722b55c18106ee16d88be568da9bb3db871bf254 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 27 Sep 2018 01:49:46 +0200 Subject: [PATCH 044/290] Update README [ci skip] --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 1f4907e0..d80d6141 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,8 @@ Don't forget to make sure the proper route has been added to `config/routes.rb`. [See here](#pass-options-to-the-datatable-class) if you need to inject params in the `UserDatatable`. +**Note :** If you have more than **2** datatables in your application, don't forget to read [this](#use-http-post-method-medium). + ### 5) Wire up the Javascript Finally, the javascript to tie this all together. In the appropriate `coffee` file: @@ -682,6 +684,18 @@ In the end, it's up to the developer which model(s), scope(s), relationship(s) (or else) to employ inside the datatable class to retrieve records from the database. +## Tests + +Datatables can be tested with Capybara provided you don't use Webrick during integration tests. + +Long story short and as a rule of thumb : use the same webserver everywhere (dev, prod, staging, test, etc...). + +If you use Puma (the Rails default webserver), use Puma everywhere, even in CI/test environment. The same goes for Thin. + +You will avoid the usual story : it works in dev but not in test environment... + +If you want to test datatables with a lot of data you might need this kind of tricks : https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara. (thanks CharlieIGG) + ## ProTipsâ„¢ ### Create a master parent class (Easy) From 557b099ad7171d5d5bc8b1ab0ef0a7af956c5938 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 5 Dec 2018 02:40:46 +0100 Subject: [PATCH 045/290] Test with latest Rails and Ruby versions --- .travis.yml | 10 +++++----- Appraisals | 4 ++-- .../{rails_4.2.10.gemfile => rails_4.2.11.gemfile} | 2 +- gemfiles/{rails_5.2.0.gemfile => rails_5.2.2.gemfile} | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) rename gemfiles/{rails_4.2.10.gemfile => rails_4.2.11.gemfile} (93%) rename gemfiles/{rails_5.2.0.gemfile => rails_5.2.2.gemfile} (92%) diff --git a/.travis.yml b/.travis.yml index ae6c6b3b..c748f4ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,14 @@ language: ruby sudo: required cache: bundler rvm: - - 2.3.7 - - 2.4.4 - - 2.5.1 + - 2.5.3 + - 2.4.5 + - 2.3.8 gemfile: - - gemfiles/rails_4.2.10.gemfile + - gemfiles/rails_4.2.11.gemfile - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.6.gemfile - - gemfiles/rails_5.2.0.gemfile + - gemfiles/rails_5.2.2.gemfile after_success: - bundle exec codeclimate-test-reporter services: diff --git a/Appraisals b/Appraisals index 96b05ec4..46c3e860 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,7 @@ # frozen_string_literal: true RAILS_VERSIONS = { - '4.2.10' => { + '4.2.11' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0' }, '5.0.7' => { @@ -12,7 +12,7 @@ RAILS_VERSIONS = { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'ruby-oci8' => '' }, - '5.2.0' => { + '5.2.2' => { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', 'ruby-oci8' => '' } diff --git a/gemfiles/rails_4.2.10.gemfile b/gemfiles/rails_4.2.11.gemfile similarity index 93% rename from gemfiles/rails_4.2.10.gemfile rename to gemfiles/rails_4.2.11.gemfile index e4d87c7b..ea82ac6e 100644 --- a/gemfiles/rails_4.2.10.gemfile +++ b/gemfiles/rails_4.2.11.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "4.2.10" +gem "rails", "4.2.11" gem "mysql2", "0.4.10" gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/gemfiles/rails_5.2.0.gemfile b/gemfiles/rails_5.2.2.gemfile similarity index 92% rename from gemfiles/rails_5.2.0.gemfile rename to gemfiles/rails_5.2.2.gemfile index f3b915c7..ee7a440a 100644 --- a/gemfiles/rails_5.2.0.gemfile +++ b/gemfiles/rails_5.2.2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "5.2.0" +gem "rails", "5.2.2" gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" From 013f85bbd9b3f21ca12cf5d31fb87bb70d94ba85 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 5 Dec 2018 02:42:03 +0100 Subject: [PATCH 046/290] Update README [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d80d6141..cc176bfb 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ It's tested against : -* Rails 4.2.10 / 5.0.7 / 5.1.6 / 5.2.0 -* Ruby 2.3.7 / 2.4.4 / 2.5.1 +* Rails 4.2.11 / 5.0.7 / 5.1.6 / 5.2.2 +* Ruby 2.3.8 / 2.4.5 / 2.5.3 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) From 207c69e4c47cfe06b20f36b521894b7aae8a8a18 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 5 Dec 2018 03:47:19 +0100 Subject: [PATCH 047/290] Add AjaxDatatablesRails::Base#column_id and AjaxDatatablesRails::Base#column_data methods These helper methods help to retrieve: * column id from view_columns hash for the named column * column search value for the named column --- lib/ajax-datatables-rails/base.rb | 9 +++++++++ spec/ajax-datatables-rails/base_spec.rb | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 0b45e7a8..57c2ef69 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -111,6 +111,15 @@ def global_search_delimiter GLOBAL_SEARCH_DELIMITER end + def column_id(name) + view_columns.keys.index(name.to_sym) + end + + def column_data(column) + id = column_id(column) + params.dig('columns', id.to_s, 'search', 'value') + end + def raw_records_error_text <<-ERROR diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index e987cb12..2777ec8d 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -222,6 +222,25 @@ def paginate_records(records) expect(datatable.datatable.send(:per_page)).to eq(20) end end + + describe '#column_id' do + let(:datatable) { ComplexDatatable.new(sample_params) } + + it 'should return column id from view_columns hash' do + expect(datatable.send(:column_id, :username)).to eq(0) + expect(datatable.send(:column_id, 'username')).to eq(0) + end + end + + describe '#column_data' do + let(:datatable) { ComplexDatatable.new(sample_params) } + before { datatable.params[:columns]['0'][:search][:value] = 'doe' } + + it 'should return column data from params' do + expect(datatable.send(:column_data, :username)).to eq('doe') + expect(datatable.send(:column_data, 'username')).to eq('doe') + end + end end end end From 3f2b90b15b4e4f66d0be7730b458c3dfc3ebce02 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 19 Dec 2018 17:45:20 +0100 Subject: [PATCH 048/290] Test with latest Rubygems --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c748f4ae..1a057e7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ -dist: trusty language: ruby -sudo: required cache: bundler +sudo: required rvm: - 2.5.3 - 2.4.5 @@ -25,7 +24,7 @@ addons: - mysql-client-5.6 before_install: - gem update --system - - gem install bundler + - gem install bundler --no-document - sh -c "if [ '$DB_ADAPTER' = 'mysql2' ]; then mysql -e 'create database ajax_datatables_rails;'; fi" - sh -c "if [ '$DB_ADAPTER' = 'postgresql' ]; then psql -c 'create database ajax_datatables_rails;' -U postgres; fi" - sh -c "if [ '$DB_ADAPTER' = 'oracle_enhanced' ]; then ./spec/install_oracle.sh; fi" From 7929b5ba28e5d11da818db9604826800302bcb96 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 22 Dec 2018 00:28:08 +0100 Subject: [PATCH 049/290] Test with Ruby 2.6 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1a057e7b..144dd3cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby cache: bundler sudo: required rvm: + - 2.6.0-rc2 - 2.5.3 - 2.4.5 - 2.3.8 From 0f5b32423da5f2487dda86ee4a334aeb45d2eef9 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 28 Dec 2018 16:54:42 +0100 Subject: [PATCH 050/290] Test with Ruby 2.6 final --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 144dd3cb..73abfc3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: ruby cache: bundler sudo: required rvm: - - 2.6.0-rc2 + - 2.6.0 - 2.5.3 - 2.4.5 - 2.3.8 From 415b69de7c87baa6516eda1331e99c1d1428eedc Mon Sep 17 00:00:00 2001 From: allard Date: Mon, 31 Dec 2018 06:38:12 +1100 Subject: [PATCH 051/290] Fixes errors when options[param] is nil --- lib/ajax-datatables-rails/datatable/datatable.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index f5ad555a..c60f0d45 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -68,6 +68,7 @@ def page end def get_param(param) + return {} if options[param].nil? options[param].to_unsafe_h.with_indifferent_access end From d855ac39920c3c41363a11c0c8f48ac4168b4794 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 4 Jan 2019 01:25:48 +0100 Subject: [PATCH 052/290] Improve lib loading --- ajax-datatables-rails.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 5f992c35..fd3ccd25 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -1,6 +1,7 @@ # frozen_string_literal: true -$LOAD_PATH.push File.expand_path('lib', __dir__) +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.push(lib) unless $LOAD_PATH.include?(lib) require 'ajax-datatables-rails/version' Gem::Specification.new do |s| From 001fd966c2001ab74dc817fdba425cf6f172f6d9 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 8 Jan 2019 01:56:51 +0100 Subject: [PATCH 053/290] Cleanup gemspec --- ajax-datatables-rails.gemspec | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index fd3ccd25..ec16b79b 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -1,8 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.push(lib) unless $LOAD_PATH.include?(lib) -require 'ajax-datatables-rails/version' +require_relative 'lib/ajax-datatables-rails/version' Gem::Specification.new do |s| s.name = 'ajax-datatables-rails' @@ -15,7 +13,9 @@ Gem::Specification.new do |s| s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app" s.license = 'MIT' - s.add_dependency 'railties', '>= 4.2' + s.files = `git ls-files`.split("\n") + + s.add_runtime_dependency 'railties', '>= 4.2' s.add_development_dependency 'rails', '>= 4.2' s.add_development_dependency 'rake' @@ -31,9 +31,4 @@ Gem::Specification.new do |s| s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' s.add_development_dependency 'appraisal' - - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } - s.require_paths = ['lib'] end From 958a8a034e54ed17cadcffa827f05c34780dff36 Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Thu, 17 Jan 2019 14:54:35 -0500 Subject: [PATCH 054/290] Use different SQL syntax for each supported database adapter. This allows indices to give performance improvements. --- .../datatable/simple_order.rb | 19 +++++++--- .../datatable/simple_order_spec.rb | 35 +++++++++++++++---- .../orm/active_record_sort_records_spec.rb | 6 ++-- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 0faf63a7..bbc3f8d5 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -14,11 +14,7 @@ def initialize(datatable, options = {}) end def query(sort_column) - if sort_nulls_last? - "CASE WHEN #{sort_column} IS NULL THEN 1 ELSE 0 END, #{sort_column} #{direction}" - else - "#{sort_column} #{direction}" - end + [sort_column, direction, nulls_last_sql].compact.join(" ") end def column @@ -43,6 +39,19 @@ def sort_nulls_last? column.nulls_last? || AjaxDatatablesRails.config.nulls_last == true end + def nulls_last_sql + return unless sort_nulls_last? + + case AjaxDatatablesRails.config.db_adapter + when -> (a) { a.in?([:pg, :postgresql, :postgres, :oracle]) } + "NULLS LAST" + when -> (a) { a.in?([:mysql, :mysql2, :sqlite, :sqlite3]) } + "IS NULL" + else + raise 'unsupported database adapter' + end + end + end end end diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 7dfb5c2d..e093b89f 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -19,7 +19,7 @@ it 'sql query' do expect(simple_order.query('email')).to eq( - 'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC' + 'email DESC NULLS LAST' ) end end @@ -28,12 +28,35 @@ let(:sorted_datatable) { DatatableOrderNullsLast.new(sample_params).datatable } let(:nulls_last_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(sorted_datatable, options) } - it 'sql query' do - expect(nulls_last_order.query('email')).to eq( - 'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC' - ) + context 'with postgres database adapter' do + before { AjaxDatatablesRails.config.db_adapter = :pg } + + 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 { AjaxDatatablesRails.config.db_adapter = :sqlite } + + it 'sql query' do + expect(nulls_last_order.query('email')).to eq('email DESC IS NULL') + end end + + context 'with mysql database adapter' do + before { AjaxDatatablesRails.config.db_adapter = :mysql } + + it 'sql query' do + expect(nulls_last_order.query('email')).to eq('email DESC IS NULL') + end + end + + # it 'sql query' do + # expect(nulls_last_order.query('email')).to eq( + # 'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC' + # ) + # end end end - end diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index 765f173d..0306896a 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -54,8 +54,7 @@ datatable.params[:order]['0'] = { column: '0', dir: 'asc' } datatable.params[:order]['1'] = { column: '1', dir: 'desc' } expect(datatable.sort_records(records).to_sql).to include( - 'ORDER BY CASE WHEN users.username IS NULL THEN 1 ELSE 0 END, users.username ASC, ' + - 'CASE WHEN users.email IS NULL THEN 1 ELSE 0 END, users.email DESC' + 'ORDER BY users.username ASC NULLS LAST, users.email DESC NULLS LAST' ) end end @@ -67,8 +66,7 @@ nulls_last_datatable.params[:order]['0'] = { column: '0', dir: 'asc' } nulls_last_datatable.params[:order]['1'] = { column: '1', dir: 'desc' } expect(nulls_last_datatable.sort_records(records).to_sql).to include( - 'ORDER BY users.username ASC, ' + - 'CASE WHEN users.email IS NULL THEN 1 ELSE 0 END, users.email DESC' + 'ORDER BY users.username ASC, users.email DESC NULLS LAST' ) end end From 5516b66de465ecfe67a41954e79793de3e742d4b Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Thu, 17 Jan 2019 15:06:18 -0500 Subject: [PATCH 055/290] Remove commented out code --- spec/ajax-datatables-rails/datatable/simple_order_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index e093b89f..929d1845 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -51,12 +51,6 @@ expect(nulls_last_order.query('email')).to eq('email DESC IS NULL') end end - - # it 'sql query' do - # expect(nulls_last_order.query('email')).to eq( - # 'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC' - # ) - # end end end end From 40e3cd14c149c0da11df9163c540107202074252 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Feb 2019 04:21:21 +0100 Subject: [PATCH 056/290] Sort gems in gemspec --- ajax-datatables-rails.gemspec | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index ec16b79b..2805c4a8 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -17,18 +17,18 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'railties', '>= 4.2' - s.add_development_dependency 'rails', '>= 4.2' - s.add_development_dependency 'rake' - s.add_development_dependency 'pg', '< 1.0' - s.add_development_dependency 'mysql2' - s.add_development_dependency 'sqlite3' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' - s.add_development_dependency 'rspec' - s.add_development_dependency 'generator_spec' - s.add_development_dependency 'pry' - s.add_development_dependency 'simplecov' + s.add_development_dependency 'appraisal' s.add_development_dependency 'database_cleaner' s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' - s.add_development_dependency 'appraisal' + s.add_development_dependency 'generator_spec' + s.add_development_dependency 'pg', '< 1.0' + s.add_development_dependency 'pry' + s.add_development_dependency 'mysql2' + s.add_development_dependency 'rails', '>= 4.2' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec' + s.add_development_dependency 'simplecov' + s.add_development_dependency 'sqlite3' end From 0f45b7626c7ae3e4edb85f3367447ba656dcf5a7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Feb 2019 04:21:54 +0100 Subject: [PATCH 057/290] Test with Ruby 2.6.1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 73abfc3a..92eac78b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: ruby cache: bundler sudo: required rvm: - - 2.6.0 + - 2.6.1 - 2.5.3 - 2.4.5 - 2.3.8 From a2ca96d1e8eab584e5e3710b1400e46cba94100a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Feb 2019 04:22:29 +0100 Subject: [PATCH 058/290] Test with Ruby head --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 92eac78b..48d96bec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ rvm: - 2.5.3 - 2.4.5 - 2.3.8 + - ruby-head gemfile: - gemfiles/rails_4.2.11.gemfile - gemfiles/rails_5.0.7.gemfile From a25011ad69981742254f3cac34a38f49e6f6ec6e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 5 Feb 2019 21:15:43 +0100 Subject: [PATCH 059/290] Fix sqlite3 version --- ajax-datatables-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 2805c4a8..bb9108b0 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -30,5 +30,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' - s.add_development_dependency 'sqlite3' + s.add_development_dependency 'sqlite3', '~> 1.3.0' end From c30c34a710f259b7cbf3e64d998274d057a73520 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 9 Feb 2019 16:36:28 +0100 Subject: [PATCH 060/290] Coding style --- .rubocop.yml | 9 ++++++--- Appraisals | 10 +++++----- ajax-datatables-rails.gemspec | 2 +- lib/ajax-datatables-rails/base.rb | 2 +- .../datatable/column/date_filter.rb | 1 + lib/ajax-datatables-rails/datatable/datatable.rb | 1 + lib/ajax-datatables-rails/orm/active_record.rb | 4 ++-- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a124ba93..bed5deaf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,7 +9,7 @@ AllCops: Documentation: Enabled: false -Gemspec/OrderedDependencies: +Layout/AlignHash: Enabled: false Layout/EmptyLines: @@ -45,5 +45,8 @@ Metrics/ClassLength: Naming/AccessorMethodName: Enabled: false -Style/NumericPredicate: - Enabled: false +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma diff --git a/Appraisals b/Appraisals index 46c3e860..a0c456ad 100644 --- a/Appraisals +++ b/Appraisals @@ -2,20 +2,20 @@ RAILS_VERSIONS = { '4.2.11' => { - 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0' + 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0', }, '5.0.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', - 'ruby-oci8' => '' + 'ruby-oci8' => '', }, '5.1.6' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', - 'ruby-oci8' => '' + 'ruby-oci8' => '', }, '5.2.2' => { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', - 'ruby-oci8' => '' - } + 'ruby-oci8' => '', + }, }.freeze RAILS_VERSIONS.each do |version, gems| diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index bb9108b0..a92e39e4 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -23,9 +23,9 @@ Gem::Specification.new do |s| s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' s.add_development_dependency 'generator_spec' + s.add_development_dependency 'mysql2' s.add_development_dependency 'pg', '< 1.0' s.add_development_dependency 'pry' - s.add_development_dependency 'mysql2' s.add_development_dependency 'rails', '>= 4.2' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 57c2ef69..08bf54bb 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -33,7 +33,7 @@ def as_json(*) { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, - data: sanitize(data) + data: sanitize(data), }.merge(get_additional_data) end diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index 8a4c4dde..7fa0b801 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -44,6 +44,7 @@ def empty_range_search? # Do a range search def date_range_search return nil if empty_range_search? + table[field].between(DateRange.new(range_start_casted, range_end_casted)) end diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index c60f0d45..bf5f3118 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -69,6 +69,7 @@ def page def get_param(param) return {} if options[param].nil? + options[param].to_unsafe_h.with_indifferent_access end diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index 9836a5b8..c81b504f 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -12,7 +12,7 @@ def filter_records(records) records.where(build_conditions) end - # rubocop:disable Style/EachWithObject + # rubocop:disable Style/EachWithObject, Style/SafeNavigation def sort_records(records) sort_by = datatable.orders.inject([]) do |queries, order| column = order.column @@ -21,7 +21,7 @@ def sort_records(records) end records.order(Arel.sql(sort_by.join(', '))) end - # rubocop:enable Style/EachWithObject + # rubocop:enable Style/EachWithObject, Style/SafeNavigation def paginate_records(records) records.offset(datatable.offset).limit(datatable.per_page) From 51d344318bbd1e9fa671b017c282046c15920a0b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 9 Feb 2019 16:37:02 +0100 Subject: [PATCH 061/290] Fix tests with Rails 4.2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 48d96bec..a9841fd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ addons: - mysql-client-5.6 before_install: - gem update --system - - gem install bundler --no-document + # - gem install bundler --no-document - sh -c "if [ '$DB_ADAPTER' = 'mysql2' ]; then mysql -e 'create database ajax_datatables_rails;'; fi" - sh -c "if [ '$DB_ADAPTER' = 'postgresql' ]; then psql -c 'create database ajax_datatables_rails;' -U postgres; fi" - sh -c "if [ '$DB_ADAPTER' = 'oracle_enhanced' ]; then ./spec/install_oracle.sh; fi" From bf3519371ce12d7a4fa4f7a5106ecbe8d60174b4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 11 Feb 2019 02:47:31 +0100 Subject: [PATCH 062/290] Update CodeClimate test reporter --- .travis.yml | 8 ++++++-- Gemfile | 5 ----- gemfiles/rails_4.2.11.gemfile | 4 ---- gemfiles/rails_5.0.7.gemfile | 4 ---- gemfiles/rails_5.1.6.gemfile | 4 ---- gemfiles/rails_5.2.2.gemfile | 4 ---- 6 files changed, 6 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9841fd4..8d734cf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ gemfile: - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.6.gemfile - gemfiles/rails_5.2.2.gemfile -after_success: - - bundle exec codeclimate-test-reporter services: - postgresql - mysql @@ -44,3 +42,9 @@ env: matrix: allow_failures: - env: DB_ADAPTER=oracle_enhanced +before_script: + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build +after_script: + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT diff --git a/Gemfile b/Gemfile index 4644180e..7f4f5e95 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,3 @@ source 'https://rubygems.org' gemspec - -# CodeClimate Test Coverage -group :test do - gem 'codeclimate-test-reporter', '~> 1.0.0' -end diff --git a/gemfiles/rails_4.2.11.gemfile b/gemfiles/rails_4.2.11.gemfile index ea82ac6e..467bbf5e 100644 --- a/gemfiles/rails_4.2.11.gemfile +++ b/gemfiles/rails_4.2.11.gemfile @@ -7,8 +7,4 @@ gem "mysql2", "0.4.10" gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" -group :test do - gem "codeclimate-test-reporter", "~> 1.0.0" -end - gemspec path: "../" diff --git a/gemfiles/rails_5.0.7.gemfile b/gemfiles/rails_5.0.7.gemfile index e31d7c24..2f74094c 100644 --- a/gemfiles/rails_5.0.7.gemfile +++ b/gemfiles/rails_5.0.7.gemfile @@ -6,8 +6,4 @@ gem "rails", "5.0.7" gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" -group :test do - gem "codeclimate-test-reporter", "~> 1.0.0" -end - gemspec path: "../" diff --git a/gemfiles/rails_5.1.6.gemfile b/gemfiles/rails_5.1.6.gemfile index 25ae1251..d0fc95cb 100644 --- a/gemfiles/rails_5.1.6.gemfile +++ b/gemfiles/rails_5.1.6.gemfile @@ -6,8 +6,4 @@ gem "rails", "5.1.6" gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" -group :test do - gem "codeclimate-test-reporter", "~> 1.0.0" -end - gemspec path: "../" diff --git a/gemfiles/rails_5.2.2.gemfile b/gemfiles/rails_5.2.2.gemfile index ee7a440a..91a1be2d 100644 --- a/gemfiles/rails_5.2.2.gemfile +++ b/gemfiles/rails_5.2.2.gemfile @@ -6,8 +6,4 @@ gem "rails", "5.2.2" gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" -group :test do - gem "codeclimate-test-reporter", "~> 1.0.0" -end - gemspec path: "../" From be99787010c4073e6b49239d5a297592627a9590 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 11 Feb 2019 03:15:17 +0100 Subject: [PATCH 063/290] Minor change --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index c0d0eb86..5ae06112 100644 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,7 @@ task :console do require 'pry' require 'rails' require 'ajax-datatables-rails' + puts 'Loaded AjaxDatatablesRails' ARGV.clear Pry.start end From fe946c8c419a6ff9e36912262f83795a6542e4a2 Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Wed, 6 Mar 2019 14:50:58 -0500 Subject: [PATCH 064/290] Change the NULLS_LAST SQL syntax to match the adapter type. --- .../datatable/simple_order_spec.rb | 2 +- .../orm/active_record_sort_records_spec.rb | 4 ++-- spec/support/test_helpers.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 929d1845..cae8e37c 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -19,7 +19,7 @@ it 'sql query' do expect(simple_order.query('email')).to eq( - 'email DESC NULLS LAST' + "email DESC #{nulls_last_sql}" ) end end diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index 0306896a..ba74fe01 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -54,7 +54,7 @@ datatable.params[:order]['0'] = { column: '0', dir: 'asc' } datatable.params[:order]['1'] = { column: '1', dir: 'desc' } expect(datatable.sort_records(records).to_sql).to include( - 'ORDER BY users.username ASC NULLS LAST, users.email DESC NULLS LAST' + "ORDER BY users.username ASC #{nulls_last_sql}, users.email DESC #{nulls_last_sql}" ) end end @@ -66,7 +66,7 @@ nulls_last_datatable.params[:order]['0'] = { column: '0', dir: 'asc' } nulls_last_datatable.params[:order]['1'] = { column: '1', dir: 'desc' } expect(nulls_last_datatable.sort_records(records).to_sql).to include( - 'ORDER BY users.username ASC, users.email DESC NULLS LAST' + "ORDER BY users.username ASC, users.email DESC #{nulls_last_sql}" ) end end diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index 2eeed31b..4fe343bd 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -97,3 +97,14 @@ def data end end end + +def nulls_last_sql + case AjaxDatatablesRails.config.db_adapter + when -> (a) { a.in?([:pg, :postgresql, :postgres, :oracle]) } + "NULLS LAST" + when -> (a) { a.in?([:mysql, :mysql2, :sqlite, :sqlite3]) } + "IS NULL" + else + raise 'unsupported database adapter' + end +end From 5abe8a858d90af4fdb21d18610d19004da4ed3a2 Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Wed, 6 Mar 2019 22:09:52 -0500 Subject: [PATCH 065/290] Simplify the nulls last case statement. --- lib/ajax-datatables-rails/datatable/simple_order.rb | 4 ++-- spec/support/test_helpers.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index bbc3f8d5..63d85d84 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -43,9 +43,9 @@ def nulls_last_sql return unless sort_nulls_last? case AjaxDatatablesRails.config.db_adapter - when -> (a) { a.in?([:pg, :postgresql, :postgres, :oracle]) } + when :pg, :postgresql, :postgres, :oracle "NULLS LAST" - when -> (a) { a.in?([:mysql, :mysql2, :sqlite, :sqlite3]) } + when :mysql, :mysql2, :sqlite, :sqlite3 "IS NULL" else raise 'unsupported database adapter' diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index 4fe343bd..bb7e26db 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -100,9 +100,9 @@ def data def nulls_last_sql case AjaxDatatablesRails.config.db_adapter - when -> (a) { a.in?([:pg, :postgresql, :postgres, :oracle]) } + when :pg, :postgresql, :postgres, :oracle "NULLS LAST" - when -> (a) { a.in?([:mysql, :mysql2, :sqlite, :sqlite3]) } + when :mysql, :mysql2, :sqlite, :sqlite3 "IS NULL" else raise 'unsupported database adapter' From 94ade8a1aa92ec4a8046e93e0bb2333d29fe46d7 Mon Sep 17 00:00:00 2001 From: Don Nguyen Date: Sat, 9 Mar 2019 09:54:58 +0700 Subject: [PATCH 066/290] Add :string_in cond This is helpful when we use multiple_select and want to search by exact values --- .../datatable/column/search.rb | 2 ++ .../orm/active_record_filter_records_spec.rb | 33 +++++++++++++++++++ spec/support/datatable_cond_string.rb | 6 ++++ 3 files changed, 41 insertions(+) diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index ce5c2f5d..bd12d170 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -71,6 +71,8 @@ def non_regex_search casted_column.matches("%#{formatted_value}%") when :string_eq raw_search(:eq) + when :string_in + raw_search(:in) when :date_range date_range_search end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 0afa5557..255a51ef 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -339,6 +339,39 @@ end end + describe 'it can filter records with condition :string_in' do + let(:datatable) { DatatableCondStringIn.new(sample_params) } + + before(:each) do + create(:user, email: 'john@foo.com') + create(:user, email: 'mary@bar.com') + create(:user, email: 'henry@baz.com') + end + + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end + + it 'should filter records matching with multiple' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry@baz.com' + expect(datatable.data.size).to eq 2 + item_first = datatable.data.first + item_last = datatable.data.last + expect(item_first[:email]).to eq 'john@foo.com' + expect(item_last[:email]).to eq 'henry@baz.com' + end + + it 'should filter records matching with multiple contains not found' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry_not@baz.com' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end + end + describe 'it can filter records with condition :null_value' do let(:datatable) { DatatableCondNullValue.new(sample_params) } diff --git a/spec/support/datatable_cond_string.rb b/spec/support/datatable_cond_string.rb index 5aef02fc..204ddb9f 100644 --- a/spec/support/datatable_cond_string.rb +++ b/spec/support/datatable_cond_string.rb @@ -22,6 +22,12 @@ def view_columns end end +class DatatableCondStringIn < ComplexDatatable + def view_columns + super.deep_merge(email: { cond: :string_in, formatter: -> (o) { o.split("|") } }) + end +end + class DatatableCondNullValue < ComplexDatatable def view_columns super.deep_merge(email: { cond: :null_value }) From d29e6bc329d415fe85469db4d95cd0a75fc3208b Mon Sep 17 00:00:00 2001 From: Don Nguyen Date: Sat, 9 Mar 2019 10:01:12 +0700 Subject: [PATCH 067/290] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc176bfb..28415e23 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ end `cond` can be : -* `:like`, `:start_with`, `:end_with`, `:string_eq` for string or full text search +* `:like`, `:start_with`, `:end_with`, `:string_eq`, `:string_in` for string or full text search * `:eq`, `:not_eq`, `:lt`, `:gt`, `:lteq`, `:gteq`, `:in` for numeric * `:date_range` for date range (only for Rails > 4.2.x, see [here](#daterange-search)) * `:null_value` for nil field From c4c250adf734340e1ba449c625d7efebe96a902b Mon Sep 17 00:00:00 2001 From: Michael Madison Date: Thu, 11 Apr 2019 03:27:25 -0500 Subject: [PATCH 068/290] sanitize is such an overused method name that it binds to a lot of different things. Because datatables inherit from AjaxDatatablesRails::ActiveRecord which inherits from AjaxDatatablesRails::Base for some odd reason sanitize binds to ActionView's sanitize method which eventually gets to Loofah and Nokogiri which doesn't handle arrays and throws the error I reported in https://github.com/jbox-web/ajax-datatables-rails/issues/325 surprisingly even when you call self.sanitize it does not call the method in the same namespace and file!! because technically the sanitize function that we want is AjaxDatatablesRails::Base's function, to disabiguate we could either rename the function (and because I don't know what else calls it that seemed like a bad idea), or we could help disambiguate by being explicit about which super's method to call. The only way I saw to do this is to call it like this: AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data). That may make for unreadable code to some, we could always define another method that then calls AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data). Or if you have another way to fix, have at it. But this breaks in Ruby 2.4.0 and rails 5.2.3 for me without this change. --- lib/ajax-datatables-rails/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 08bf54bb..e285c593 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -33,7 +33,7 @@ def as_json(*) { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, - data: sanitize(data), + data: AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data), }.merge(get_additional_data) end From 47d91c7290b7a2b3ce27f2633835db34b075b70c Mon Sep 17 00:00:00 2001 From: Dave Morse Date: Tue, 16 Apr 2019 15:00:32 -0500 Subject: [PATCH 069/290] Update README.md to stop people from walking into issue #287 [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc176bfb..c46b0adc 100644 --- a/README.md +++ b/README.md @@ -350,7 +350,7 @@ $ -> $('#users-datatable').dataTable processing: true serverSide: true - ajax: $('#users-datatable').data('source') + ajax: {url: $('#users-datatable').data('source')} pagingType: 'full_numbers' columns: [ {data: 'id'} @@ -373,7 +373,7 @@ jQuery(document).ready(function() { $('#users-datatable').dataTable({ "processing": true, "serverSide": true, - "ajax": $('#users-datatable').data('source'), + "ajax": {"url": $('#users-datatable').data('source')}, "pagingType": "full_numbers", "columns": [ {"data": "id"}, From 6b88459aece6117e82f5f3f240f9f9810078c800 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 17 Apr 2019 23:47:54 +0200 Subject: [PATCH 070/290] Test with latest Ruby / Rails versions --- .travis.yml | 10 +++++----- Appraisals | 4 ++-- README.md | 4 ++-- gemfiles/{rails_5.1.6.gemfile => rails_5.1.7.gemfile} | 2 +- gemfiles/{rails_5.2.2.gemfile => rails_5.2.3.gemfile} | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) rename gemfiles/{rails_5.1.6.gemfile => rails_5.1.7.gemfile} (90%) rename gemfiles/{rails_5.2.2.gemfile => rails_5.2.3.gemfile} (90%) diff --git a/.travis.yml b/.travis.yml index 8d734cf0..75591749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,16 +2,16 @@ language: ruby cache: bundler sudo: required rvm: - - 2.6.1 - - 2.5.3 - - 2.4.5 + - 2.6.2 + - 2.5.5 + - 2.4.6 - 2.3.8 - ruby-head gemfile: - gemfiles/rails_4.2.11.gemfile - gemfiles/rails_5.0.7.gemfile - - gemfiles/rails_5.1.6.gemfile - - gemfiles/rails_5.2.2.gemfile + - gemfiles/rails_5.1.7.gemfile + - gemfiles/rails_5.2.3.gemfile services: - postgresql - mysql diff --git a/Appraisals b/Appraisals index a0c456ad..1388bdb1 100644 --- a/Appraisals +++ b/Appraisals @@ -8,11 +8,11 @@ RAILS_VERSIONS = { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', 'ruby-oci8' => '', }, - '5.1.6' => { + '5.1.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'ruby-oci8' => '', }, - '5.2.2' => { + '5.2.3' => { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', 'ruby-oci8' => '', }, diff --git a/README.md b/README.md index c46b0adc..c7c42e62 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ It's tested against : -* Rails 4.2.11 / 5.0.7 / 5.1.6 / 5.2.2 -* Ruby 2.3.8 / 2.4.5 / 2.5.3 +* Rails 4.2.11 / 5.0.7 / 5.1.7 / 5.2.3 +* Ruby 2.3.8 / 2.4.5 / 2.5.3 / 2.6.2 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) diff --git a/gemfiles/rails_5.1.6.gemfile b/gemfiles/rails_5.1.7.gemfile similarity index 90% rename from gemfiles/rails_5.1.6.gemfile rename to gemfiles/rails_5.1.7.gemfile index d0fc95cb..e5869bcf 100644 --- a/gemfiles/rails_5.1.6.gemfile +++ b/gemfiles/rails_5.1.7.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "5.1.6" +gem "rails", "5.1.7" gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/gemfiles/rails_5.2.2.gemfile b/gemfiles/rails_5.2.3.gemfile similarity index 90% rename from gemfiles/rails_5.2.2.gemfile rename to gemfiles/rails_5.2.3.gemfile index 91a1be2d..9d4ae3a9 100644 --- a/gemfiles/rails_5.2.2.gemfile +++ b/gemfiles/rails_5.2.3.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "5.2.2" +gem "rails", "5.2.3" gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" From 522ee882a3553e3a1332036598c4a05a7f9f6244 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 17 Apr 2019 23:53:14 +0200 Subject: [PATCH 071/290] Update changelog [ci skip] --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c19fc0b..d63cf334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## 1.1.0 (2019-04-18) + +* Add rudimentary support for Microsoft SQL Server +* Fixes errors when options[param] is nil (thanks @allard) +* Test with latest Rails and Ruby versions + +This is the last version to support Rails 4.x and Ruby 2.3.x. + ## 1.0.0 (2018-08-28) * Breaking change: Remove dependency on view_context [Issue #288](https://github.com/jbox-web/ajax-datatables-rails/issues/288) From 87fe4d7adc112eb270f7f03fb028e5d72b308bcd Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 18 Apr 2019 00:13:36 +0200 Subject: [PATCH 072/290] Coding style [ci skip] --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c7c42e62..3414ec88 100644 --- a/README.md +++ b/README.md @@ -350,7 +350,8 @@ $ -> $('#users-datatable').dataTable processing: true serverSide: true - ajax: {url: $('#users-datatable').data('source')} + ajax: + url: $('#users-datatable').data('source') pagingType: 'full_numbers' columns: [ {data: 'id'} @@ -373,7 +374,9 @@ jQuery(document).ready(function() { $('#users-datatable').dataTable({ "processing": true, "serverSide": true, - "ajax": {"url": $('#users-datatable').data('source')}, + "ajax": { + "url": $('#users-datatable').data('source') + }, "pagingType": "full_numbers", "columns": [ {"data": "id"}, @@ -657,7 +660,7 @@ This feature works with [yadcf](https://github.com/vedmack/yadcf). To enable the date range search, for example `created_at` : -* add a 'created_at' `
` in your html +* add a `created_at` `` in your html * declare your column in `view_columns` : `created_at: { source: 'Post.created_at', cond: :date_range, delimiter: '-yadcf_delim-' }` * add it in `data` : `created_at: record.decorate.created_at` * setup yadcf to make `created_at` search field a range From 703eb66297107256f28b1b4752e90b6166d5c679 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 18 Apr 2019 00:55:52 +0200 Subject: [PATCH 073/290] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d63cf334..973f89aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## 1.1.0 (2019-04-18) * Add rudimentary support for Microsoft SQL Server -* Fixes errors when options[param] is nil (thanks @allard) +* Fixes errors when options[param] is nil [PR 315](https://github.com/jbox-web/ajax-datatables-rails/pull/315) (thanks @allard) +* Add :string_in cond [PR 323](https://github.com/jbox-web/ajax-datatables-rails/pull/323) (thanks @donnguyen) +* Update documentation * Test with latest Rails and Ruby versions This is the last version to support Rails 4.x and Ruby 2.3.x. From 0aa6b48ade2b0efcab725da6627aa555ec9b278f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 18 Apr 2019 01:05:17 +0200 Subject: [PATCH 074/290] Fix flaky tests --- .../orm/active_record_filter_records_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 255a51ef..b55b770b 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -358,10 +358,11 @@ it 'should filter records matching with multiple' do datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry@baz.com' expect(datatable.data.size).to eq 2 - item_first = datatable.data.first - item_last = datatable.data.last - expect(item_first[:email]).to eq 'john@foo.com' - expect(item_last[:email]).to eq 'henry@baz.com' + items = datatable.data.sort_by { |h| h[:email] } + item_first = items.first + item_last = items.last + expect(item_first[:email]).to eq 'henry@baz.com' + expect(item_last[:email]).to eq 'john@foo.com' end it 'should filter records matching with multiple contains not found' do From 2a0877f965c064716374fd4927ef1e0c53d383eb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 18 Apr 2019 01:11:11 +0200 Subject: [PATCH 075/290] Update changelog [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 973f89aa..b0210e34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Add rudimentary support for Microsoft SQL Server * Fixes errors when options[param] is nil [PR 315](https://github.com/jbox-web/ajax-datatables-rails/pull/315) (thanks @allard) +* Improve query performance when nulls_last option is enabled [PR 317](https://github.com/jbox-web/ajax-datatables-rails/pull/317) (thanks @natebird) * Add :string_in cond [PR 323](https://github.com/jbox-web/ajax-datatables-rails/pull/323) (thanks @donnguyen) * Update documentation * Test with latest Rails and Ruby versions From c022c0fde16f8af8ba9f8634af1915c5354f28ad Mon Sep 17 00:00:00 2001 From: Michael Madison Date: Sun, 5 May 2019 02:04:31 -0500 Subject: [PATCH 076/290] shifted to renaming the sanitize function to sanitize_data as discussed --- lib/ajax-datatables-rails/base.rb | 4 ++-- lib/ajax-datatables-rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index e285c593..f99a5d31 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -33,7 +33,7 @@ def as_json(*) { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, - data: AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data), + data: sanitize_data(data), }.merge(get_additional_data) end @@ -81,7 +81,7 @@ def get_additional_data end end - def sanitize(data) + def sanitize_data(data) data.map do |record| if record.is_a?(Array) record.map { |td| ERB::Util.html_escape(td) } diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 2e6960f8..7e0ffd6b 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AjaxDatatablesRails - VERSION = '1.0.0' + VERSION = '1.0.1' end From ced35634fda0b92d7ae5a5c9558e3e287a5a32a8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 9 May 2019 01:47:25 +0200 Subject: [PATCH 077/290] Fix tests --- spec/ajax-datatables-rails/base_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 2777ec8d..a28318d0 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -54,7 +54,7 @@ it 'should html escape data' do create(:user, first_name: 'Name ">', last_name: 'Name ">') - data = datatable.send(:sanitize, datatable.data) + data = datatable.send(:sanitize_data, datatable.data) item = data.first expect(item[:first_name]).to eq 'Name "><img src=x onerror=alert("first_name")>' expect(item[:last_name]).to eq 'Name "><img src=x onerror=alert("last_name")>' @@ -74,7 +74,7 @@ it 'should html escape data' do create(:user, first_name: 'Name ">', last_name: 'Name ">') - data = datatable.send(:sanitize, datatable.data) + data = datatable.send(:sanitize_data, datatable.data) item = data.first expect(item[2]).to eq 'Name "><img src=x onerror=alert("first_name")>' expect(item[3]).to eq 'Name "><img src=x onerror=alert("last_name")>' From d999ff60a329bf0cf538ba103150d3bc7b432dbb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 9 May 2019 01:47:35 +0200 Subject: [PATCH 078/290] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0210e34..af8f9d8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fixes errors when options[param] is nil [PR 315](https://github.com/jbox-web/ajax-datatables-rails/pull/315) (thanks @allard) * Improve query performance when nulls_last option is enabled [PR 317](https://github.com/jbox-web/ajax-datatables-rails/pull/317) (thanks @natebird) * Add :string_in cond [PR 323](https://github.com/jbox-web/ajax-datatables-rails/pull/323) (thanks @donnguyen) +* Rename `sanitize` private method [PR 326](https://github.com/jbox-web/ajax-datatables-rails/pull/326) (thanks @epipheus) * Update documentation * Test with latest Rails and Ruby versions From 71e2c12f0aaa8aaa848c54e03aca05d7c5f9ef97 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 9 May 2019 01:48:34 +0200 Subject: [PATCH 079/290] Bump to version 1.1.0 --- CHANGELOG.md | 2 +- lib/ajax-datatables-rails/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af8f9d8e..403b805c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 1.1.0 (2019-04-18) +## 1.1.0 (to come) * Add rudimentary support for Microsoft SQL Server * Fixes errors when options[param] is nil [PR 315](https://github.com/jbox-web/ajax-datatables-rails/pull/315) (thanks @allard) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 7e0ffd6b..741b97b5 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AjaxDatatablesRails - VERSION = '1.0.1' + VERSION = '1.1.0' end From 6ce6fbd2e21907e279e44fa6e3f1ebe9dc77d589 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 15 Sep 2019 19:19:42 +0200 Subject: [PATCH 080/290] Fix MySQL package version for Travis --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 75591749..eda22b4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,11 +17,6 @@ services: - mysql addons: postgresql: '9.6' - apt: - packages: - - mysql-server-5.6 - - mysql-client-core-5.6 - - mysql-client-5.6 before_install: - gem update --system # - gem install bundler --no-document From ce8624a77bbc1254f67d9ad0cf8b2777a2a74e1c Mon Sep 17 00:00:00 2001 From: MichaelBK Date: Sun, 15 Sep 2019 22:19:44 +0300 Subject: [PATCH 081/290] add imports-loader package --- doc/webpack.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/webpack.md b/doc/webpack.md index e0d001e0..55341404 100644 --- a/doc/webpack.md +++ b/doc/webpack.md @@ -5,7 +5,9 @@ We assume here that Bootstrap and FontAwesome are already installed with Webpack Inspired by https://datatables.net/download and completed : Add npm packages : - +```sh +$ yarn add imports-loader +``` ```sh $ yarn add datatables.net $ yarn add datatables.net-bs From 58060069cd557db3cf3e75a168dbe307a0e11fb1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 16 Sep 2019 20:36:39 +0200 Subject: [PATCH 082/290] Don't test Rails 4.2.x with Ruby head --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index eda22b4a..ec1f17a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,9 @@ env: matrix: allow_failures: - env: DB_ADAPTER=oracle_enhanced + exclude: + - rvm: ruby-head + gemfile: gemfiles/rails_4.2.11.gemfile before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter From 41ae027e5538b7cd161c963a0108f6bce89ab925 Mon Sep 17 00:00:00 2001 From: Martin Magnusek Date: Wed, 27 Nov 2019 11:30:25 +0100 Subject: [PATCH 083/290] Search in column and global together --- .../orm/active_record.rb | 13 ++++++----- .../orm/active_record_filter_records_spec.rb | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index c81b504f..545b64a6 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -30,20 +30,21 @@ def paginate_records(records) # ----------------- SEARCH HELPER METHODS -------------------- def build_conditions - if datatable.searchable? - build_conditions_for_datatable - else - build_conditions_for_selected_columns + @criteria ||= begin + criteria = [build_conditions_for_selected_columns] + criteria << build_conditions_for_datatable if datatable.searchable? + criteria.compact.reduce(:and) end end def build_conditions_for_datatable + columns = searchable_columns.reject(&:searched?) criteria = search_for.inject([]) do |crit, atom| search = Datatable::SimpleSearch.new(value: atom, regex: datatable.search.regexp?) - crit << searchable_columns.map do |simple_column| + crit << columns.map do |simple_column| simple_column.search = search simple_column.search_query - end.reduce(:or) + end.compact.reduce(:or) end.compact.reduce(:and) criteria end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index b55b770b..f0a540b0 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -23,6 +23,29 @@ end end + describe '#build_conditions' do + before(:each) do + create(:user, username: 'johndoe', email: 'johndoe@example.com') + create(:user, username: 'msmith', email: 'mary.smith@example.com') + create(:user, username: 'hsmith', email: 'henry.smith@example.net') + end + + context 'with column and global search' do + before(:each) do + datatable.params[:search] = { value: 'example.com', regex: 'false' } + datatable.params[:columns]['0'][:search][:value] = 'smith' + end + + it 'return a filtered set of records' do + query = datatable.build_conditions + results = records.where(query).map(&:username) + expect(results).to include('msmith') + expect(results).not_to include('johndoe') + expect(results).not_to include('hsmith') + end + end + end + describe '#build_conditions_for_datatable' do before(:each) do create(:user, username: 'johndoe', email: 'johndoe@example.com') From 5fd021b2e6831ab3eda88bba171f334a27ee229c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 11 Dec 2019 21:22:52 +0100 Subject: [PATCH 084/290] Update Travis url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2fe75dc..93a01c3c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![GitHub license](https://img.shields.io/github/license/jbox-web/ajax-datatables-rails.svg)](https://github.com/jbox-web/ajax-datatables-rails/blob/master/LICENSE) [![Gem](https://img.shields.io/gem/v/ajax-datatables-rails.svg)](https://rubygems.org/gems/ajax-datatables-rails) [![Gem](https://img.shields.io/gem/dtv/ajax-datatables-rails.svg)](https://rubygems.org/gems/ajax-datatables-rails) -[![Build Status](https://travis-ci.org/jbox-web/ajax-datatables-rails.svg?branch=master)](https://travis-ci.org/jbox-web/ajax-datatables-rails) +[![Build Status](https://travis-ci.com/jbox-web/ajax-datatables-rails.svg?branch=master)](https://travis-ci.com/jbox-web/ajax-datatables-rails) [![Code Climate](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails) [![Test Coverage](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/coverage) From 3f75539592a556f450aca8307f95bcb678c0b735 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 11 Dec 2019 21:23:31 +0100 Subject: [PATCH 085/290] Test with latest Ruby versions --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec1f17a3..bb7b7516 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: ruby cache: bundler sudo: required rvm: - - 2.6.2 - - 2.5.5 - - 2.4.6 + - 2.6.5 + - 2.5.7 + - 2.4.9 - 2.3.8 - ruby-head gemfile: From 8328ad25f0cf12030a1bb3be093152e110e99a9e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 11 Dec 2019 21:24:02 +0100 Subject: [PATCH 086/290] Don't update rubygem/bundler --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb7b7516..53b98207 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,6 @@ services: addons: postgresql: '9.6' before_install: - - gem update --system - # - gem install bundler --no-document - sh -c "if [ '$DB_ADAPTER' = 'mysql2' ]; then mysql -e 'create database ajax_datatables_rails;'; fi" - sh -c "if [ '$DB_ADAPTER' = 'postgresql' ]; then psql -c 'create database ajax_datatables_rails;' -U postgres; fi" - sh -c "if [ '$DB_ADAPTER' = 'oracle_enhanced' ]; then ./spec/install_oracle.sh; fi" From 198edcd25670463b8dd516850b1591eac815030b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 01:42:42 +0100 Subject: [PATCH 087/290] Test with Rails 6.x --- .travis.yml | 5 +++++ Appraisals | 4 ++++ README.md | 4 ++-- gemfiles/rails_6.0.1.gemfile | 9 +++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_6.0.1.gemfile diff --git a/.travis.yml b/.travis.yml index 53b98207..f43037d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ gemfile: - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.7.gemfile - gemfiles/rails_5.2.3.gemfile + - gemfiles/rails_6.0.1.gemfile services: - postgresql - mysql @@ -38,6 +39,10 @@ matrix: exclude: - rvm: ruby-head gemfile: gemfiles/rails_4.2.11.gemfile + - rvm: 2.3.8 + gemfile: gemfiles/rails_6.0.1.gemfile + - rvm: 2.4.9 + gemfile: gemfiles/rails_6.0.1.gemfile before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter diff --git a/Appraisals b/Appraisals index 1388bdb1..49c0bce6 100644 --- a/Appraisals +++ b/Appraisals @@ -16,6 +16,10 @@ RAILS_VERSIONS = { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', 'ruby-oci8' => '', }, + '6.0.1' => { + 'activerecord-oracle_enhanced-adapter' => '~> 6.0.0', + 'ruby-oci8' => '', + }, }.freeze RAILS_VERSIONS.each do |version, gems| diff --git a/README.md b/README.md index 93a01c3c..c69461b7 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ It's tested against : -* Rails 4.2.11 / 5.0.7 / 5.1.7 / 5.2.3 -* Ruby 2.3.8 / 2.4.5 / 2.5.3 / 2.6.2 +* Rails 4.2.11 / 5.0.7 / 5.1.7 / 5.2.3 / 6.0.1 +* Ruby 2.3.8 / 2.4.9 / 2.5.7 / 2.6.5 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) diff --git a/gemfiles/rails_6.0.1.gemfile b/gemfiles/rails_6.0.1.gemfile new file mode 100644 index 00000000..304a82ee --- /dev/null +++ b/gemfiles/rails_6.0.1.gemfile @@ -0,0 +1,9 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.1" +gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" +gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" + +gemspec path: "../" From f5d124aba1bae63e090b5a55f53f396f8a95027d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 02:07:41 +0100 Subject: [PATCH 088/290] Fix gem dependencies --- Appraisals | 11 +++++++++++ ajax-datatables-rails.gemspec | 2 -- gemfiles/rails_4.2.11.gemfile | 3 ++- gemfiles/rails_5.0.7.gemfile | 2 ++ gemfiles/rails_5.1.7.gemfile | 2 ++ gemfiles/rails_5.2.3.gemfile | 2 ++ gemfiles/rails_6.0.1.gemfile | 2 ++ 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Appraisals b/Appraisals index 49c0bce6..397e7ee2 100644 --- a/Appraisals +++ b/Appraisals @@ -3,21 +3,32 @@ RAILS_VERSIONS = { '4.2.11' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0', + 'sqlite3' => '~> 1.3.0', + 'mysql2' => '0.4.10', + 'ruby-oci8' => '', }, '5.0.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', + 'sqlite3' => '~> 1.3.0', + 'mysql2' => '', 'ruby-oci8' => '', }, '5.1.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', + 'sqlite3' => '~> 1.3.0', + 'mysql2' => '', 'ruby-oci8' => '', }, '5.2.3' => { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', + 'sqlite3' => '~> 1.3.0', + 'mysql2' => '', 'ruby-oci8' => '', }, '6.0.1' => { 'activerecord-oracle_enhanced-adapter' => '~> 6.0.0', + 'sqlite3' => '~> 1.4.0', + 'mysql2' => '', 'ruby-oci8' => '', }, }.freeze diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index a92e39e4..ab228f65 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -23,12 +23,10 @@ Gem::Specification.new do |s| s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' s.add_development_dependency 'generator_spec' - s.add_development_dependency 'mysql2' s.add_development_dependency 'pg', '< 1.0' s.add_development_dependency 'pry' s.add_development_dependency 'rails', '>= 4.2' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' - s.add_development_dependency 'sqlite3', '~> 1.3.0' end diff --git a/gemfiles/rails_4.2.11.gemfile b/gemfiles/rails_4.2.11.gemfile index 467bbf5e..804009a9 100644 --- a/gemfiles/rails_4.2.11.gemfile +++ b/gemfiles/rails_4.2.11.gemfile @@ -3,8 +3,9 @@ source "https://rubygems.org" gem "rails", "4.2.11" -gem "mysql2", "0.4.10" gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0" +gem "sqlite3", "~> 1.3.0" +gem "mysql2", "0.4.10" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" gemspec path: "../" diff --git a/gemfiles/rails_5.0.7.gemfile b/gemfiles/rails_5.0.7.gemfile index 2f74094c..ff4c4849 100644 --- a/gemfiles/rails_5.0.7.gemfile +++ b/gemfiles/rails_5.0.7.gemfile @@ -4,6 +4,8 @@ source "https://rubygems.org" gem "rails", "5.0.7" gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0" +gem "sqlite3", "~> 1.3.0" +gem "mysql2" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" gemspec path: "../" diff --git a/gemfiles/rails_5.1.7.gemfile b/gemfiles/rails_5.1.7.gemfile index e5869bcf..4dc08389 100644 --- a/gemfiles/rails_5.1.7.gemfile +++ b/gemfiles/rails_5.1.7.gemfile @@ -4,6 +4,8 @@ source "https://rubygems.org" gem "rails", "5.1.7" gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" +gem "sqlite3", "~> 1.3.0" +gem "mysql2" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" gemspec path: "../" diff --git a/gemfiles/rails_5.2.3.gemfile b/gemfiles/rails_5.2.3.gemfile index 9d4ae3a9..d30c085e 100644 --- a/gemfiles/rails_5.2.3.gemfile +++ b/gemfiles/rails_5.2.3.gemfile @@ -4,6 +4,8 @@ source "https://rubygems.org" gem "rails", "5.2.3" gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" +gem "sqlite3", "~> 1.3.0" +gem "mysql2" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" gemspec path: "../" diff --git a/gemfiles/rails_6.0.1.gemfile b/gemfiles/rails_6.0.1.gemfile index 304a82ee..1f7c73d3 100644 --- a/gemfiles/rails_6.0.1.gemfile +++ b/gemfiles/rails_6.0.1.gemfile @@ -4,6 +4,8 @@ source "https://rubygems.org" gem "rails", "6.0.1" gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" +gem "sqlite3", "~> 1.4.0" +gem "mysql2" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" gemspec path: "../" From 9df9623e5ce436849eb5ed384f5065b4972cf978 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 02:09:41 +0100 Subject: [PATCH 089/290] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 403b805c..7d01ca5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ * Add :string_in cond [PR 323](https://github.com/jbox-web/ajax-datatables-rails/pull/323) (thanks @donnguyen) * Rename `sanitize` private method [PR 326](https://github.com/jbox-web/ajax-datatables-rails/pull/326) (thanks @epipheus) * Update documentation -* Test with latest Rails and Ruby versions +* Test with latest Rails (6.x) and Ruby versions (2.6) This is the last version to support Rails 4.x and Ruby 2.3.x. From 633247a751654cec798b6b2265bc30b204dd9bf5 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 02:32:12 +0100 Subject: [PATCH 090/290] Download Oracle package from a custom location --- spec/install_oracle.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/install_oracle.sh b/spec/install_oracle.sh index cec3ac49..aa52ba33 100755 --- a/spec/install_oracle.sh +++ b/spec/install_oracle.sh @@ -4,7 +4,12 @@ wget 'https://github.com/cbandy/travis-oracle/archive/v2.0.3.tar.gz' mkdir -p ~/.travis/oracle tar xz --strip-components 1 -C ~/.travis/oracle -f v2.0.3.tar.gz -~/.travis/oracle/download.sh +if [ -n $CUSTOM_ORACLE_FILE ]; then + wget -q $CUSTOM_ORACLE_FILE -O ~/.travis/oracle/oracle-xe-11.2.0-1.0.x86_64.rpm.zip +else + ~/.travis/oracle/download.sh +fi + ~/.travis/oracle/install.sh "$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA < Date: Thu, 12 Dec 2019 02:33:51 +0100 Subject: [PATCH 091/290] Tests on Oracle DB should work now --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f43037d3..ef0eeb51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,8 +34,6 @@ env: - DB_ADAPTER=sqlite3 - DB_ADAPTER=oracle_enhanced matrix: - allow_failures: - - env: DB_ADAPTER=oracle_enhanced exclude: - rvm: ruby-head gemfile: gemfiles/rails_4.2.11.gemfile From 6b8fc55dc67046d6bedd013732b3303fca96ef02 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 03:54:25 +0100 Subject: [PATCH 092/290] Add comment/reminder for dev setup --- spec/install_oracle.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/install_oracle.sh b/spec/install_oracle.sh index aa52ba33..44db7ded 100755 --- a/spec/install_oracle.sh +++ b/spec/install_oracle.sh @@ -12,6 +12,7 @@ fi ~/.travis/oracle/install.sh +# in dev env: sqlplus system/password@localhost/XE "$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA < Date: Thu, 12 Dec 2019 03:59:41 +0100 Subject: [PATCH 093/290] Fix tests on Oracle DB --- spec/ajax-datatables-rails/datatable/simple_order_spec.rb | 2 ++ .../orm/active_record_filter_records_spec.rb | 8 ++++---- .../orm/active_record_paginate_records_spec.rb | 8 ++++---- .../orm/active_record_sort_records_spec.rb | 4 ++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index cae8e37c..28f20058 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -18,6 +18,8 @@ after { AjaxDatatablesRails.config.nulls_last = false } it 'sql query' do + skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' + expect(simple_order.query('email')).to eq( "email DESC #{nulls_last_sql}" ) diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index b55b770b..a15202b4 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -126,7 +126,7 @@ expect(result).to be_a(Arel::Nodes::And) end - if AjaxDatatablesRails.config.db_adapter == :postgresql + if ENV['DB_ADAPTER'] == 'postgresql' context 'when db_adapter is postgresql' do it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns @@ -138,7 +138,7 @@ end end - if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] + if ENV['DB_ADAPTER'] == 'oracle_enhanced' context 'when db_adapter is oracle' do it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns @@ -150,7 +150,7 @@ end end - if AjaxDatatablesRails.config.db_adapter.in? %i[mysql2 sqlite3] + if ENV['DB_ADAPTER'] == 'mysql2' context 'when db_adapter is mysql2' do it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns @@ -288,7 +288,7 @@ create(:user, last_name: 'MARY') end - if AjaxDatatablesRails.config.db_adapter == :oracleenhanced + if ENV['DB_ADAPTER'] == 'oracle_enhanced' context 'when db_adapter is oracleenhanced' do it 'should filter records matching' do datatable.params[:columns]['3'][:search][:value] = 'RY' diff --git a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb index d4964178..51689833 100644 --- a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb @@ -16,8 +16,8 @@ end it 'paginates records properly' do - if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] - if Rails.version.in? %w[4.0.13 4.1.16 4.2.10] + if ENV['DB_ADAPTER'] == 'oracle_enhanced' + if Rails.version.in? %w[4.2.11] expect(datatable.paginate_records(records).to_sql).to include( 'rownum <= 10' ) @@ -34,8 +34,8 @@ datatable.params[:start] = '26' datatable.params[:length] = '25' - if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] - if Rails.version.in? %w[4.0.13 4.1.16 4.2.10] + if ENV['DB_ADAPTER'] == 'oracle_enhanced' + if Rails.version.in? %w[4.2.11] expect(datatable.paginate_records(records).to_sql).to include( 'rownum <= 51' ) diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index ba74fe01..1c0e8cad 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -49,6 +49,8 @@ after { AjaxDatatablesRails.config.nulls_last = false } it 'can handle multiple sorting columns' do + skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' + # set to order by Users username in ascending order, and # by Users email in descending order datatable.params[:order]['0'] = { column: '0', dir: 'asc' } @@ -61,6 +63,8 @@ describe '#sort_records with nulls last using column config' do it 'can handle multiple sorting columns' do + skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' + # set to order by Users username in ascending order, and # by Users email in descending order nulls_last_datatable.params[:order]['0'] = { column: '0', dir: 'asc' } From 7883f78497dcb5c8a608e90f961a5dc73dc6aa8c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 04:48:15 +0100 Subject: [PATCH 094/290] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d01ca5d..603ed0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 1.1.0 (to come) +## 1.1.0 (2019-12-12) * Add rudimentary support for Microsoft SQL Server * Fixes errors when options[param] is nil [PR 315](https://github.com/jbox-web/ajax-datatables-rails/pull/315) (thanks @allard) From d55140e2088c1fcf6bfe9ef07b4ec254e8afbb9a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 04:51:36 +0100 Subject: [PATCH 095/290] Drop support of Rails 4.2.x and Ruby 2.3 --- .travis.yml | 6 ------ Appraisals | 6 ------ CHANGELOG.md | 5 +++++ ajax-datatables-rails.gemspec | 4 ++-- gemfiles/rails_4.2.11.gemfile | 11 ----------- 5 files changed, 7 insertions(+), 25 deletions(-) delete mode 100644 gemfiles/rails_4.2.11.gemfile diff --git a/.travis.yml b/.travis.yml index ef0eeb51..41024c17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,8 @@ rvm: - 2.6.5 - 2.5.7 - 2.4.9 - - 2.3.8 - ruby-head gemfile: - - gemfiles/rails_4.2.11.gemfile - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.7.gemfile - gemfiles/rails_5.2.3.gemfile @@ -35,10 +33,6 @@ env: - DB_ADAPTER=oracle_enhanced matrix: exclude: - - rvm: ruby-head - gemfile: gemfiles/rails_4.2.11.gemfile - - rvm: 2.3.8 - gemfile: gemfiles/rails_6.0.1.gemfile - rvm: 2.4.9 gemfile: gemfiles/rails_6.0.1.gemfile before_script: diff --git a/Appraisals b/Appraisals index 397e7ee2..e59bb61e 100644 --- a/Appraisals +++ b/Appraisals @@ -1,12 +1,6 @@ # frozen_string_literal: true RAILS_VERSIONS = { - '4.2.11' => { - 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0', - 'sqlite3' => '~> 1.3.0', - 'mysql2' => '0.4.10', - 'ruby-oci8' => '', - }, '5.0.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', 'sqlite3' => '~> 1.3.0', diff --git a/CHANGELOG.md b/CHANGELOG.md index 603ed0a1..117ff285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 1.2.0 (to come) + +* Drop support of Rails 4.x +* Drop support of Ruby 2.3 + ## 1.1.0 (2019-12-12) * Add rudimentary support for Microsoft SQL Server diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index ab228f65..a3735a20 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_runtime_dependency 'railties', '>= 4.2' + s.add_runtime_dependency 'railties', '>= 5.0' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' s.add_development_dependency 'appraisal' @@ -25,7 +25,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'generator_spec' s.add_development_dependency 'pg', '< 1.0' s.add_development_dependency 'pry' - s.add_development_dependency 'rails', '>= 4.2' + s.add_development_dependency 'rails', '>= 5.0' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'simplecov' diff --git a/gemfiles/rails_4.2.11.gemfile b/gemfiles/rails_4.2.11.gemfile deleted file mode 100644 index 804009a9..00000000 --- a/gemfiles/rails_4.2.11.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "4.2.11" -gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0" -gem "sqlite3", "~> 1.3.0" -gem "mysql2", "0.4.10" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" - -gemspec path: "../" From 972018756d261a8a1e1ad2273c8979f18f7c60c3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 05:18:02 +0100 Subject: [PATCH 096/290] Use Zeitwerk to load files --- ajax-datatables-rails.gemspec | 3 +++ lib/ajax-datatables-rails.rb | 29 +++++++++++++++++++++- lib/ajax-datatables-rails/config.rb | 28 --------------------- lib/ajax-datatables-rails/configuration.rb | 10 ++++++++ lib/ajax_datatables_rails.rb | 16 ------------ 5 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 lib/ajax-datatables-rails/config.rb create mode 100644 lib/ajax-datatables-rails/configuration.rb delete mode 100644 lib/ajax_datatables_rails.rb diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index a3735a20..08fe45a6 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -13,9 +13,12 @@ Gem::Specification.new do |s| s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app" s.license = 'MIT' + s.required_ruby_version = '>= 2.4.4' + s.files = `git ls-files`.split("\n") s.add_runtime_dependency 'railties', '>= 5.0' + s.add_runtime_dependency 'zeitwerk' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' s.add_development_dependency 'appraisal' diff --git a/lib/ajax-datatables-rails.rb b/lib/ajax-datatables-rails.rb index 9675176c..e1423993 100644 --- a/lib/ajax-datatables-rails.rb +++ b/lib/ajax-datatables-rails.rb @@ -1,3 +1,30 @@ # frozen_string_literal: true -require 'ajax_datatables_rails' +require 'active_support/configurable' + +require 'zeitwerk' +loader = Zeitwerk::Loader.for_gem +generators = "#{__dir__}/generators" +loader.ignore(generators) +loader.inflector.inflect( + 'orm' => 'ORM', + 'ajax-datatables-rails' => 'AjaxDatatablesRails', +) +loader.setup + +module AjaxDatatablesRails + # Configure AjaxDatatablesRails global settings + # + # AjaxDatatablesRails.configure do |config| + # config.db_adapter = :postgresql + # end + + def self.configure + yield @config ||= AjaxDatatablesRails::Configuration.new + end + + # AjaxDatatablesRails global settings + def self.config + @config ||= AjaxDatatablesRails::Configuration.new + end +end diff --git a/lib/ajax-datatables-rails/config.rb b/lib/ajax-datatables-rails/config.rb deleted file mode 100644 index a95532e1..00000000 --- a/lib/ajax-datatables-rails/config.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require 'active_support/configurable' - -module AjaxDatatablesRails - - # Configure AjaxDatatablesRails global settings - # - # AjaxDatatablesRails.configure do |config| - # config.db_adapter = :postgresql - # end - - def self.configure - yield @config ||= AjaxDatatablesRails::Configuration.new - end - - # AjaxDatatablesRails global settings - def self.config - @config ||= AjaxDatatablesRails::Configuration.new - end - - class Configuration - include ActiveSupport::Configurable - - config_accessor(:db_adapter) { :postgresql } - config_accessor(:nulls_last) { false } - end -end diff --git a/lib/ajax-datatables-rails/configuration.rb b/lib/ajax-datatables-rails/configuration.rb new file mode 100644 index 00000000..7c6d6ab3 --- /dev/null +++ b/lib/ajax-datatables-rails/configuration.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + class Configuration + include ActiveSupport::Configurable + + config_accessor(:db_adapter) { :postgresql } + config_accessor(:nulls_last) { false } + end +end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb deleted file mode 100644 index 6c8edc6b..00000000 --- a/lib/ajax_datatables_rails.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module AjaxDatatablesRails - require 'ajax-datatables-rails/version' - require 'ajax-datatables-rails/config' - require 'ajax-datatables-rails/base' - require 'ajax-datatables-rails/datatable/datatable' - require 'ajax-datatables-rails/datatable/simple_search' - require 'ajax-datatables-rails/datatable/simple_order' - require 'ajax-datatables-rails/datatable/column/search' - require 'ajax-datatables-rails/datatable/column/order' - require 'ajax-datatables-rails/datatable/column/date_filter' - require 'ajax-datatables-rails/datatable/column' - require 'ajax-datatables-rails/orm/active_record' - require 'ajax-datatables-rails/active_record' -end From 0e592e89f0365d6c02a3373f8f3191b6bd3d26ec Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 05:22:37 +0100 Subject: [PATCH 097/290] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c69461b7..d1828bd4 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ It's tested against : -* Rails 4.2.11 / 5.0.7 / 5.1.7 / 5.2.3 / 6.0.1 -* Ruby 2.3.8 / 2.4.9 / 2.5.7 / 2.6.5 +* Rails 5.0.7 / 5.1.7 / 5.2.3 / 6.0.1 +* Ruby 2.4.9 / 2.5.7 / 2.6.5 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) From ee4e327c987e356164fc6e1764b69214e44e007b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 05:23:30 +0100 Subject: [PATCH 098/290] Update CHANGELOG [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 117ff285..6e7eb62a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Drop support of Rails 4.x * Drop support of Ruby 2.3 +* Use [zeitwerk](https://github.com/fxn/zeitwerk) to load gem files ## 1.1.0 (2019-12-12) From 450b1d10cd992784f143d15561280b67a2bcd7cf Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 05:36:22 +0100 Subject: [PATCH 099/290] Fix coding style --- .rubocop.yml | 16 ++++++---- ajax-datatables-rails.gemspec | 1 + bin/rubocop | 29 +++++++++++++++++++ lib/ajax-datatables-rails.rb | 2 +- .../datatable/simple_order.rb | 6 ++-- 5 files changed, 44 insertions(+), 10 deletions(-) create mode 100755 bin/rubocop diff --git a/.rubocop.yml b/.rubocop.yml index bed5deaf..dd6efd02 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,15 +1,15 @@ AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.4 Exclude: + - bin/* + - lib/generators/**/*.rb - gemfiles/* - - spec/**/*.rb - - lib/ajax-datatables-rails.rb - - lib/generators/rails/templates/*.rb + - spec/**/* -Documentation: +Style/Documentation: Enabled: false -Layout/AlignHash: +Layout/HashAlignment: Enabled: false Layout/EmptyLines: @@ -45,6 +45,10 @@ Metrics/ClassLength: Naming/AccessorMethodName: Enabled: false +Naming/FileName: + Exclude: + - lib/ajax-datatables-rails.rb + Style/TrailingCommaInArrayLiteral: EnforcedStyleForMultiline: comma diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 08fe45a6..d0c5853f 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -31,5 +31,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'rails', '>= 5.0' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' + s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov' end diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 00000000..d0c48829 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/lib/ajax-datatables-rails.rb b/lib/ajax-datatables-rails.rb index e1423993..a051bd43 100644 --- a/lib/ajax-datatables-rails.rb +++ b/lib/ajax-datatables-rails.rb @@ -8,7 +8,7 @@ loader.ignore(generators) loader.inflector.inflect( 'orm' => 'ORM', - 'ajax-datatables-rails' => 'AjaxDatatablesRails', + 'ajax-datatables-rails' => 'AjaxDatatablesRails' ) loader.setup diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 63d85d84..a5725228 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -14,7 +14,7 @@ def initialize(datatable, options = {}) end def query(sort_column) - [sort_column, direction, nulls_last_sql].compact.join(" ") + [sort_column, direction, nulls_last_sql].compact.join(' ') end def column @@ -44,9 +44,9 @@ def nulls_last_sql case AjaxDatatablesRails.config.db_adapter when :pg, :postgresql, :postgres, :oracle - "NULLS LAST" + 'NULLS LAST' when :mysql, :mysql2, :sqlite, :sqlite3 - "IS NULL" + 'IS NULL' else raise 'unsupported database adapter' end From 189ef11ec803d2a7c7895347eaff43b07fa5b345 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 05:42:39 +0100 Subject: [PATCH 100/290] Provide a better interface to gem version --- ajax-datatables-rails.gemspec | 2 +- lib/ajax-datatables-rails/version.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index d0c5853f..82d19f61 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -4,7 +4,7 @@ require_relative 'lib/ajax-datatables-rails/version' Gem::Specification.new do |s| s.name = 'ajax-datatables-rails' - s.version = AjaxDatatablesRails::VERSION + s.version = AjaxDatatablesRails::VERSION::STRING s.platform = Gem::Platform::RUBY s.authors = ['Joel Quenneville', 'Antonio Antillon'] s.email = ['joel.quenneville@collegeplus.org', 'antillas21@gmail.com'] diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 741b97b5..7fb71ae2 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,5 +1,17 @@ # frozen_string_literal: true module AjaxDatatablesRails - VERSION = '1.1.0' + + def self.gem_version + Gem::Version.new VERSION::STRING + end + + module VERSION + MAJOR = 1 + MINOR = 1 + TINY = 0 + PRE = nil + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') + end end From b06604e1b14aaef6352a814cfb07a796bcde1c84 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 12 Dec 2019 05:51:26 +0100 Subject: [PATCH 101/290] Remove deprecated method --- lib/ajax-datatables-rails/base.rb | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index f99a5d31..c124e2df 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -34,7 +34,7 @@ def as_json(*) recordsTotal: records_total_count, recordsFiltered: records_filtered_count, data: sanitize_data(data), - }.merge(get_additional_data) + }.merge(additional_data) end def records @@ -64,23 +64,6 @@ def search_columns private - # This method is necessary for smooth transition from - # `additinonal_datas` method to `additional_data` - # without breaking change. - def get_additional_data - if respond_to?(:additional_datas) - puts <<-WARNING - `additional_datas` has been deprecated and - will be removed in next major version update! - Please use `additional_data` instead. - WARNING - - additional_datas - else - additional_data - end - end - def sanitize_data(data) data.map do |record| if record.is_a?(Array) From 44488c7f83adf3141191daea6dfe16e472ac76e3 Mon Sep 17 00:00:00 2001 From: RutSzymon Date: Mon, 16 Dec 2019 12:25:25 +0100 Subject: [PATCH 102/290] Improved range_end_casted method in Column::DateFilter to support greater than the current date --- lib/ajax-datatables-rails/datatable/column/date_filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index 7fa0b801..16a3a713 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -55,7 +55,7 @@ def range_start_casted end def range_end_casted - range_end.blank? ? Time.current : parse_date("#{range_end} 23:59:59") + range_end.blank? ? parse_date("9999-12-31 23:59:59") : parse_date("#{range_end} 23:59:59") end def parse_date(date) From 2f826df1379a8b6f3129c5603c5aea1772cfbd4f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 26 Dec 2019 01:50:32 +0100 Subject: [PATCH 103/290] Ruby 2.7 is out --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 41024c17..b6d50da1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby cache: bundler sudo: required rvm: + - 2.7.0 - 2.6.5 - 2.5.7 - 2.4.9 From bb910b28247d7225dd7f8324ebb72293b1a838fa Mon Sep 17 00:00:00 2001 From: Pavel Bezpalov Date: Fri, 14 Feb 2020 17:18:59 +0200 Subject: [PATCH 104/290] Added processing arrays in json params --- .../datatable/datatable.rb | 8 ++++- .../datatable/datatable_spec.rb | 36 +++++++++++++------ spec/support/test_helpers.rb | 7 ++++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index bf5f3118..48e3b145 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -70,7 +70,13 @@ def page def get_param(param) return {} if options[param].nil? - options[param].to_unsafe_h.with_indifferent_access + if options[param].is_a? Array + hash = {} + options[param].each_with_index { |value, index| hash[index] = value } + hash + else + options[param].to_unsafe_h.with_indifferent_access + end end end diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index aa8a5185..4f839215 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -3,9 +3,11 @@ describe AjaxDatatablesRails::Datatable::Datatable do let(:datatable) { ComplexDatatable.new(sample_params).datatable } + let(:datatable_json) { ComplexDatatable.new(sample_params_json).datatable } let(:order_option) { {'0'=>{'column'=>'0', 'dir'=>'asc'}, '1'=>{'column'=>'1', 'dir'=>'desc'}} } + let(:order_option_json) { [{'column'=>'0', 'dir'=>'asc'}, {'column'=>'1', 'dir'=>'desc'}] } - describe 'order methods' do + shared_examples 'order methods' do it 'should be orderable' do expect(datatable.orderable?).to eq(true) end @@ -35,6 +37,28 @@ end end + shared_examples 'columns methods' do + it 'should have 4 columns' do + expect(datatable.columns.count).to eq(6) + end + + it 'child class' do + expect(datatable.columns.first).to be_a(AjaxDatatablesRails::Datatable::Column) + end + end + + describe 'with query params' do + it_behaves_like 'order methods' + it_behaves_like 'columns methods' + end + + describe 'with json params' do + let(:order_option) { order_option_json } + let(:datatable) { datatable_json } + it_behaves_like 'order methods' + it_behaves_like 'columns methods' + end + describe 'search methods' do it 'should be searchable' do datatable.options[:search][:value] = 'atom' @@ -51,16 +75,6 @@ end end - describe 'columns methods' do - it 'should have 4 columns' do - expect(datatable.columns.count).to eq(6) - end - - it 'child class' do - expect(datatable.columns.first).to be_a(AjaxDatatablesRails::Datatable::Column) - end - end - describe 'option methods' do before :each do datatable.options[:start] = '50' diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index bb7e26db..62a63f2b 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -51,6 +51,13 @@ def sample_params } ) end + +def sample_params_json + hash_params = sample_params.to_unsafe_h + hash_params["columns"] = hash_params["columns"].values + hash_params["order"] = hash_params["order"].values + ActionController::Parameters.new(hash_params) +end # rubocop:enable Metrics/MethodLength class ComplexDatatable < AjaxDatatablesRails::ActiveRecord From 4076beff7d14ed56b6ff5cf8345f3c6a954f190f Mon Sep 17 00:00:00 2001 From: Pavel Bezpalov Date: Fri, 14 Feb 2020 17:36:07 +0200 Subject: [PATCH 105/290] Updated readme examples --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d1828bd4..8c51e825 100644 --- a/README.md +++ b/README.md @@ -787,14 +787,20 @@ $ -> $('#posts-datatable').dataTable ajax: url: $('#posts-datatable').data('source') + contentType: 'application/json' type: 'POST' + data: (d) -> + JSON.stringify d # ...others options, see [here](#5-wire-up-the-javascript) $ -> $('#users-datatable').dataTable ajax: url: $('#users-datatable').data('source') + contentType: 'application/json' type: 'POST' + data: (d) -> + JSON.stringify d # ...others options, see [here](#5-wire-up-the-javascript) ``` From e2a18d5065f3137fb51648b33e02dd858896d934 Mon Sep 17 00:00:00 2001 From: Pavel Bezpalov Date: Fri, 14 Feb 2020 17:54:34 +0200 Subject: [PATCH 106/290] Added different examples --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c51e825..36d08091 100644 --- a/README.md +++ b/README.md @@ -783,16 +783,15 @@ then in your views : then in your Coffee/JS : ```coffee +# send params in form data $ -> $('#posts-datatable').dataTable ajax: url: $('#posts-datatable').data('source') - contentType: 'application/json' type: 'POST' - data: (d) -> - JSON.stringify d # ...others options, see [here](#5-wire-up-the-javascript) +# send params as json data $ -> $('#users-datatable').dataTable ajax: From ce307200af40d021b38c259ac7faddafa3d3d752 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 4 Apr 2020 14:29:23 +0200 Subject: [PATCH 107/290] Test with latest Ruby versions --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b6d50da1..dd7e1fe4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,10 @@ language: ruby cache: bundler sudo: required rvm: - - 2.7.0 - - 2.6.5 - - 2.5.7 - - 2.4.9 + - 2.7.1 + - 2.6.6 + - 2.5.8 + - 2.4.10 - ruby-head gemfile: - gemfiles/rails_5.0.7.gemfile @@ -34,7 +34,7 @@ env: - DB_ADAPTER=oracle_enhanced matrix: exclude: - - rvm: 2.4.9 + - rvm: 2.4.10 gemfile: gemfiles/rails_6.0.1.gemfile before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter From 9bd7f51c40b4f0996a95029ebba636138f3dcb50 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:17:19 +0200 Subject: [PATCH 108/290] Add binstubs for Rake and RSpec --- bin/rake | 29 +++++++++++++++++++++++++++++ bin/rspec | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 bin/rake create mode 100755 bin/rspec diff --git a/bin/rake b/bin/rake new file mode 100755 index 00000000..9275675e --- /dev/null +++ b/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 00000000..a6c78521 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") From 01c0fcb18cabd9e1a87016ce95356b3ef2367693 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:18:31 +0200 Subject: [PATCH 109/290] Force simplecov version to workaround CodeClimate bug See: https://github.com/codeclimate/test-reporter/issues/413 --- ajax-datatables-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 82d19f61..7b2ad593 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -32,5 +32,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'rubocop' - s.add_development_dependency 'simplecov' + s.add_development_dependency 'simplecov', '~> 0.17.1' end From 820302041fb009e2320b90b788372ed35cc96045 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:23:45 +0200 Subject: [PATCH 110/290] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1828bd4..1bfa7c55 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It's tested against : * Rails 5.0.7 / 5.1.7 / 5.2.3 / 6.0.1 -* Ruby 2.4.9 / 2.5.7 / 2.6.5 +* Ruby 2.4.10 / 2.5.8 / 2.6.6 / 2.7.1 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) From 2b3bad970a21baf1e18895f2dbe06776fe7496b6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:25:04 +0200 Subject: [PATCH 111/290] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e7eb62a..dbde285b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * Drop support of Ruby 2.3 * Use [zeitwerk](https://github.com/fxn/zeitwerk) to load gem files +This is the last version to support Rails 5.0.x and Ruby 2.4.x. + ## 1.1.0 (2019-12-12) * Add rudimentary support for Microsoft SQL Server From a7868f47ba50af763ae68099465db5343869c495 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:29:18 +0200 Subject: [PATCH 112/290] Cleanup Travis file --- .travis.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd7e1fe4..13bad11a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,44 +1,55 @@ +--- +os: linux +dist: bionic + language: ruby cache: bundler -sudo: required rvm: - 2.7.1 - 2.6.6 - 2.5.8 - 2.4.10 - ruby-head + gemfile: - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.7.gemfile - gemfiles/rails_5.2.3.gemfile - gemfiles/rails_6.0.1.gemfile + services: - postgresql - mysql + addons: postgresql: '9.6' + before_install: - sh -c "if [ '$DB_ADAPTER' = 'mysql2' ]; then mysql -e 'create database ajax_datatables_rails;'; fi" - sh -c "if [ '$DB_ADAPTER' = 'postgresql' ]; then psql -c 'create database ajax_datatables_rails;' -U postgres; fi" - sh -c "if [ '$DB_ADAPTER' = 'oracle_enhanced' ]; then ./spec/install_oracle.sh; fi" + env: global: - ORACLE_COOKIE=sqldev - ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip - ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe - ORACLE_SID=XE - matrix: + jobs: - DB_ADAPTER=postgresql - DB_ADAPTER=mysql2 - DB_ADAPTER=sqlite3 - DB_ADAPTER=oracle_enhanced -matrix: + +jobs: exclude: - rvm: 2.4.10 gemfile: gemfiles/rails_6.0.1.gemfile + before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build + after_script: - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT From 21a9842ef2e1a07c6c71954d2672c67be08b8108 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:34:01 +0200 Subject: [PATCH 113/290] Add binstub for Appraisal --- bin/appraisal | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 bin/appraisal diff --git a/bin/appraisal b/bin/appraisal new file mode 100755 index 00000000..0e7ba65d --- /dev/null +++ b/bin/appraisal @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'appraisal' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("appraisal", "appraisal") From a8bc7946214a252cbc3318fda0de58ca7838d392 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:34:58 +0200 Subject: [PATCH 114/290] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbde285b..21f3ee96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Drop support of Rails 4.x * Drop support of Ruby 2.3 * Use [zeitwerk](https://github.com/fxn/zeitwerk) to load gem files +* Add binstubs to ease development This is the last version to support Rails 5.0.x and Ruby 2.4.x. From 173b5223e5f12e6ac62c5447e8af0b489c5cc693 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Apr 2020 21:36:43 +0200 Subject: [PATCH 115/290] Allow failures for ruby-head --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 13bad11a..2aa7e2da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,8 @@ jobs: exclude: - rvm: 2.4.10 gemfile: gemfiles/rails_6.0.1.gemfile + allow_failures: + - rvm: ruby-head before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter From 6c12590fbd2be15175ba22e4b95a662047ec6ddc Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 03:19:17 +0200 Subject: [PATCH 116/290] Add Guard gem --- Guardfile | 16 ++++++++++++++++ ajax-datatables-rails.gemspec | 1 + bin/_guard-core | 29 +++++++++++++++++++++++++++++ bin/guard | 29 +++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 Guardfile create mode 100755 bin/_guard-core create mode 100755 bin/guard diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..15175960 --- /dev/null +++ b/Guardfile @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +guard :rspec, cmd: 'bundle exec rspec' do + require 'guard/rspec/dsl' + dsl = Guard::RSpec::Dsl.new(self) + + # RSpec files + rspec = dsl.rspec + watch(rspec.spec_helper) { rspec.spec_dir } + watch(rspec.spec_support) { rspec.spec_dir } + watch(rspec.spec_files) + + # Ruby files + ruby = dsl.ruby + dsl.watch_spec_files_for(ruby.lib_files) +end diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 7b2ad593..055b040f 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' s.add_development_dependency 'generator_spec' + s.add_development_dependency 'guard-rspec' s.add_development_dependency 'pg', '< 1.0' s.add_development_dependency 'pry' s.add_development_dependency 'rails', '>= 5.0' diff --git a/bin/_guard-core b/bin/_guard-core new file mode 100755 index 00000000..cd565c3a --- /dev/null +++ b/bin/_guard-core @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application '_guard-core' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("guard", "_guard-core") diff --git a/bin/guard b/bin/guard new file mode 100755 index 00000000..bcb966f4 --- /dev/null +++ b/bin/guard @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'guard' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("guard", "guard") From 90a70f0f1ade22445c0ec00cb5509cad8afc4a61 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 03:23:21 +0200 Subject: [PATCH 117/290] Revert Travis distro config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2aa7e2da..886e71ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ --- os: linux -dist: bionic +dist: xenial language: ruby cache: bundler From 0b934f0f7be32693910195bd3a6f74e9a0383400 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 04:13:28 +0200 Subject: [PATCH 118/290] Bump to version 1.2.0 --- lib/ajax-datatables-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 7fb71ae2..6d5dcee9 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -8,7 +8,7 @@ def self.gem_version module VERSION MAJOR = 1 - MINOR = 1 + MINOR = 2 TINY = 0 PRE = nil From 9cb1dba4710b272c35735746dcd948cca170ab90 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 04:31:15 +0200 Subject: [PATCH 119/290] Update CHANGELOG --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f3ee96..021c7754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # CHANGELOG -## 1.2.0 (to come) +## 1.3.0 (to come) + +* Drop support of Rails 5.0.x +* Drop support of Ruby 2.4 + +## 1.2.0 (2020-04-19) * Drop support of Rails 4.x * Drop support of Ruby 2.3 From fea29467c0c2ab2f8e1ff131c88334bbcf9ed95e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 04:33:28 +0200 Subject: [PATCH 120/290] Ruby 2.4 is EOL --- .rubocop.yml | 2 +- .travis.yml | 4 ---- README.md | 2 +- ajax-datatables-rails.gemspec | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dd6efd02..92689c89 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Exclude: - bin/* - lib/generators/**/*.rb diff --git a/.travis.yml b/.travis.yml index 886e71ac..dcb26778 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ rvm: - 2.7.1 - 2.6.6 - 2.5.8 - - 2.4.10 - ruby-head gemfile: @@ -42,9 +41,6 @@ env: - DB_ADAPTER=oracle_enhanced jobs: - exclude: - - rvm: 2.4.10 - gemfile: gemfiles/rails_6.0.1.gemfile allow_failures: - rvm: ruby-head diff --git a/README.md b/README.md index 1bfa7c55..3e890b06 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It's tested against : * Rails 5.0.7 / 5.1.7 / 5.2.3 / 6.0.1 -* Ruby 2.4.10 / 2.5.8 / 2.6.6 / 2.7.1 +* Ruby 2.5.8 / 2.6.6 / 2.7.1 * Postgresql 9.6 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 055b040f..8dd8031a 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app" s.license = 'MIT' - s.required_ruby_version = '>= 2.4.4' + s.required_ruby_version = '>= 2.5.0' s.files = `git ls-files`.split("\n") From 6b677361fc0d5518f3892a1b4682f433224cffc5 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 04:37:00 +0200 Subject: [PATCH 121/290] Drop support of Rails 5.0.x --- .travis.yml | 1 - Appraisals | 6 ------ README.md | 2 +- ajax-datatables-rails.gemspec | 4 ++-- gemfiles/rails_5.0.7.gemfile | 11 ----------- 5 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 gemfiles/rails_5.0.7.gemfile diff --git a/.travis.yml b/.travis.yml index dcb26778..e55e1455 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ rvm: - ruby-head gemfile: - - gemfiles/rails_5.0.7.gemfile - gemfiles/rails_5.1.7.gemfile - gemfiles/rails_5.2.3.gemfile - gemfiles/rails_6.0.1.gemfile diff --git a/Appraisals b/Appraisals index e59bb61e..3ae089d8 100644 --- a/Appraisals +++ b/Appraisals @@ -1,12 +1,6 @@ # frozen_string_literal: true RAILS_VERSIONS = { - '5.0.7' => { - 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', - 'sqlite3' => '~> 1.3.0', - 'mysql2' => '', - 'ruby-oci8' => '', - }, '5.1.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'sqlite3' => '~> 1.3.0', diff --git a/README.md b/README.md index 3e890b06..d41e4bd5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails 5.0.7 / 5.1.7 / 5.2.3 / 6.0.1 +* Rails 5.1.7 / 5.2.3 / 6.0.1 * Ruby 2.5.8 / 2.6.6 / 2.7.1 * Postgresql 9.6 * MySQL 5.6 diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 8dd8031a..d849641a 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_runtime_dependency 'railties', '>= 5.0' + s.add_runtime_dependency 'railties', '>= 5.1' s.add_runtime_dependency 'zeitwerk' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' @@ -29,7 +29,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'guard-rspec' s.add_development_dependency 'pg', '< 1.0' s.add_development_dependency 'pry' - s.add_development_dependency 'rails', '>= 5.0' + s.add_development_dependency 'rails', '>= 5.1' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'rubocop' diff --git a/gemfiles/rails_5.0.7.gemfile b/gemfiles/rails_5.0.7.gemfile deleted file mode 100644 index ff4c4849..00000000 --- a/gemfiles/rails_5.0.7.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "5.0.7" -gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0" -gem "sqlite3", "~> 1.3.0" -gem "mysql2" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" - -gemspec path: "../" From ae0980cc90d74ad85b2e39d82898d196121ab6ec Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 19 Apr 2020 04:39:38 +0200 Subject: [PATCH 122/290] Test with latest Rails versions --- .travis.yml | 4 ++-- Appraisals | 4 ++-- README.md | 2 +- gemfiles/{rails_5.2.3.gemfile => rails_5.2.4.gemfile} | 2 +- gemfiles/{rails_6.0.1.gemfile => rails_6.0.2.gemfile} | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename gemfiles/{rails_5.2.3.gemfile => rails_5.2.4.gemfile} (92%) rename gemfiles/{rails_6.0.1.gemfile => rails_6.0.2.gemfile} (92%) diff --git a/.travis.yml b/.travis.yml index e55e1455..27a3f7e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ rvm: gemfile: - gemfiles/rails_5.1.7.gemfile - - gemfiles/rails_5.2.3.gemfile - - gemfiles/rails_6.0.1.gemfile + - gemfiles/rails_5.2.4.gemfile + - gemfiles/rails_6.0.2.gemfile services: - postgresql diff --git a/Appraisals b/Appraisals index 3ae089d8..39b9bbe2 100644 --- a/Appraisals +++ b/Appraisals @@ -7,13 +7,13 @@ RAILS_VERSIONS = { 'mysql2' => '', 'ruby-oci8' => '', }, - '5.2.3' => { + '5.2.4' => { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', 'sqlite3' => '~> 1.3.0', 'mysql2' => '', 'ruby-oci8' => '', }, - '6.0.1' => { + '6.0.2' => { 'activerecord-oracle_enhanced-adapter' => '~> 6.0.0', 'sqlite3' => '~> 1.4.0', 'mysql2' => '', diff --git a/README.md b/README.md index d41e4bd5..85c716c5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails 5.1.7 / 5.2.3 / 6.0.1 +* Rails 5.1.7 / 5.2.4 / 6.0.2 * Ruby 2.5.8 / 2.6.6 / 2.7.1 * Postgresql 9.6 * MySQL 5.6 diff --git a/gemfiles/rails_5.2.3.gemfile b/gemfiles/rails_5.2.4.gemfile similarity index 92% rename from gemfiles/rails_5.2.3.gemfile rename to gemfiles/rails_5.2.4.gemfile index d30c085e..cb28c74f 100644 --- a/gemfiles/rails_5.2.3.gemfile +++ b/gemfiles/rails_5.2.4.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "5.2.3" +gem "rails", "5.2.4" gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" gem "sqlite3", "~> 1.3.0" gem "mysql2" diff --git a/gemfiles/rails_6.0.1.gemfile b/gemfiles/rails_6.0.2.gemfile similarity index 92% rename from gemfiles/rails_6.0.1.gemfile rename to gemfiles/rails_6.0.2.gemfile index 1f7c73d3..ad38664b 100644 --- a/gemfiles/rails_6.0.1.gemfile +++ b/gemfiles/rails_6.0.2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "6.0.1" +gem "rails", "6.0.2" gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" gem "sqlite3", "~> 1.4.0" gem "mysql2" From e59df4f100f17f0c6be8f00facab5eb9a42c6abc Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 7 May 2020 01:17:48 +0200 Subject: [PATCH 123/290] Test with latest Rails version --- .travis.yml | 2 +- Appraisals | 2 +- gemfiles/{rails_6.0.2.gemfile => rails_6.0.3.gemfile} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename gemfiles/{rails_6.0.2.gemfile => rails_6.0.3.gemfile} (92%) diff --git a/.travis.yml b/.travis.yml index 27a3f7e4..297761aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ rvm: gemfile: - gemfiles/rails_5.1.7.gemfile - gemfiles/rails_5.2.4.gemfile - - gemfiles/rails_6.0.2.gemfile + - gemfiles/rails_6.0.3.gemfile services: - postgresql diff --git a/Appraisals b/Appraisals index 39b9bbe2..7937dc44 100644 --- a/Appraisals +++ b/Appraisals @@ -13,7 +13,7 @@ RAILS_VERSIONS = { 'mysql2' => '', 'ruby-oci8' => '', }, - '6.0.2' => { + '6.0.3' => { 'activerecord-oracle_enhanced-adapter' => '~> 6.0.0', 'sqlite3' => '~> 1.4.0', 'mysql2' => '', diff --git a/gemfiles/rails_6.0.2.gemfile b/gemfiles/rails_6.0.3.gemfile similarity index 92% rename from gemfiles/rails_6.0.2.gemfile rename to gemfiles/rails_6.0.3.gemfile index ad38664b..c8169539 100644 --- a/gemfiles/rails_6.0.2.gemfile +++ b/gemfiles/rails_6.0.3.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "6.0.2" +gem "rails", "6.0.3" gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" gem "sqlite3", "~> 1.4.0" gem "mysql2" From 84da1f887bd8e2271f925c709870426a78b5c7c3 Mon Sep 17 00:00:00 2001 From: Alejandro Figueroa Date: Tue, 21 Jul 2020 13:21:03 -0400 Subject: [PATCH 124/290] Add imports-loader options object imports-loader v1.1.0 changes [syntax](https://github.com/webpack-contrib/imports-loader/blob/f71a9fbb3ade447ae9cf57044814d0ca693fc96a/README.md#disable-amd-import-syntax) for disabling AMD import. --- doc/webpack.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/webpack.md b/doc/webpack.md index 55341404..70239a0c 100644 --- a/doc/webpack.md +++ b/doc/webpack.md @@ -24,7 +24,10 @@ In `config/webpack/loaders/datatables.js` : ```js module.exports = { test: /datatables\.net.*/, - loader: 'imports-loader?define=>false' + loader: 'imports-loader', + options: { + additionalCode: 'var define = false;' + } } ``` From 41cc661e8acb9fa4ae12dd862e1fb329ae79b008 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 11 Dec 2020 12:23:28 +0100 Subject: [PATCH 125/290] Rails 6.1.0 is out --- .travis.yml | 3 ++- Appraisals | 6 ++++++ ajax-datatables-rails.gemspec | 2 +- gemfiles/rails_6.1.0.gemfile | 11 +++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_6.1.0.gemfile diff --git a/.travis.yml b/.travis.yml index 297761aa..f0cf5568 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ dist: xenial language: ruby cache: bundler rvm: - - 2.7.1 + - 2.7.2 - 2.6.6 - 2.5.8 - ruby-head @@ -14,6 +14,7 @@ gemfile: - gemfiles/rails_5.1.7.gemfile - gemfiles/rails_5.2.4.gemfile - gemfiles/rails_6.0.3.gemfile + - gemfiles/rails_6.1.0.gemfile services: - postgresql diff --git a/Appraisals b/Appraisals index 7937dc44..e3b8effd 100644 --- a/Appraisals +++ b/Appraisals @@ -19,6 +19,12 @@ RAILS_VERSIONS = { 'mysql2' => '', 'ruby-oci8' => '', }, + '6.1.0' => { + 'activerecord-oracle_enhanced-adapter' => '~> 6.1.0.rc1', + 'sqlite3' => '~> 1.4.0', + 'mysql2' => '', + 'ruby-oci8' => '', + }, }.freeze RAILS_VERSIONS.each do |version, gems| diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index d849641a..dd875cf0 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'faker' s.add_development_dependency 'generator_spec' s.add_development_dependency 'guard-rspec' - s.add_development_dependency 'pg', '< 1.0' + s.add_development_dependency 'pg' s.add_development_dependency 'pry' s.add_development_dependency 'rails', '>= 5.1' s.add_development_dependency 'rake' diff --git a/gemfiles/rails_6.1.0.gemfile b/gemfiles/rails_6.1.0.gemfile new file mode 100644 index 00000000..5fe2a715 --- /dev/null +++ b/gemfiles/rails_6.1.0.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.1.0" +gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0.rc1" +gem "sqlite3", "~> 1.4.0" +gem "mysql2" +gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" + +gemspec path: "../" From a5f3e9bee8ba750d8fc8bc867f426ab5aaa18ade Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 22 Dec 2020 18:41:57 +0100 Subject: [PATCH 126/290] Goodbye Travis --- .github/workflows/ci.yml | 87 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 53 ------------------------ README.md | 2 +- spec/spec_helper.rb | 1 + 4 files changed, 89 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..0b7dd9c6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +--- +name: CI + +on: + - push + - pull_request + +jobs: + rspec: + runs-on: ubuntu-latest + + services: + postgres: + image: 'postgres:13' + ports: ['5432:5432'] + env: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: ajax_datatables_rails + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + # mariadb: + # image: 'mariadb:10.5' + # ports: ['3306:3306'] + # env: + # MYSQL_ROOT_PASSWORD: root + # MYSQL_DATABASE: ajax_datatables_rails + # options: >- + # --health-cmd 'mysqladmin ping' + # --health-interval 10s + # --health-timeout 5s + # --health-retries 3 + + strategy: + fail-fast: false + matrix: + ruby: + - 2.7.x + - 2.6.x + - 2.5.x + rails: + - rails_5.1.7 + - rails_5.2.4 + - rails_6.0.3 + - rails_6.1.0 + adapter: + - sqlite3 + - postgresql + # - mysql2 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Ruby + uses: actions/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Setup Ruby cache + uses: actions/cache@v2 + with: + path: "${GITHUB_WORKSPACE}/vendor/bundle" + key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}- + + - name: Bundle + env: + RAILS_VERSION: ${{ matrix.rails }} + DB_ADAPTER: ${{ matrix.adapter }} + run: | + export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile" + gem install bundler + bundle config path "${GITHUB_WORKSPACE}/vendor/bundle" + bundle install --jobs 4 --retry 3 + + - name: RSpec + env: + RAILS_VERSION: ${{ matrix.rails }} + DB_ADAPTER: ${{ matrix.adapter }} + run: | + export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile" + bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f0cf5568..00000000 --- a/.travis.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -os: linux -dist: xenial - -language: ruby -cache: bundler -rvm: - - 2.7.2 - - 2.6.6 - - 2.5.8 - - ruby-head - -gemfile: - - gemfiles/rails_5.1.7.gemfile - - gemfiles/rails_5.2.4.gemfile - - gemfiles/rails_6.0.3.gemfile - - gemfiles/rails_6.1.0.gemfile - -services: - - postgresql - - mysql - -addons: - postgresql: '9.6' - -before_install: - - sh -c "if [ '$DB_ADAPTER' = 'mysql2' ]; then mysql -e 'create database ajax_datatables_rails;'; fi" - - sh -c "if [ '$DB_ADAPTER' = 'postgresql' ]; then psql -c 'create database ajax_datatables_rails;' -U postgres; fi" - - sh -c "if [ '$DB_ADAPTER' = 'oracle_enhanced' ]; then ./spec/install_oracle.sh; fi" - -env: - global: - - ORACLE_COOKIE=sqldev - - ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip - - ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe - - ORACLE_SID=XE - jobs: - - DB_ADAPTER=postgresql - - DB_ADAPTER=mysql2 - - DB_ADAPTER=sqlite3 - - DB_ADAPTER=oracle_enhanced - -jobs: - allow_failures: - - rvm: ruby-head - -before_script: - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build - -after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT diff --git a/README.md b/README.md index 85c716c5..1dc013ad 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![GitHub license](https://img.shields.io/github/license/jbox-web/ajax-datatables-rails.svg)](https://github.com/jbox-web/ajax-datatables-rails/blob/master/LICENSE) [![Gem](https://img.shields.io/gem/v/ajax-datatables-rails.svg)](https://rubygems.org/gems/ajax-datatables-rails) [![Gem](https://img.shields.io/gem/dtv/ajax-datatables-rails.svg)](https://rubygems.org/gems/ajax-datatables-rails) -[![Build Status](https://travis-ci.com/jbox-web/ajax-datatables-rails.svg?branch=master)](https://travis-ci.com/jbox-web/ajax-datatables-rails) +[![CI](https://github.com/jbox-web/ajax-datatables-rails/workflows/CI/badge.svg)](https://github.com/jbox-web/ajax-datatables-rails/actions) [![Code Climate](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails) [![Test Coverage](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/coverage) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d8409949..ce3fc3a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,6 +64,7 @@ encoding: 'utf8' } +options = options.merge(host: '127.0.0.1', port: 5432, user: 'postgres', password: 'postgres') if adapter == 'postgresql' options = options.merge(username: 'root') if adapter == 'mysql2' options = options.merge(username: ENV['USER'], password: ENV['USER'], database: 'xe', host: '127.0.0.1/xe') if adapter == 'oracle_enhanced' options = options.merge(database: ':memory:') if adapter == 'sqlite3' From e1665743da74762e8a6434428bb2c8250d8a6eac Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 22 Dec 2020 19:28:37 +0100 Subject: [PATCH 127/290] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1dc013ad..f77ea82e 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ It's tested against : -* Rails 5.1.7 / 5.2.4 / 6.0.2 -* Ruby 2.5.8 / 2.6.6 / 2.7.1 -* Postgresql 9.6 +* Rails 5.1.7 / 5.2.4 / 6.0.3 / 6.1.0 +* Ruby 2.5.x / 2.6.x / 2.7.x +* SQLite3 +* Postgresql 13 * MySQL 5.6 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) -* SQLite3 ## Description From 2de4f7f7be8f72bcac743b5ca2fa6e8712051aec Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 22 Dec 2020 19:29:55 +0100 Subject: [PATCH 128/290] Restore MariaDB CI --- .github/workflows/ci.yml | 17 +++++++++++++++-- spec/spec_helper.rb | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b7dd9c6..ca1a33ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,10 @@ jobs: --health-timeout 5s --health-retries 5 + # Using docker image fails with + # invalid reference format # mariadb: - # image: 'mariadb:10.5' + # image: 'mariadb:10.3' # ports: ['3306:3306'] # env: # MYSQL_ROOT_PASSWORD: root @@ -49,7 +51,7 @@ jobs: adapter: - sqlite3 - postgresql - # - mysql2 + - mysql2 steps: - name: Checkout @@ -78,6 +80,17 @@ jobs: bundle config path "${GITHUB_WORKSPACE}/vendor/bundle" bundle install --jobs 4 --retry 3 + - name: Set DB Adapter + env: + RAILS_VERSION: ${{ matrix.rails }} + DB_ADAPTER: ${{ matrix.adapter }} + # See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql + run: | + if [ "${DB_ADAPTER}" = "mysql2" ]; then + sudo systemctl start mysql.service + mysql -u root -proot -e 'create database ajax_datatables_rails;' + fi + - name: RSpec env: RAILS_VERSION: ${{ matrix.rails }} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce3fc3a2..5d160441 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,8 +64,8 @@ encoding: 'utf8' } -options = options.merge(host: '127.0.0.1', port: 5432, user: 'postgres', password: 'postgres') if adapter == 'postgresql' -options = options.merge(username: 'root') if adapter == 'mysql2' +options = options.merge(host: '127.0.0.1', port: 5432, username: 'postgres', password: 'postgres') if adapter == 'postgresql' +options = options.merge(host: '127.0.0.1', port: 3306, username: 'root', password: 'root') if adapter == 'mysql2' options = options.merge(username: ENV['USER'], password: ENV['USER'], database: 'xe', host: '127.0.0.1/xe') if adapter == 'oracle_enhanced' options = options.merge(database: ':memory:') if adapter == 'sqlite3' From 0f536135b13dc49a94ab1da8779298b7307d3450 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 22 Dec 2020 20:06:03 +0100 Subject: [PATCH 129/290] Restore Oracle CI --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++----------- gemfiles/rails_6.1.0.gemfile | 2 +- spec/install_oracle.sh | 8 ++++---- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca1a33ce..fa7fe75b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,12 @@ jobs: rspec: runs-on: ubuntu-latest + env: + ORACLE_COOKIE: sqldev + ORACLE_FILE: oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip + ORACLE_HOME: /u01/app/oracle/product/11.2.0/xe + ORACLE_SID: XE + services: postgres: image: 'postgres:13' @@ -52,6 +58,7 @@ jobs: - sqlite3 - postgresql - mysql2 + - oracle_enhanced steps: - name: Checkout @@ -62,6 +69,25 @@ jobs: with: ruby-version: ${{ matrix.ruby }} + - name: Set DB Adapter + env: + RAILS_VERSION: ${{ matrix.rails }} + DB_ADAPTER: ${{ matrix.adapter }} + CUSTOM_ORACLE_FILE: ${{ secrets.CUSTOM_ORACLE_FILE }} + + # See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql + run: | + if [ "${DB_ADAPTER}" = "mysql2" ]; then + sudo systemctl start mysql.service + mysql -u root -proot -e 'create database ajax_datatables_rails;' + fi + + if [ "${DB_ADAPTER}" = "oracle_enhanced" ]; then + ./spec/install_oracle.sh + # Fix error : libnnz11.so: cannot open shared object file: No such file or directory + sudo ln -s ${ORACLE_HOME}/lib/libnnz11.so /usr/lib/libnnz11.so + fi + - name: Setup Ruby cache uses: actions/cache@v2 with: @@ -77,20 +103,9 @@ jobs: run: | export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile" gem install bundler - bundle config path "${GITHUB_WORKSPACE}/vendor/bundle" + # bundle config path "${GITHUB_WORKSPACE}/vendor/bundle" bundle install --jobs 4 --retry 3 - - name: Set DB Adapter - env: - RAILS_VERSION: ${{ matrix.rails }} - DB_ADAPTER: ${{ matrix.adapter }} - # See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql - run: | - if [ "${DB_ADAPTER}" = "mysql2" ]; then - sudo systemctl start mysql.service - mysql -u root -proot -e 'create database ajax_datatables_rails;' - fi - - name: RSpec env: RAILS_VERSION: ${{ matrix.rails }} diff --git a/gemfiles/rails_6.1.0.gemfile b/gemfiles/rails_6.1.0.gemfile index 5fe2a715..6161d04e 100644 --- a/gemfiles/rails_6.1.0.gemfile +++ b/gemfiles/rails_6.1.0.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "rails", "6.1.0" -gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0.rc1" +gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0" gem "sqlite3", "~> 1.4.0" gem "mysql2" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/spec/install_oracle.sh b/spec/install_oracle.sh index 44db7ded..07537f79 100755 --- a/spec/install_oracle.sh +++ b/spec/install_oracle.sh @@ -4,8 +4,8 @@ wget 'https://github.com/cbandy/travis-oracle/archive/v2.0.3.tar.gz' mkdir -p ~/.travis/oracle tar xz --strip-components 1 -C ~/.travis/oracle -f v2.0.3.tar.gz -if [ -n $CUSTOM_ORACLE_FILE ]; then - wget -q $CUSTOM_ORACLE_FILE -O ~/.travis/oracle/oracle-xe-11.2.0-1.0.x86_64.rpm.zip +if [ -n ${CUSTOM_ORACLE_FILE} ]; then + wget -q ${CUSTOM_ORACLE_FILE} -O ~/.travis/oracle/oracle-xe-11.2.0-1.0.x86_64.rpm.zip else ~/.travis/oracle/download.sh fi @@ -13,6 +13,6 @@ fi ~/.travis/oracle/install.sh # in dev env: sqlplus system/password@localhost/XE -"$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA < Date: Tue, 22 Dec 2020 23:33:54 +0100 Subject: [PATCH 130/290] Fix activerecord Oracle adapter version --- Appraisals | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Appraisals b/Appraisals index e3b8effd..d0581ec8 100644 --- a/Appraisals +++ b/Appraisals @@ -20,7 +20,7 @@ RAILS_VERSIONS = { 'ruby-oci8' => '', }, '6.1.0' => { - 'activerecord-oracle_enhanced-adapter' => '~> 6.1.0.rc1', + 'activerecord-oracle_enhanced-adapter' => '~> 6.1.0', 'sqlite3' => '~> 1.4.0', 'mysql2' => '', 'ruby-oci8' => '', From 181e40e50e01b790f9c15601ce8dcdda6b7188e0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 22 Dec 2020 23:34:32 +0100 Subject: [PATCH 131/290] Add rspec-retry to avoid false positive --- ajax-datatables-rails.gemspec | 1 + spec/spec_helper.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index dd875cf0..59043cbb 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -32,6 +32,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rails', '>= 5.1' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' + s.add_development_dependency 'rspec-retry' s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov', '~> 0.17.1' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d160441..9b6bdc58 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ require 'simplecov' require 'rspec' +require 'rspec/retry' require 'database_cleaner' require 'factory_bot' require 'faker' @@ -52,6 +53,12 @@ config.after(:each) do DatabaseCleaner.clean end + + if ENV.key?('GITHUB_ACTIONS') + config.around(:each) do |ex| + ex.run_with_retry retry: 3 + end + end end require 'ajax-datatables-rails' From 0e7d36caa3419beda6fb91367b71ea0ed04660c2 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 23 Dec 2020 00:50:14 +0100 Subject: [PATCH 132/290] Drop support of Rails 5.1.x --- .github/workflows/ci.yml | 1 - Appraisals | 6 ------ CHANGELOG.md | 2 +- README.md | 2 +- gemfiles/rails_5.1.7.gemfile | 11 ----------- 5 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 gemfiles/rails_5.1.7.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa7fe75b..45ef0ae6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,6 @@ jobs: - 2.6.x - 2.5.x rails: - - rails_5.1.7 - rails_5.2.4 - rails_6.0.3 - rails_6.1.0 diff --git a/Appraisals b/Appraisals index d0581ec8..801a5a17 100644 --- a/Appraisals +++ b/Appraisals @@ -1,12 +1,6 @@ # frozen_string_literal: true RAILS_VERSIONS = { - '5.1.7' => { - 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', - 'sqlite3' => '~> 1.3.0', - 'mysql2' => '', - 'ruby-oci8' => '', - }, '5.2.4' => { 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', 'sqlite3' => '~> 1.3.0', diff --git a/CHANGELOG.md b/CHANGELOG.md index 021c7754..3684e5ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.3.0 (to come) -* Drop support of Rails 5.0.x +* Drop support of Rails 5.0.x and 5.1.x * Drop support of Ruby 2.4 ## 1.2.0 (2020-04-19) diff --git a/README.md b/README.md index f77ea82e..8affe290 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails 5.1.7 / 5.2.4 / 6.0.3 / 6.1.0 +* Rails 5.2.4 / 6.0.3 / 6.1.0 * Ruby 2.5.x / 2.6.x / 2.7.x * SQLite3 * Postgresql 13 diff --git a/gemfiles/rails_5.1.7.gemfile b/gemfiles/rails_5.1.7.gemfile deleted file mode 100644 index 4dc08389..00000000 --- a/gemfiles/rails_5.1.7.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "5.1.7" -gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" -gem "sqlite3", "~> 1.3.0" -gem "mysql2" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" - -gemspec path: "../" From 18353be80620cab0dc62361328685feb81a81748 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 23 Dec 2020 00:59:46 +0100 Subject: [PATCH 133/290] Amend CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3684e5ee..6df0283a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ * Use [zeitwerk](https://github.com/fxn/zeitwerk) to load gem files * Add binstubs to ease development -This is the last version to support Rails 5.0.x and Ruby 2.4.x. +This is the last version to support Rails 5.0.x, Rails 5.1.x and Ruby 2.4.x. ## 1.1.0 (2019-12-12) From 9cd82aec2e2f6cf1f3aa841c9f353ea7e2590e96 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 23 Dec 2020 01:07:44 +0100 Subject: [PATCH 134/290] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8affe290..bb94465a 100644 --- a/README.md +++ b/README.md @@ -317,7 +317,7 @@ def additional_data end ``` -Very useful with https://github.com/vedmack/yadcf to provide values for dropdown filters. +Very useful with [datatables-factory](https://github.com/jbox-web/datatables-factory) (or [yadcf](https://github.com/vedmack/yadcf)) to provide values for dropdown filters. ### 4) Setup the Controller action @@ -656,7 +656,7 @@ See [DefaultScope is evil](https://rails-bestpractices.com/posts/2013/06/15/defa ### DateRange search -This feature works with [yadcf](https://github.com/vedmack/yadcf). +This feature works with [datatables-factory](https://github.com/jbox-web/datatables-factory) (or [yadcf](https://github.com/vedmack/yadcf)). To enable the date range search, for example `created_at` : @@ -827,9 +827,9 @@ end ## Tutorial -You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to). Its real world example. +You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to) or [here](https://github.com/jbox-web/ajax-datatables-rails-sample-project). Its real world examples. -Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277) +Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277#issuecomment-366526373) Use [has_scope](https://github.com/plataformatec/has_scope) gem with `ajax-datatables-rails` : [#280](https://github.com/jbox-web/ajax-datatables-rails/issues/280) From 80c2e34ce8f50aba86147867928cae0678184757 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 23 Dec 2020 00:37:42 +0100 Subject: [PATCH 135/290] Make db_adapter config per datatable --- CHANGELOG.md | 1 + README.md | 42 +++++++++---------- lib/ajax-datatables-rails.rb | 2 +- lib/ajax-datatables-rails/base.rb | 2 + lib/ajax-datatables-rails/configuration.rb | 1 - lib/ajax-datatables-rails/datatable/column.rb | 2 +- .../datatable/simple_order.rb | 6 ++- .../templates/ajax_datatables_rails_config.rb | 6 +-- .../configuration_spec.rb | 34 --------------- .../datatable/column_spec.rb | 20 ++++----- .../datatable/simple_order_spec.rb | 14 ++++--- .../orm/active_record_sort_records_spec.rb | 4 +- spec/spec_helper.rb | 10 ----- spec/support/test_helpers.rb | 4 +- 14 files changed, 51 insertions(+), 97 deletions(-) delete mode 100644 spec/ajax-datatables-rails/configuration_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df0283a..a807d001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Drop support of Rails 5.0.x and 5.1.x * Drop support of Ruby 2.4 +* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) ## 1.2.0 (2020-04-19) diff --git a/README.md b/README.md index bb94465a..41c243b6 100644 --- a/README.md +++ b/README.md @@ -95,29 +95,7 @@ You can install jQuery DataTables : * with [Rails webpacker gem](https://github.com/rails/webpacker) (see [here](/doc/webpack.md) for more infos) -## Configuration - -Generate the `ajax-datatables-rails` config file with this command : - -```sh -$ bundle exec rails generate datatable:config -``` - -Doing so, will create the `config/initializers/ajax_datatables_rails.rb` file with the following content : - -```ruby -AjaxDatatablesRails.configure do |config| - # available options for db_adapter are: :pg, :mysql, :mysql2, :sqlite, :sqlite3 - # config.db_adapter = :pg - - # Or you can use your rails environment adapter if you want a generic dev and production - # config.db_adapter = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym -end -``` - -Uncomment the `config.db_adapter` line and set the corresponding value to your database and gem. This is all you need. - -#### Note +## Note Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for performing database queries. @@ -541,6 +519,24 @@ class UnrespondedMessagesDatatable < AjaxDatatablesRails::ActiveRecord end ``` +### Change the DB adapter for a datatable class + +If you have models from different databases you can set the `db_adapter` on the datatable class : + +```ruby +class MySharedModelDatatable < AjaxDatatablesRails::ActiveRecord + self.db_adapter = :oracle_enhanced + + # ... other methods (view_columns, data...) + + def get_raw_records + AnimalsRecord.connected_to(role: :reading) do + Dog.all + end + end +end +``` + ### Columns syntax You can mix several model in the same datatable. diff --git a/lib/ajax-datatables-rails.rb b/lib/ajax-datatables-rails.rb index a051bd43..1036689c 100644 --- a/lib/ajax-datatables-rails.rb +++ b/lib/ajax-datatables-rails.rb @@ -16,7 +16,7 @@ module AjaxDatatablesRails # Configure AjaxDatatablesRails global settings # # AjaxDatatablesRails.configure do |config| - # config.db_adapter = :postgresql + # config.nulls_last = true # end def self.configure diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index c124e2df..6be3cc01 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -3,6 +3,8 @@ module AjaxDatatablesRails class Base + class_attribute :db_adapter, default: ActiveRecord::Base.connection.adapter_name.downcase.to_sym + attr_reader :params, :options, :datatable GLOBAL_SEARCH_DELIMITER = ' ' diff --git a/lib/ajax-datatables-rails/configuration.rb b/lib/ajax-datatables-rails/configuration.rb index 7c6d6ab3..eb6d100b 100644 --- a/lib/ajax-datatables-rails/configuration.rb +++ b/lib/ajax-datatables-rails/configuration.rb @@ -4,7 +4,6 @@ module AjaxDatatablesRails class Configuration include ActiveSupport::Configurable - config_accessor(:db_adapter) { :postgresql } config_accessor(:nulls_last) { false } end end diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 10544d01..062ce92a 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -72,7 +72,7 @@ def formatted_value private def type_cast - @type_cast ||= DB_ADAPTER_TYPE_CAST.fetch(AjaxDatatablesRails.config.db_adapter, TYPE_CAST_DEFAULT) + @type_cast ||= DB_ADAPTER_TYPE_CAST.fetch(datatable.db_adapter, TYPE_CAST_DEFAULT) end def casted_column diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index a5725228..2a093c09 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -42,13 +42,15 @@ def sort_nulls_last? def nulls_last_sql return unless sort_nulls_last? - case AjaxDatatablesRails.config.db_adapter + adapter = @datatable.datatable.db_adapter + + case adapter when :pg, :postgresql, :postgres, :oracle 'NULLS LAST' when :mysql, :mysql2, :sqlite, :sqlite3 'IS NULL' else - raise 'unsupported database adapter' + raise "unsupported database adapter: #{adapter}" end end diff --git a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb index aa2544fd..0199aef8 100644 --- a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +++ b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true AjaxDatatablesRails.configure do |config| - # available options for db_adapter are: :pg, :mysql, :mysql2, :sqlite, :sqlite3 - # config.db_adapter = :pg - - # Or you can use your rails environment adapter if you want a generic dev and production - # config.db_adapter = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym + # config.nulls_last = true end diff --git a/spec/ajax-datatables-rails/configuration_spec.rb b/spec/ajax-datatables-rails/configuration_spec.rb deleted file mode 100644 index df547c95..00000000 --- a/spec/ajax-datatables-rails/configuration_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'spec_helper' - -describe AjaxDatatablesRails do - describe 'configurations' do - context 'configurable from outside' do - before(:each) do - AjaxDatatablesRails.configure do |config| - config.db_adapter = :mysql - end - end - - it 'should have custom value' do - expect(AjaxDatatablesRails.config.db_adapter).to eq(:mysql) - end - end - end -end - -describe AjaxDatatablesRails::Configuration do - let(:config) { AjaxDatatablesRails::Configuration.new } - - describe 'default config' do - it 'default db_adapter should :postgresql' do - expect(config.db_adapter).to eq(:postgresql) - end - end - - describe 'custom config' do - it 'should accept db_adapter custom value' do - config.db_adapter = :mysql - expect(config.db_adapter).to eq(:mysql) - end - end -end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 472bbc52..8051f89d 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -153,52 +153,52 @@ let(:column) { datatable.datatable.columns.first } it 'returns VARCHAR if :db_adapter is :pg' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :pg } + expect(datatable).to receive(:db_adapter) { :pg } expect(column.send(:type_cast)).to eq('VARCHAR') end it 'returns VARCHAR if :db_adapter is :postgre' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgre } + expect(datatable).to receive(:db_adapter) { :postgre } expect(column.send(:type_cast)).to eq('VARCHAR') end it 'returns VARCHAR if :db_adapter is :postgresql' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgresql } + expect(datatable).to receive(:db_adapter) { :postgresql } expect(column.send(:type_cast)).to eq('VARCHAR') end it 'returns VARCHAR2(4000) if :db_adapter is :oracle' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracle } + expect(datatable).to receive(:db_adapter) { :oracle } expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') end it 'returns VARCHAR2(4000) if :db_adapter is :oracleenhanced' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracleenhanced } + expect(datatable).to receive(:db_adapter) { :oracleenhanced } expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') end it 'returns CHAR if :db_adapter is :mysql2' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql2 } + expect(datatable).to receive(:db_adapter) { :mysql2 } expect(column.send(:type_cast)).to eq('CHAR') end it 'returns CHAR if :db_adapter is :mysql' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql } + expect(datatable).to receive(:db_adapter) { :mysql } expect(column.send(:type_cast)).to eq('CHAR') end it 'returns TEXT if :db_adapter is :sqlite' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite } + expect(datatable).to receive(:db_adapter) { :sqlite } expect(column.send(:type_cast)).to eq('TEXT') end it 'returns TEXT if :db_adapter is :sqlite3' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite3 } + expect(datatable).to receive(:db_adapter) { :sqlite3 } expect(column.send(:type_cast)).to eq('TEXT') end it 'returns VARCHAR(4000) if :db_adapter is :sqlserver' do - allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlserver } + expect(datatable).to receive(:db_adapter) { :sqlserver } expect(column.send(:type_cast)).to eq('VARCHAR(4000)') end end diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 28f20058..111f0646 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -2,7 +2,8 @@ describe AjaxDatatablesRails::Datatable::SimpleOrder do - let(:datatable) { ComplexDatatable.new(sample_params).datatable } + let(:parent) { ComplexDatatable.new(sample_params) } + let(:datatable) { parent.datatable } let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'column' => '1', 'dir' => 'desc'}) } let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) } @@ -21,17 +22,18 @@ skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' expect(simple_order.query('email')).to eq( - "email DESC #{nulls_last_sql}" + "email DESC #{nulls_last_sql(parent)}" ) end end describe 'using column option' do - let(:sorted_datatable) { DatatableOrderNullsLast.new(sample_params).datatable } + let(:parent) { DatatableOrderNullsLast.new(sample_params) } + let(:sorted_datatable) { parent.datatable } let(:nulls_last_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(sorted_datatable, options) } context 'with postgres database adapter' do - before { AjaxDatatablesRails.config.db_adapter = :pg } + before { parent.db_adapter = :pg } it 'sql query' do expect(nulls_last_order.query('email')).to eq('email DESC NULLS LAST') @@ -39,7 +41,7 @@ end context 'with sqlite database adapter' do - before { AjaxDatatablesRails.config.db_adapter = :sqlite } + before { parent.db_adapter = :sqlite } it 'sql query' do expect(nulls_last_order.query('email')).to eq('email DESC IS NULL') @@ -47,7 +49,7 @@ end context 'with mysql database adapter' do - before { AjaxDatatablesRails.config.db_adapter = :mysql } + before { parent.db_adapter = :mysql } it 'sql query' do expect(nulls_last_order.query('email')).to eq('email DESC IS NULL') diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index 1c0e8cad..15365ded 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -56,7 +56,7 @@ datatable.params[:order]['0'] = { column: '0', dir: 'asc' } datatable.params[:order]['1'] = { column: '1', dir: 'desc' } expect(datatable.sort_records(records).to_sql).to include( - "ORDER BY users.username ASC #{nulls_last_sql}, users.email DESC #{nulls_last_sql}" + "ORDER BY users.username ASC #{nulls_last_sql(datatable)}, users.email DESC #{nulls_last_sql(datatable)}" ) end end @@ -70,7 +70,7 @@ nulls_last_datatable.params[:order]['0'] = { column: '0', dir: 'asc' } nulls_last_datatable.params[:order]['1'] = { column: '1', dir: 'desc' } expect(nulls_last_datatable.sort_records(records).to_sql).to include( - "ORDER BY users.username ASC, users.email DESC #{nulls_last_sql}" + "ORDER BY users.username ASC, users.email DESC #{nulls_last_sql(datatable)}" ) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9b6bdc58..e57521f6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,12 +22,6 @@ FactoryBot.find_definitions end - config.after(:each) do - AjaxDatatablesRails.configure do |c| - c.db_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym - end - end - config.color = true config.fail_fast = false @@ -78,10 +72,6 @@ ActiveRecord::Base.establish_connection(options) -AjaxDatatablesRails.configure do |c| - c.db_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym -end - load File.dirname(__FILE__) + '/support/schema.rb' load File.dirname(__FILE__) + '/support/test_helpers.rb' load File.dirname(__FILE__) + '/support/datatable_cond_date.rb' diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index bb7e26db..026a7a04 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -98,8 +98,8 @@ def data end end -def nulls_last_sql - case AjaxDatatablesRails.config.db_adapter +def nulls_last_sql(datatable) + case datatable.db_adapter when :pg, :postgresql, :postgres, :oracle "NULLS LAST" when :mysql, :mysql2, :sqlite, :sqlite3 From 414d1699d3b90e8b9b30499882e280e884a03976 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 23 Dec 2020 06:09:37 +0100 Subject: [PATCH 136/290] Update README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41c243b6..a5830047 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ The final goal of this gem is to **generate a JSON** content that will be given All the datatable customizations (header, tr, td, css classes, width, height, buttons, etc...) **must** take place in the [javascript definition](#5-wire-up-the-javascript) of the datatable. jQuery DataTables is a very powerful tool with a lot of customizations available. Take the time to [read the doc](https://datatables.net/reference/option/). +You'll find a sample project here : https://ajax-datatables-rails.herokuapp.com + +Its real world examples. The code is here : https://github.com/jbox-web/ajax-datatables-rails-sample-project ## Warnings @@ -823,8 +826,6 @@ end ## Tutorial -You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to) or [here](https://github.com/jbox-web/ajax-datatables-rails-sample-project). Its real world examples. - Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277#issuecomment-366526373) Use [has_scope](https://github.com/plataformatec/has_scope) gem with `ajax-datatables-rails` : [#280](https://github.com/jbox-web/ajax-datatables-rails/issues/280) From 75f3072254b92f8539106e8e38fe59724a7aec38 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 30 Dec 2020 23:23:02 +0100 Subject: [PATCH 137/290] Ruby 3.0 is out \o/ --- .github/workflows/ci.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45ef0ae6..ab19cfeb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,9 +46,10 @@ jobs: fail-fast: false matrix: ruby: - - 2.7.x - - 2.6.x - - 2.5.x + - '3.0' + - '2.7' + - '2.6' + - '2.5' rails: - rails_5.2.4 - rails_6.0.3 @@ -58,13 +59,16 @@ jobs: - postgresql - mysql2 - oracle_enhanced + exclude: + - ruby: '3.0' + rails: rails_5.2.4 steps: - name: Checkout uses: actions/checkout@v2 - name: Setup Ruby - uses: actions/setup-ruby@v1 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} From 33f7334b14940e40080af15705e4b97cdc00ae33 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 00:18:31 +0100 Subject: [PATCH 138/290] Use ubuntu-20.04 in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab19cfeb..ae76b071 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: jobs: rspec: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 env: ORACLE_COOKIE: sqldev From 60814d8bbaeb9c0a7b0aa4c93846e1b58e8f3983 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 01:14:34 +0100 Subject: [PATCH 139/290] Add missing modules for JRuby --- lib/ajax-datatables-rails/datatable.rb | 6 ++++++ lib/ajax-datatables-rails/orm.rb | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 lib/ajax-datatables-rails/datatable.rb create mode 100644 lib/ajax-datatables-rails/orm.rb diff --git a/lib/ajax-datatables-rails/datatable.rb b/lib/ajax-datatables-rails/datatable.rb new file mode 100644 index 00000000..739e07b0 --- /dev/null +++ b/lib/ajax-datatables-rails/datatable.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + module Datatable + end +end diff --git a/lib/ajax-datatables-rails/orm.rb b/lib/ajax-datatables-rails/orm.rb new file mode 100644 index 00000000..9334b847 --- /dev/null +++ b/lib/ajax-datatables-rails/orm.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + module ORM + end +end From 389593ad7ef68674019cc7a0298c198922308fa9 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 01:30:59 +0100 Subject: [PATCH 140/290] Improve Rubocop config --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 92689c89..13b824c4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ AllCops: + NewCops: enable + SuggestExtensions: false TargetRubyVersion: 2.5 Exclude: - bin/* From 8ddde044f8c9e6f2f0bd5290f1c2822fe3e2c1d1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 01:32:30 +0100 Subject: [PATCH 141/290] Deprecate Array style for columns --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a5830047..c090e8a0 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,8 @@ def data end end ``` -You can either use the v0.3 Array style for your columns : + +**Deprecated:** You can either use the v0.3 Array style for your columns : This method builds a 2d array that is used by datatables to construct the html table. Insert the values you want on each column. From fb565835fc26d1b10847e21a7c478c975702447b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 01:49:12 +0100 Subject: [PATCH 142/290] Make AjaxDatatablesRails::Base#connected_columns, #searchable_columns and #search_columns private --- lib/ajax-datatables-rails/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 6be3cc01..111724d2 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -43,6 +43,8 @@ def records @records ||= retrieve_records end + private + # helper methods def connected_columns @connected_columns ||= begin @@ -64,8 +66,6 @@ def search_columns end end - private - def sanitize_data(data) data.map do |record| if record.is_a?(Array) From 3828392ae72741b2143cc60868f039778fcb7563 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:05:14 +0100 Subject: [PATCH 143/290] Add comments --- lib/ajax-datatables-rails/base.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 111724d2..69fce3a6 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -15,6 +15,7 @@ def initialize(params, options = {}) @datatable = Datatable::Datatable.new(self) end + # User defined methods def view_columns raise(NotImplementedError, view_columns_error_text) end @@ -27,10 +28,12 @@ def data raise(NotImplementedError, data_error_text) end + # User overides def additional_data {} end + # JSON structure sent to jQuery DataTables def as_json(*) { recordsTotal: records_total_count, From 17aa050bca617ff8829354cf629d918920f3e95c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:07:46 +0100 Subject: [PATCH 144/290] Make AjaxDatatablesRails::Base#records private --- lib/ajax-datatables-rails/base.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 69fce3a6..7200aaf2 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -42,10 +42,6 @@ def as_json(*) }.merge(additional_data) end - def records - @records ||= retrieve_records - end - private # helper methods @@ -79,6 +75,10 @@ def sanitize_data(data) end end + def records + @records ||= retrieve_records + end + def retrieve_records records = fetch_records records = filter_records(records) From 44fe02364eab4a4ac4a33422f16990ea19bed69f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:10:41 +0100 Subject: [PATCH 145/290] Reorganize AjaxDatatablesRails::Base specs --- spec/ajax-datatables-rails/base_spec.rb | 57 +++++++++++++------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index a28318d0..354c7141 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -13,7 +13,7 @@ end end - context 'Public API' do + describe 'User API' do describe '#view_columns' do it 'raises an error if not defined by the user' do datatable = described_class.new(sample_params) @@ -81,33 +81,9 @@ end end end + end - describe '#as_json' do - let(:datatable) { ComplexDatatable.new(sample_params) } - - it 'should return a hash' do - create_list(:user, 5) - data = datatable.as_json - expect(data[:recordsTotal]).to eq 5 - expect(data[:recordsFiltered]).to eq 5 - expect(data[:data]).to be_a(Array) - expect(data[:data].size).to eq 5 - end - - context 'with additional_data' do - it 'should return a hash' do - create_list(:user, 5) - expect(datatable).to receive(:additional_data){ { foo: 'bar' } } - data = datatable.as_json - expect(data[:recordsTotal]).to eq 5 - expect(data[:recordsFiltered]).to eq 5 - expect(data[:data]).to be_a(Array) - expect(data[:data].size).to eq 5 - expect(data[:foo]).to eq 'bar' - end - end - end - + describe 'ORM API' do describe '#filter_records' do let(:records) { User.all } @@ -160,6 +136,33 @@ def paginate_records(records) end end + describe 'JSON format' do + describe '#as_json' do + let(:datatable) { ComplexDatatable.new(sample_params) } + + it 'should return a hash' do + create_list(:user, 5) + data = datatable.as_json + expect(data[:recordsTotal]).to eq 5 + expect(data[:recordsFiltered]).to eq 5 + expect(data[:data]).to be_a(Array) + expect(data[:data].size).to eq 5 + end + + context 'with additional_data' do + it 'should return a hash' do + create_list(:user, 5) + expect(datatable).to receive(:additional_data){ { foo: 'bar' } } + data = datatable.as_json + expect(data[:recordsTotal]).to eq 5 + expect(data[:recordsFiltered]).to eq 5 + expect(data[:data]).to be_a(Array) + expect(data[:data].size).to eq 5 + expect(data[:foo]).to eq 'bar' + end + end + end + end context 'Private API' do context 'when orm is not implemented' do From d696982df06cad48465ebb7edf7889c83d0d37ca Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:14:26 +0100 Subject: [PATCH 146/290] Add comment --- lib/ajax-datatables-rails/base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 7200aaf2..9c0a5fa6 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -75,6 +75,7 @@ def sanitize_data(data) end end + # called from within #data def records @records ||= retrieve_records end From 39942163b7a92f1f59d1870755566a9e4ac746d4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:16:27 +0100 Subject: [PATCH 147/290] Make AjaxDatatablesRails::Base#column_id and #column_data public --- lib/ajax-datatables-rails/base.rb | 19 +++++++++-------- spec/ajax-datatables-rails/base_spec.rb | 28 +++++++++++++------------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 9c0a5fa6..605f8afe 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -42,6 +42,16 @@ def as_json(*) }.merge(additional_data) end + # User helper methods + def column_id(name) + view_columns.keys.index(name.to_sym) + end + + def column_data(column) + id = column_id(column) + params.dig('columns', id.to_s, 'search', 'value') + end + private # helper methods @@ -100,15 +110,6 @@ def global_search_delimiter GLOBAL_SEARCH_DELIMITER end - def column_id(name) - view_columns.keys.index(name.to_sym) - end - - def column_data(column) - id = column_id(column) - params.dig('columns', id.to_s, 'search', 'value') - end - def raw_records_error_text <<-ERROR diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 354c7141..c9174647 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -225,24 +225,26 @@ def paginate_records(records) expect(datatable.datatable.send(:per_page)).to eq(20) end end + end + end - describe '#column_id' do - let(:datatable) { ComplexDatatable.new(sample_params) } + describe 'User helper methods' do + describe '#column_id' do + let(:datatable) { ComplexDatatable.new(sample_params) } - it 'should return column id from view_columns hash' do - expect(datatable.send(:column_id, :username)).to eq(0) - expect(datatable.send(:column_id, 'username')).to eq(0) - end + it 'should return column id from view_columns hash' do + expect(datatable.column_id(:username)).to eq(0) + expect(datatable.column_id('username')).to eq(0) end + end - describe '#column_data' do - let(:datatable) { ComplexDatatable.new(sample_params) } - before { datatable.params[:columns]['0'][:search][:value] = 'doe' } + describe '#column_data' do + let(:datatable) { ComplexDatatable.new(sample_params) } + before { datatable.params[:columns]['0'][:search][:value] = 'doe' } - it 'should return column data from params' do - expect(datatable.send(:column_data, :username)).to eq('doe') - expect(datatable.send(:column_data, 'username')).to eq('doe') - end + it 'should return column data from params' do + expect(datatable.column_data(:username)).to eq('doe') + expect(datatable.column_data('username')).to eq('doe') end end end From 2c547cbc56b2b1aaa03faf57a5eb87537d75a42a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:37:59 +0100 Subject: [PATCH 148/290] Move tests --- spec/ajax-datatables-rails/base_spec.rb | 34 ------------ .../datatable/datatable_spec.rb | 52 ++++++++++++++----- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index c9174647..25c7df47 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -192,40 +192,6 @@ def paginate_records(records) end end end - - describe 'helper methods' do - describe '#offset' do - it 'defaults to 0' do - datatable = described_class.new({}) - expect(datatable.datatable.send(:offset)).to eq(0) - end - - it 'matches the value on view params[:start]' do - datatable = described_class.new({ start: '11' }) - expect(datatable.datatable.send(:offset)).to eq(11) - end - end - - describe '#page' do - it 'calculates page number from params[:start] and #per_page' do - datatable = described_class.new({ start: '11' }) - expect(datatable.datatable.send(:page)).to eq(2) - end - end - - describe '#per_page' do - it 'defaults to 10' do - datatable = described_class.new(sample_params) - expect(datatable.datatable.send(:per_page)).to eq(10) - end - - it 'matches the value on view params[:length]' do - other_view = { length: 20 } - datatable = described_class.new(other_view) - expect(datatable.datatable.send(:per_page)).to eq(20) - end - end - end end describe 'User helper methods' do diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index aa8a5185..c1b4981d 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -3,9 +3,10 @@ describe AjaxDatatablesRails::Datatable::Datatable do let(:datatable) { ComplexDatatable.new(sample_params).datatable } - let(:order_option) { {'0'=>{'column'=>'0', 'dir'=>'asc'}, '1'=>{'column'=>'1', 'dir'=>'desc'}} } describe 'order methods' do + let(:order_option) { {'0'=>{'column'=>'0', 'dir'=>'asc'}, '1'=>{'column'=>'1', 'dir'=>'desc'}} } + it 'should be orderable' do expect(datatable.orderable?).to eq(true) end @@ -62,25 +63,50 @@ end describe 'option methods' do - before :each do - datatable.options[:start] = '50' - datatable.options[:length] = '15' + describe '#paginate?' do + it { + expect(datatable.paginate?).to be(true) + } end - it 'paginate?' do - expect(datatable.paginate?).to be(true) - end + describe '#per_page' do + context 'when params[:length] is missing' do + it 'defaults to 10' do + expect(datatable.per_page).to eq(10) + end + end + + context 'when params[:length] is passed' do + let(:datatable) { ComplexDatatable.new({ length: '20' }).datatable } - it 'offset' do - expect(datatable.offset).to eq(50) + it 'matches the value on view params[:length]' do + expect(datatable.per_page).to eq(20) + end + end end - it 'page' do - expect(datatable.page).to eq(4) + describe '#offset' do + context 'when params[:start] is missing' do + it 'defaults to 0' do + expect(datatable.offset).to eq(0) + end + end + + context 'when params[:start] is passed' do + let(:datatable) { ComplexDatatable.new({ start: '11' }).datatable } + + it 'matches the value on view params[:start]' do + expect(datatable.offset).to eq(11) + end + end end - it 'per_page' do - expect(datatable.per_page).to eq(15) + describe '#page' do + let(:datatable) { ComplexDatatable.new({ start: '11' }).datatable } + + it 'calculates page number from params[:start] and #per_page' do + expect(datatable.page).to eq(2) + end end end end From 16c0e019318efd8ac9bcf9e3c40a574aaf82189f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:40:09 +0100 Subject: [PATCH 149/290] Improve tests on AjaxDatatablesRails::Base --- lib/ajax-datatables-rails/base.rb | 17 +++ .../orm/active_record.rb | 4 - spec/ajax-datatables-rails/base_spec.rb | 112 ++++++++---------- 3 files changed, 66 insertions(+), 67 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 605f8afe..dbba832a 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -28,6 +28,23 @@ def data raise(NotImplementedError, data_error_text) end + # ORM defined methods + def fetch_records + get_raw_records + end + + def filter_records(records) + raise(NotImplementedError) + end + + def sort_records(records) + raise(NotImplementedError) + end + + def paginate_records(records) + raise(NotImplementedError) + end + # User overides def additional_data {} diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index c81b504f..600dc4ad 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -4,10 +4,6 @@ module AjaxDatatablesRails module ORM module ActiveRecord - def fetch_records - get_raw_records - end - def filter_records(records) records.where(build_conditions) end diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 25c7df47..c98bf581 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -84,54 +84,70 @@ end describe 'ORM API' do - describe '#filter_records' do - let(:records) { User.all } + context 'when ORM is not implemented' do + let(:datatable) { AjaxDatatablesRails::Base.new(sample_params) } - let(:datatable) do - datatable = Class.new(ComplexDatatable) do - def filter_records(records) - raise NotImplementedError - end + describe '#fetch_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.fetch_records }.to raise_error NotImplementedError end - datatable.new(sample_params) end - it 'should allow method override' do - expect { datatable.filter_records(records) }.to raise_error(NotImplementedError) + describe '#filter_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.filter_records([]) }.to raise_error NotImplementedError + end end - end - - describe '#sort_records' do - let(:records) { User.all } - let(:datatable) do - datatable = Class.new(ComplexDatatable) do - def sort_records(records) - raise NotImplementedError - end + describe '#sort_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.sort_records([]) }.to raise_error NotImplementedError end - datatable.new(sample_params) end - it 'should allow method override' do - expect { datatable.sort_records(records) }.to raise_error(NotImplementedError) + describe '#paginate_records' do + it 'raises an error if it does not include an ORM module' do + expect { datatable.paginate_records([]) }.to raise_error NotImplementedError + end end end - describe '#paginate_records' do - let(:records) { User.all } - - let(:datatable) do - datatable = Class.new(ComplexDatatable) do - def paginate_records(records) - raise NotImplementedError + context 'when ORM is implemented' do + describe 'it allows method override' do + let(:datatable) do + datatable = Class.new(ComplexDatatable) do + def filter_records(records) + raise NotImplementedError.new('FOO') + end + + def sort_records(records) + raise NotImplementedError.new('FOO') + end + + def paginate_records(records) + raise NotImplementedError.new('FOO') + end end + datatable.new(sample_params) end - datatable.new(sample_params) - end - it 'should allow method override' do - expect { datatable.paginate_records(records) }.to raise_error(NotImplementedError) + describe '#filter_records' do + it { + expect { datatable.filter_records([]) }.to raise_error(NotImplementedError).with_message('FOO') + } + end + + describe '#sort_records' do + it { + expect { datatable.sort_records([]) }.to raise_error(NotImplementedError).with_message('FOO') + } + end + + describe '#paginate_records' do + it { + expect { datatable.paginate_records([]) }.to raise_error(NotImplementedError).with_message('FOO') + } + end end end end @@ -164,36 +180,6 @@ def paginate_records(records) end end - context 'Private API' do - context 'when orm is not implemented' do - let(:datatable) { AjaxDatatablesRails::Base.new(sample_params) } - - describe '#fetch_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.fetch_records }.to raise_error NoMethodError - end - end - - describe '#filter_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.filter_records }.to raise_error NoMethodError - end - end - - describe '#sort_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.sort_records }.to raise_error NoMethodError - end - end - - describe '#paginate_records' do - it 'raises an error if it does not include an ORM module' do - expect { datatable.paginate_records }.to raise_error NoMethodError - end - end - end - end - describe 'User helper methods' do describe '#column_id' do let(:datatable) { ComplexDatatable.new(sample_params) } From 6ebcf1a20d4b5fccbf58317ac2f5a93cd2ee8428 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 02:57:51 +0100 Subject: [PATCH 150/290] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a807d001..ece64c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,12 @@ * Drop support of Rails 5.0.x and 5.1.x * Drop support of Ruby 2.4 +* Add support of Rails 6.1 +* Add support of Ruby 3.0 +* Switch from Travis to Github Actions +* Improve specs * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) +* Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371)) ## 1.2.0 (2020-04-19) From 0a32d5f86befc3ef2480e4450e2cc2157e5d9e3e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 03:40:48 +0100 Subject: [PATCH 151/290] Improve spec organization in active_record_filter_records_spec --- .../orm/active_record_filter_records_spec.rb | 538 +++++++++--------- 1 file changed, 272 insertions(+), 266 deletions(-) diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index a15202b4..7bc24697 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -183,372 +183,378 @@ end describe 'filter conditions' do - describe 'it can filter records with condition :date_range' do - let(:datatable) { DatatableCondDate.new(sample_params) } + context 'date condition' do + describe 'it can filter records with condition :date_range' do + let(:datatable) { DatatableCondDate.new(sample_params) } - before(:each) do - create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000') - create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000') - end - - context 'when range is empty' do - it 'should not filter records' do - datatable.params[:columns]['5'][:search][:value] = '-' - expect(datatable.data.size).to eq 2 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' - end - end - - context 'when start date is filled' do - it 'should filter records created after this date' do - datatable.params[:columns]['5'][:search][:value] = '31/12/1999-' - expect(datatable.data.size).to eq 2 - end - end - - context 'when end date is filled' do - it 'should filter records created before this date' do - datatable.params[:columns]['5'][:search][:value] = '-31/12/1999' - expect(datatable.data.size).to eq 0 - end - end - - context 'when both date are filled' do - it 'should filter records created between the range' do - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' - expect(datatable.data.size).to eq 1 + before(:each) do + create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000') + create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000') end - end - context 'when another filter is active' do context 'when range is empty' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' + it 'should not filter records' do datatable.params[:columns]['5'][:search][:value] = '-' - expect(datatable.data.size).to eq 1 + expect(datatable.data.size).to eq 2 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' end end context 'when start date is filled' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' + it 'should filter records created after this date' do + datatable.params[:columns]['5'][:search][:value] = '31/12/1999-' + expect(datatable.data.size).to eq 2 end end context 'when end date is filled' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '-15/01/2000' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' + it 'should filter records created before this date' do + datatable.params[:columns]['5'][:search][:value] = '-31/12/1999' + expect(datatable.data.size).to eq 0 end end context 'when both date are filled' do - it 'should filter records' do - datatable.params[:columns]['0'][:search][:value] = 'doe' + it 'should filter records created between the range' do datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'Doe' end end - end - end - describe 'it can filter records with condition :start_with' do - let(:datatable) { DatatableCondStartWith.new(sample_params) } + context 'when another filter is active' do + context 'when range is empty' do + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' + datatable.params[:columns]['5'][:search][:value] = '-' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' + end + end + + context 'when start date is filled' do + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' + datatable.params[:columns]['5'][:search][:value] = '01/12/1999-' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' + end + end - before(:each) do - create(:user, first_name: 'John') - create(:user, first_name: 'Mary') - end + context 'when end date is filled' do + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' + datatable.params[:columns]['5'][:search][:value] = '-15/01/2000' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' + end + end - it 'should filter records matching' do - datatable.params[:columns]['2'][:search][:value] = 'Jo' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'John' + context 'when both date are filled' do + it 'should filter records' do + datatable.params[:columns]['0'][:search][:value] = 'doe' + datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'Doe' + end + end + end end end - describe 'it can filter records with condition :end_with' do - let(:datatable) { DatatableCondEndWith.new(sample_params) } - - before(:each) do - create(:user, last_name: 'JOHN') - create(:user, last_name: 'MARY') - end + context 'numeric condition' do + describe 'it can filter records with condition :eq' do + let(:datatable) { DatatableCondEq.new(sample_params) } - if ENV['DB_ADAPTER'] == 'oracle_enhanced' - context 'when db_adapter is oracleenhanced' do - it 'should filter records matching' do - datatable.params[:columns]['3'][:search][:value] = 'RY' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'MARY' - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) end - else + it 'should filter records matching' do - datatable.params[:columns]['3'][:search][:value] = 'ry' + datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first - expect(item[:last_name]).to eq 'MARY' + expect(item[:first_name]).to eq 'john' end end - end - describe 'it can filter records with condition :like' do - let(:datatable) { DatatableCondLike.new(sample_params) } + describe 'it can filter records with condition :not_eq' do + let(:datatable) { DatatableCondNotEq.new(sample_params) } - before(:each) do - create(:user, email: 'john@foo.com') - create(:user, email: 'mary@bar.com') - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end - it 'should filter records matching' do - datatable.params[:columns]['1'][:search][:value] = 'foo' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:email]).to eq 'john@foo.com' + it 'should filter records matching' do + datatable.params[:columns]['4'][:search][:value] = 1 + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:first_name]).to eq 'mary' + end end - end - describe 'it can filter records with condition :string_eq' do - let(:datatable) { DatatableCondStringEq.new(sample_params) } + describe 'it can filter records with condition :lt' do + let(:datatable) { DatatableCondLt.new(sample_params) } - before(:each) do - create(:user, email: 'john@foo.com') - create(:user, email: 'mary@bar.com') - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end - it 'should filter records matching' do - datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:email]).to eq 'john@foo.com' + it 'should filter records matching' do + datatable.params[:columns]['4'][:search][:value] = 2 + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:first_name]).to eq 'john' + end end - end - describe 'it can filter records with condition :string_in' do - let(:datatable) { DatatableCondStringIn.new(sample_params) } + describe 'it can filter records with condition :gt' do + let(:datatable) { DatatableCondGt.new(sample_params) } - before(:each) do - create(:user, email: 'john@foo.com') - create(:user, email: 'mary@bar.com') - create(:user, email: 'henry@baz.com') - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end - it 'should filter records matching' do - datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:email]).to eq 'john@foo.com' + it 'should filter records matching' do + datatable.params[:columns]['4'][:search][:value] = 1 + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:first_name]).to eq 'mary' + end end - it 'should filter records matching with multiple' do - datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry@baz.com' - expect(datatable.data.size).to eq 2 - items = datatable.data.sort_by { |h| h[:email] } - item_first = items.first - item_last = items.last - expect(item_first[:email]).to eq 'henry@baz.com' - expect(item_last[:email]).to eq 'john@foo.com' - end + describe 'it can filter records with condition :lteq' do + let(:datatable) { DatatableCondLteq.new(sample_params) } + + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end - it 'should filter records matching with multiple contains not found' do - datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry_not@baz.com' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:email]).to eq 'john@foo.com' + it 'should filter records matching' do + datatable.params[:columns]['4'][:search][:value] = 2 + expect(datatable.data.size).to eq 2 + end end - end - describe 'it can filter records with condition :null_value' do - let(:datatable) { DatatableCondNullValue.new(sample_params) } + describe 'it can filter records with condition :gteq' do + let(:datatable) { DatatableCondGteq.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', email: 'foo@bar.com') - create(:user, first_name: 'mary', email: nil) - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end - context 'when condition is NULL' do it 'should filter records matching' do - datatable.params[:columns]['1'][:search][:value] = 'NULL' - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'mary' + datatable.params[:columns]['4'][:search][:value] = 1 + expect(datatable.data.size).to eq 2 end end - context 'when condition is !NULL' do + describe 'it can filter records with condition :in' do + let(:datatable) { DatatableCondIn.new(sample_params) } + + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end + it 'should filter records matching' do - datatable.params[:columns]['1'][:search][:value] = '!NULL' + datatable.params[:columns]['4'][:search][:value] = [1] expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:first_name]).to eq 'john' end end - end - describe 'it can filter records with condition :eq' do - let(:datatable) { DatatableCondEq.new(sample_params) } + describe 'it can filter records with condition :in with regex' do + let(:datatable) { DatatableCondInWithRegex.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'john' + it 'should filter records matching' do + datatable.params[:columns]['4'][:search][:value] = '1|2' + datatable.params[:order]['0'] = { column: '4', dir: 'asc' } + expect(datatable.data.size).to eq 2 + item = datatable.data.first + expect(item[:first_name]).to eq 'john' + end end - end - describe 'it can filter records with condition :not_eq' do - let(:datatable) { DatatableCondNotEq.new(sample_params) } + describe 'Integer overflows' do + let(:datatable) { DatatableCondEq.new(sample_params) } + let(:largest_postgresql_integer_value) { 2147483647 } + let(:smallest_postgresql_integer_value) { -2147483648 } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'mary' - end - end + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value) + end - describe 'it can filter records with condition :lt' do - let(:datatable) { DatatableCondLt.new(sample_params) } + it 'Returns an empty result if input value is too large' do + datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + 1 + expect(datatable.data.size).to eq 0 + end - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + it 'Returns an empty result if input value is too small' do + datatable.params[:columns]['4'][:search][:value] = smallest_postgresql_integer_value - 1 + expect(datatable.data.size).to eq 0 + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = 2 - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'john' + it 'returns the matching user' do + datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + expect(datatable.data.size).to eq 1 + end end end - describe 'it can filter records with condition :gt' do - let(:datatable) { DatatableCondGt.new(sample_params) } + context 'string condition' do + describe 'it can filter records with condition :start_with' do + let(:datatable) { DatatableCondStartWith.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + before(:each) do + create(:user, first_name: 'John') + create(:user, first_name: 'Mary') + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'mary' + it 'should filter records matching' do + datatable.params[:columns]['2'][:search][:value] = 'Jo' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:first_name]).to eq 'John' + end end - end - describe 'it can filter records with condition :lteq' do - let(:datatable) { DatatableCondLteq.new(sample_params) } + describe 'it can filter records with condition :end_with' do + let(:datatable) { DatatableCondEndWith.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + before(:each) do + create(:user, last_name: 'JOHN') + create(:user, last_name: 'MARY') + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = 2 - expect(datatable.data.size).to eq 2 + if ENV['DB_ADAPTER'] == 'oracle_enhanced' + context 'when db_adapter is oracleenhanced' do + it 'should filter records matching' do + datatable.params[:columns]['3'][:search][:value] = 'RY' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'MARY' + end + end + else + it 'should filter records matching' do + datatable.params[:columns]['3'][:search][:value] = 'ry' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'MARY' + end + end end - end - describe 'it can filter records with condition :gteq' do - let(:datatable) { DatatableCondGteq.new(sample_params) } + describe 'it can filter records with condition :like' do + let(:datatable) { DatatableCondLike.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + before(:each) do + create(:user, email: 'john@foo.com') + create(:user, email: 'mary@bar.com') + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 - expect(datatable.data.size).to eq 2 + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'foo' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end end - end - describe 'it can filter records with condition :in' do - let(:datatable) { DatatableCondIn.new(sample_params) } + describe 'it can filter records with condition :string_eq' do + let(:datatable) { DatatableCondStringEq.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + before(:each) do + create(:user, email: 'john@foo.com') + create(:user, email: 'mary@bar.com') + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = [1] - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:first_name]).to eq 'john' + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end end - end - describe 'it can filter records with condition :in with regex' do - let(:datatable) { DatatableCondInWithRegex.new(sample_params) } + describe 'it can filter records with condition :string_in' do + let(:datatable) { DatatableCondStringIn.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end + before(:each) do + create(:user, email: 'john@foo.com') + create(:user, email: 'mary@bar.com') + create(:user, email: 'henry@baz.com') + end - it 'should filter records matching' do - datatable.params[:columns]['4'][:search][:value] = '1|2' - datatable.params[:order]['0'] = { column: '4', dir: 'asc' } - expect(datatable.data.size).to eq 2 - item = datatable.data.first - expect(item[:first_name]).to eq 'john' - end - end + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end - describe 'Integer overflows' do - let(:datatable) { DatatableCondEq.new(sample_params) } - let(:largest_postgresql_integer_value) { 2147483647 } - let(:smallest_postgresql_integer_value) { -2147483648 } + it 'should filter records matching with multiple' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry@baz.com' + expect(datatable.data.size).to eq 2 + items = datatable.data.sort_by { |h| h[:email] } + item_first = items.first + item_last = items.last + expect(item_first[:email]).to eq 'henry@baz.com' + expect(item_last[:email]).to eq 'john@foo.com' + end - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value) + it 'should filter records matching with multiple contains not found' do + datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry_not@baz.com' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:email]).to eq 'john@foo.com' + end end - it 'Returns an empty result if input value is too large' do - datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + 1 - expect(datatable.data.size).to eq 0 - end + describe 'it can filter records with condition :null_value' do + let(:datatable) { DatatableCondNullValue.new(sample_params) } - it 'Returns an empty result if input value is too small' do - datatable.params[:columns]['4'][:search][:value] = smallest_postgresql_integer_value - 1 - expect(datatable.data.size).to eq 0 - end + before(:each) do + create(:user, first_name: 'john', email: 'foo@bar.com') + create(:user, first_name: 'mary', email: nil) + end + + context 'when condition is NULL' do + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = 'NULL' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:first_name]).to eq 'mary' + end + end - it 'returns the matching user' do - datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value - expect(datatable.data.size).to eq 1 + context 'when condition is !NULL' do + it 'should filter records matching' do + datatable.params[:columns]['1'][:search][:value] = '!NULL' + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:first_name]).to eq 'john' + end + end end end end From 4792df29159a217fda904df57ca38c94c939cfa6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 03:43:11 +0100 Subject: [PATCH 152/290] Add spec for "cond: " --- .../orm/active_record_filter_records_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 7bc24697..9cf83877 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -420,6 +420,25 @@ end end + context 'proc condition' do + describe 'it can filter records with lambda/proc condition' do + let(:datatable) { DatatableCondProc.new(sample_params) } + + before(:each) do + create(:user, username: 'johndoe', email: 'johndoe@example.com') + create(:user, username: 'johndie', email: 'johndie@example.com') + create(:user, username: 'msmith', email: 'mary.smith@example.com') + end + + it 'should filter records matching' do + datatable.params[:columns]['0'][:search][:value] = 'john' + expect(datatable.data.size).to eq 2 + item = datatable.data.first + expect(item[:username]).to eq 'johndie' + end + end + end + context 'string condition' do describe 'it can filter records with condition :start_with' do let(:datatable) { DatatableCondStartWith.new(sample_params) } From 1e31e319e83d579c3e4d88711b0a52a75bc8e6bd Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 03:54:50 +0100 Subject: [PATCH 153/290] Make some internal constants private --- lib/ajax-datatables-rails/datatable/column.rb | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 062ce92a..591a69e3 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -4,29 +4,12 @@ module AjaxDatatablesRails module Datatable class Column - TYPE_CAST_DEFAULT = 'VARCHAR' - TYPE_CAST_MYSQL = 'CHAR' - TYPE_CAST_SQLITE = 'TEXT' - TYPE_CAST_ORACLE = 'VARCHAR2(4000)' - TYPE_CAST_SQLSERVER = 'VARCHAR(4000)' - - DB_ADAPTER_TYPE_CAST = { - mysql: TYPE_CAST_MYSQL, - mysql2: TYPE_CAST_MYSQL, - sqlite: TYPE_CAST_SQLITE, - sqlite3: TYPE_CAST_SQLITE, - oracle: TYPE_CAST_ORACLE, - oracleenhanced: TYPE_CAST_ORACLE, - sqlserver: TYPE_CAST_SQLSERVER, - }.freeze - - attr_reader :datatable, :index, :options - attr_writer :search - include Search include Order include DateFilter + attr_reader :datatable, :index, :options + attr_writer :search def initialize(datatable, index, options) @datatable = datatable @@ -71,6 +54,29 @@ def formatted_value private + TYPE_CAST_DEFAULT = 'VARCHAR' + TYPE_CAST_MYSQL = 'CHAR' + TYPE_CAST_SQLITE = 'TEXT' + TYPE_CAST_ORACLE = 'VARCHAR2(4000)' + TYPE_CAST_SQLSERVER = 'VARCHAR(4000)' + + DB_ADAPTER_TYPE_CAST = { + mysql: TYPE_CAST_MYSQL, + mysql2: TYPE_CAST_MYSQL, + sqlite: TYPE_CAST_SQLITE, + sqlite3: TYPE_CAST_SQLITE, + oracle: TYPE_CAST_ORACLE, + oracleenhanced: TYPE_CAST_ORACLE, + sqlserver: TYPE_CAST_SQLSERVER, + }.freeze + + private_constant :TYPE_CAST_DEFAULT + private_constant :TYPE_CAST_MYSQL + private_constant :TYPE_CAST_SQLITE + private_constant :TYPE_CAST_ORACLE + private_constant :TYPE_CAST_SQLSERVER + private_constant :DB_ADAPTER_TYPE_CAST + def type_cast @type_cast ||= DB_ADAPTER_TYPE_CAST.fetch(datatable.db_adapter, TYPE_CAST_DEFAULT) end From 2bfe295ab51ff730c9ba37154a491654110aabf6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 04:18:48 +0100 Subject: [PATCH 154/290] Fix https://github.com/jbox-web/ajax-datatables-rails/issues/372 --- lib/ajax-datatables-rails/orm/active_record.rb | 2 +- .../orm/active_record_filter_records_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index 600dc4ad..ad258d44 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -39,7 +39,7 @@ def build_conditions_for_datatable crit << searchable_columns.map do |simple_column| simple_column.search = search simple_column.search_query - end.reduce(:or) + end.compact.reduce(:or) end.compact.reduce(:and) criteria end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 9cf83877..07dc20f2 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -106,6 +106,20 @@ expect(results).not_to include('msmith') end end + + context 'when column.search_query returns nil' do + let(:datatable) { DatatableCondUnknown.new(sample_params) } + + before(:each) do + datatable.params[:search] = { value: 'john doe', regex: 'false' } + end + + it 'does not raise error' do + expect { + datatable.data.size + }.to_not raise_error + end + end end end From fb9fd4d28afdb82cbeb0af64159222efe466de20 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 04:21:19 +0100 Subject: [PATCH 155/290] Raise error on unknown view column 'cond:' params --- CHANGELOG.md | 1 + lib/ajax-datatables-rails/datatable/column.rb | 22 +++++++++++++++++++ .../datatable/column/search.rb | 4 ++-- lib/ajax-datatables-rails/error.rb | 8 +++++++ .../orm/active_record_filter_records_spec.rb | 17 ++++++++++++++ spec/spec_helper.rb | 1 + spec/support/datatable_cond_unknown.rb | 5 +++++ 7 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 lib/ajax-datatables-rails/error.rb create mode 100644 spec/support/datatable_cond_unknown.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index ece64c2c..eb4a29b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Improve specs * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) * Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371)) +* Raise an error when column's `cond:` setting is unknown ## 1.2.0 (2020-04-19) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 591a69e3..179ee580 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -16,6 +16,7 @@ def initialize(datatable, index, options) @index = index @options = options @view_column = datatable.view_columns[options[:data].to_sym] + validate_settings! end def data @@ -85,6 +86,27 @@ def casted_column @casted_column ||= ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(type_cast)]) end + def validate_settings! + raise AjaxDatatablesRails::Error::InvalidSearchCondition, cond unless valid_search_condition?(cond) + end + + VALID_SEARCH_CONDITIONS = [ + # String condition + :start_with, :end_with, :like, :string_eq, :string_in, :null_value, + # Numeric condition + :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in, + # Date condition + :date_range + ] + + private_constant :VALID_SEARCH_CONDITIONS + + def valid_search_condition?(cond) + return true if cond.is_a?(Proc) + + VALID_SEARCH_CONDITIONS.include?(cond) + end + end end end diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index bd12d170..7c89be72 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -61,8 +61,6 @@ def non_regex_search filter when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in searchable_integer? ? raw_search(cond) : empty_search - when :null_value - null_value_search when :start_with casted_column.matches("#{formatted_value}%") when :end_with @@ -73,6 +71,8 @@ def non_regex_search raw_search(:eq) when :string_in raw_search(:in) + when :null_value + null_value_search when :date_range date_range_search end diff --git a/lib/ajax-datatables-rails/error.rb b/lib/ajax-datatables-rails/error.rb new file mode 100644 index 00000000..22a2665a --- /dev/null +++ b/lib/ajax-datatables-rails/error.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + module Error + class BaseError < StandardError; end + class InvalidSearchCondition < BaseError; end + end +end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 07dc20f2..e43cd64b 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -107,6 +107,7 @@ end end + # TODO: improve (or delete?) this test context 'when column.search_query returns nil' do let(:datatable) { DatatableCondUnknown.new(sample_params) } @@ -115,6 +116,8 @@ end it 'does not raise error' do + allow_any_instance_of(AjaxDatatablesRails::Datatable::Column).to receive(:valid_search_condition?).and_return(true) + expect { datatable.data.size }.to_not raise_error @@ -590,5 +593,19 @@ end end end + + context 'unknown condition' do + let(:datatable) { DatatableCondUnknown.new(sample_params) } + + before(:each) do + datatable.params[:search] = { value: 'john doe', regex: 'false' } + end + + it 'should raise error' do + expect { + datatable.data.size + }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchCondition).with_message('foo') + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e57521f6..65889acb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -78,5 +78,6 @@ load File.dirname(__FILE__) + '/support/datatable_cond_numeric.rb' load File.dirname(__FILE__) + '/support/datatable_cond_proc.rb' load File.dirname(__FILE__) + '/support/datatable_cond_string.rb' +load File.dirname(__FILE__) + '/support/datatable_cond_unknown.rb' load File.dirname(__FILE__) + '/support/datatable_order_nulls_last.rb' require File.dirname(__FILE__) + '/support/test_models.rb' diff --git a/spec/support/datatable_cond_unknown.rb b/spec/support/datatable_cond_unknown.rb new file mode 100644 index 00000000..3894eb39 --- /dev/null +++ b/spec/support/datatable_cond_unknown.rb @@ -0,0 +1,5 @@ +class DatatableCondUnknown < ComplexDatatable + def view_columns + super.deep_merge(username: { cond: :foo }) + end +end From 888388deba57b7c87f30c03dbd399a5264536066 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 04:41:21 +0100 Subject: [PATCH 156/290] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb4a29b3..bdd88956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) * Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371)) * Raise an error when column's `cond:` setting is unknown +* Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258)) ## 1.2.0 (2020-04-19) From 93f753fe2647f932a70d462f6f6695722418f1a7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 04:57:16 +0100 Subject: [PATCH 157/290] Improve encapsulation --- lib/ajax-datatables-rails/datatable/datatable.rb | 8 ++++++-- lib/ajax-datatables-rails/datatable/simple_order.rb | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index bf5f3118..78e84253 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -4,7 +4,7 @@ module AjaxDatatablesRails module Datatable class Datatable - attr_reader :datatable, :options + attr_reader :options def initialize(datatable) @datatable = datatable @@ -41,7 +41,7 @@ def search def columns @columns ||= get_param(:columns).map do |index, column_options| - Column.new(datatable, index, column_options) + Column.new(@datatable, index, column_options) end end @@ -73,6 +73,10 @@ def get_param(param) options[param].to_unsafe_h.with_indifferent_access end + def db_adapter + @datatable.db_adapter + end + end end end diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 2a093c09..6d9cb005 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -11,6 +11,7 @@ class SimpleOrder def initialize(datatable, options = {}) @datatable = datatable @options = options + @adapter = datatable.db_adapter end def query(sort_column) @@ -42,15 +43,13 @@ def sort_nulls_last? def nulls_last_sql return unless sort_nulls_last? - adapter = @datatable.datatable.db_adapter - - case adapter + case @adapter when :pg, :postgresql, :postgres, :oracle 'NULLS LAST' when :mysql, :mysql2, :sqlite, :sqlite3 'IS NULL' else - raise "unsupported database adapter: #{adapter}" + raise "unsupported database adapter: #{@adapter}" end end From 03bf755aba5c86b1eba8b2cce6271938ac5cf1f8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 05:16:27 +0100 Subject: [PATCH 158/290] Update README --- README.md | 36 +++--------------------------------- doc/migrate.md | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c090e8a0..5baa3ef8 100644 --- a/README.md +++ b/README.md @@ -42,38 +42,6 @@ You'll find a sample project here : https://ajax-datatables-rails.herokuapp.com Its real world examples. The code is here : https://github.com/jbox-web/ajax-datatables-rails-sample-project -## Warnings - -**Breaking changes :** - -1) the *v1.0.0* version is a **major break** from *v0.4*. - -* Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228)) -* The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods. - -To mitigate this 2 changes see the [migration doc](/doc/migrate.md). - -2) the *v0.4* version is a **major break** from *v0.3*. - -The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). - -It also brings a new (more natural) way of defining columns, based on hash definitions (and not arrays) and add some filtering options for column search. - -[See below](#3-customize-the-generated-datatables-class) for more infos. - -To migrate on the v0.4 you'll need to : - -* update your DataTables classes to remove all the `extend` directives -* switch to hash definitions of `view_columns` -* update your views to declare your columns bindings ([See here](#5-wire-up-the-javascript)) - - -## Documentation version - -This documentation is about the `v1.x.x` release (master branch) of this gem. - -You can still have access to the `v0.4.x` documentation on the [v0.4.x branch](https://github.com/jbox-web/ajax-datatables-rails/tree/v0.4.x). - ## Installation @@ -185,7 +153,7 @@ def view_columns @view_columns ||= { id: { source: "User.id" }, first_name: { source: "User.first_name", cond: :like, searchable: true, orderable: true }, - last_name: { source: "User.last_name", cond: :like }, + last_name: { source: "User.last_name", cond: :like, nulls_last: true }, email: { source: "User.email" }, bio: { source: "User.bio" }, } @@ -202,6 +170,8 @@ end * `:null_value` for nil field * `Proc` for whatever (see [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to/blob/master/app/datatables/city_datatable.rb) for real example) +The `nulls_last` param allows for nulls to be ordered last. + See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models. You can customize or sanitize the search value passed to the DB by using the `:formatter` option with a lambda : diff --git a/doc/migrate.md b/doc/migrate.md index bad82db0..a2b33a2f 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,5 +1,10 @@ ## To migrate from `v0.4.x` to `v1.0.0` +The *v1.0.0* version is a **major break** from *v0.4*. + +* Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228)) +* The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods. + 1) To mitigate the first change (Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord`) Create a new `ApplicationDatatable` class and make all your classes inherits from it : @@ -51,3 +56,17 @@ end This way, you can still use `def_delegators` in your datatables [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-helpers). Note that the recommanded way is to use [Draper gem](https://github.com/drapergem/draper) to separate filtering logic from view/presentation logic [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-decorators). + +## To migrate from `v0.3.x` to `v0.4.x` + +The *v0.4* version is a **major break** from *v0.3*. + +The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). + +It also brings a new (more natural) way of defining columns, based on hash definitions (and not arrays) and add some filtering options for column search. + +To migrate on the v0.4 you'll need to : + +* update your DataTables classes to remove all the `extend` directives +* switch to hash definitions of `view_columns` +* update your views to declare your columns bindings ([See here](https://github.com/jbox-web/ajax-datatables-rails#5-wire-up-the-javascript)) From b18aebaadccc2397c2739ee36405161bac3611e0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 05:19:34 +0100 Subject: [PATCH 159/290] Update README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5baa3ef8..8848142f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It's tested against : * Ruby 2.5.x / 2.6.x / 2.7.x * SQLite3 * Postgresql 13 -* MySQL 5.6 +* MySQL 8 * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) ## Description @@ -166,9 +166,9 @@ end * `:like`, `:start_with`, `:end_with`, `:string_eq`, `:string_in` for string or full text search * `:eq`, `:not_eq`, `:lt`, `:gt`, `:lteq`, `:gteq`, `:in` for numeric -* `:date_range` for date range (only for Rails > 4.2.x, see [here](#daterange-search)) +* `:date_range` for date range * `:null_value` for nil field -* `Proc` for whatever (see [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to/blob/master/app/datatables/city_datatable.rb) for real example) +* `Proc` for whatever (see [here](https://github.com/jbox-web/ajax-datatables-rails-sample-project/blob/master/app/datatables/city_datatable.rb) for real example) The `nulls_last` param allows for nulls to be ordered last. From 6e2b3a3b09240d1bd60c44b2e0c5172d97e287a3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 05:23:01 +0100 Subject: [PATCH 160/290] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8848142f..dfd6a275 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ If you'd be interested in contributing to speed development, please [open an iss ## Quick start (in 5 steps) The following examples assume that we are setting up `ajax-datatables-rails` for an index page of users from a `User` model, -and that we are using Postgresql as our db, because you **should be using it**. (It also works with other DB, see above, just be sure to have [configured the right adapter](#configuration)) +and that we are using Postgresql as our db, because you **should be using it**. (It also works with other DB, [see above](#change-the-db-adapter-for-a-datatable-class)) The goal is to render a users table and display : `id`, `first name`, `last name`, `email`, and `bio` for each user. From 30a1f7eb30bc231c2d08231d9f27d9086ea8ec73 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 05:43:05 +0100 Subject: [PATCH 161/290] Add Rubygem metadata --- ajax-datatables-rails.gemspec | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 59043cbb..d3a7c8f5 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -12,6 +12,12 @@ Gem::Specification.new do |s| s.summary = 'A gem that simplifies using datatables and hundreds of records via ajax' s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app" s.license = 'MIT' + s.metadata = { + 'homepage_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', + 'changelog_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/blob/master/CHANGELOG.md', + 'source_code_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', + 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues' + } s.required_ruby_version = '>= 2.5.0' From 244f0ddc37e4cb7f0f9a6c367d86ff725129dfa7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 18:40:05 +0100 Subject: [PATCH 162/290] Rais >= 5.2 is required --- ajax-datatables-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index d3a7c8f5..8403945f 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -35,7 +35,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'guard-rspec' s.add_development_dependency 'pg' s.add_development_dependency 'pry' - s.add_development_dependency 'rails', '>= 5.1' + s.add_development_dependency 'rails', '>= 5.2' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'rspec-retry' From e72fef122451e96ffafb38620a34f35c82427e04 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 05:04:01 +0100 Subject: [PATCH 163/290] Remove global nulls_last settings. It's defined by class now. --- CHANGELOG.md | 7 +++++- README.md | 10 +++++++- ajax-datatables-rails.gemspec | 1 - doc/migrate.md | 25 +++++++++++++++++++ lib/ajax-datatables-rails.rb | 16 ------------ lib/ajax-datatables-rails/base.rb | 1 + lib/ajax-datatables-rails/configuration.rb | 9 ------- .../datatable/datatable.rb | 4 +++ .../datatable/simple_order.rb | 9 ++++--- .../datatable/simple_order_spec.rb | 6 ++--- .../orm/active_record_sort_records_spec.rb | 4 +-- 11 files changed, 55 insertions(+), 37 deletions(-) delete mode 100644 lib/ajax-datatables-rails/configuration.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd88956..02511ad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,16 @@ * Add support of Ruby 3.0 * Switch from Travis to Github Actions * Improve specs -* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) * Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371)) * Raise an error when column's `cond:` setting is unknown * Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258)) +* `AjaxDatatablesRails.config` is removed with no replacement. The gem is now configless :) +* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) +* `AjaxDatatablesRails.config.nulls_last=` is removed and is configured per datatable class now (or by column). It defaults to false. + +To mitigate this 3 changes see the [migration doc](/doc/migrate.md). + ## 1.2.0 (2020-04-19) * Drop support of Rails 4.x diff --git a/README.md b/README.md index dfd6a275..faa8efbe 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,15 @@ end * `:null_value` for nil field * `Proc` for whatever (see [here](https://github.com/jbox-web/ajax-datatables-rails-sample-project/blob/master/app/datatables/city_datatable.rb) for real example) -The `nulls_last` param allows for nulls to be ordered last. +The `nulls_last` param allows for nulls to be ordered last. You can configure it by column, like above, or by datatable class : + +```ruby +class MyDatatable < AjaxDatatablesRails::ActiveRecord + self.nulls_last = true + + # ... other methods (view_columns, data...) +end +``` See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models. diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 8403945f..ec1dc852 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_runtime_dependency 'railties', '>= 5.1' s.add_runtime_dependency 'zeitwerk' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' diff --git a/doc/migrate.md b/doc/migrate.md index a2b33a2f..de12ff99 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,3 +1,28 @@ +## To migrate from `v1.0.x` to `v1.3.0` + +The *v1.3.0* version has some breaking changes : + +* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) + +This change is transparent for everyone. Just remove `AjaxDatatablesRails.config.db_adapter=` from your configuration (if exists) and it should work fine. + +Now you can use AjaxDatatablesRails in multi-db environments. + +* `AjaxDatatablesRails.config.nulls_last=` is removed and is configured per datatable class now (or by column). It defaults to false. + +This change is easy to mitigate : add `self.nulls_last = true` in [`ApplicationDatatable`](https://github.com/jbox-web/ajax-datatables-rails#create-a-master-parent-class-easy) and remove `AjaxDatatablesRails.config.nulls_last=` + +```ruby +class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord + self.nulls_last = true + # puts commonly used methods here +end +``` + +* `AjaxDatatablesRails.config` is removed with no replacement + +Fix the two changes above and remove any configuration file about AjaxDatatablesRails. The gem is now configless :) + ## To migrate from `v0.4.x` to `v1.0.0` The *v1.0.0* version is a **major break** from *v0.4*. diff --git a/lib/ajax-datatables-rails.rb b/lib/ajax-datatables-rails.rb index 1036689c..05d6fff1 100644 --- a/lib/ajax-datatables-rails.rb +++ b/lib/ajax-datatables-rails.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'active_support/configurable' - require 'zeitwerk' loader = Zeitwerk::Loader.for_gem generators = "#{__dir__}/generators" @@ -13,18 +11,4 @@ loader.setup module AjaxDatatablesRails - # Configure AjaxDatatablesRails global settings - # - # AjaxDatatablesRails.configure do |config| - # config.nulls_last = true - # end - - def self.configure - yield @config ||= AjaxDatatablesRails::Configuration.new - end - - # AjaxDatatablesRails global settings - def self.config - @config ||= AjaxDatatablesRails::Configuration.new - end end diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index dbba832a..b852c147 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -4,6 +4,7 @@ module AjaxDatatablesRails class Base class_attribute :db_adapter, default: ActiveRecord::Base.connection.adapter_name.downcase.to_sym + class_attribute :nulls_last, default: false attr_reader :params, :options, :datatable diff --git a/lib/ajax-datatables-rails/configuration.rb b/lib/ajax-datatables-rails/configuration.rb deleted file mode 100644 index eb6d100b..00000000 --- a/lib/ajax-datatables-rails/configuration.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module AjaxDatatablesRails - class Configuration - include ActiveSupport::Configurable - - config_accessor(:nulls_last) { false } - end -end diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index 78e84253..9c4daa28 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -77,6 +77,10 @@ def db_adapter @datatable.db_adapter end + def nulls_last + @datatable.nulls_last + end + end end end diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 6d9cb005..69366e83 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -9,9 +9,10 @@ class SimpleOrder DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC].freeze def initialize(datatable, options = {}) - @datatable = datatable - @options = options - @adapter = datatable.db_adapter + @datatable = datatable + @options = options + @adapter = datatable.db_adapter + @nulls_last = datatable.nulls_last end def query(sort_column) @@ -37,7 +38,7 @@ def column_direction end def sort_nulls_last? - column.nulls_last? || AjaxDatatablesRails.config.nulls_last == true + column.nulls_last? || @nulls_last == true end def nulls_last_sql diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 111f0646..55239d74 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -14,9 +14,9 @@ end describe 'option methods with nulls last' do - describe 'using global option' do - before { AjaxDatatablesRails.config.nulls_last = true } - after { AjaxDatatablesRails.config.nulls_last = false } + describe 'using class option' do + before { parent.nulls_last = true } + after { parent.nulls_last = false } it 'sql query' do skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index 15365ded..fb10879b 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -45,8 +45,8 @@ end describe '#sort_records with nulls last using global config' do - before { AjaxDatatablesRails.config.nulls_last = true } - after { AjaxDatatablesRails.config.nulls_last = false } + before { datatable.nulls_last = true } + after { datatable.nulls_last = false } it 'can handle multiple sorting columns' do skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' From 578e62b7b3afdad8f059a64f80d3761cf0bd6e40 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 05:50:46 +0100 Subject: [PATCH 164/290] Remove useless config generator --- lib/generators/datatable/config_generator.rb | 19 ------------------- .../templates/ajax_datatables_rails_config.rb | 5 ----- 2 files changed, 24 deletions(-) delete mode 100644 lib/generators/datatable/config_generator.rb delete mode 100644 lib/generators/datatable/templates/ajax_datatables_rails_config.rb diff --git a/lib/generators/datatable/config_generator.rb b/lib/generators/datatable/config_generator.rb deleted file mode 100644 index 33558cb1..00000000 --- a/lib/generators/datatable/config_generator.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'rails/generators' - -module Datatable - module Generators - class ConfigGenerator < ::Rails::Generators::Base - source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates')) - desc <<~DESC - Description: - Creates an initializer file for AjaxDatatablesRails configuration at config/initializers. - DESC - - def copy_config_file - template 'ajax_datatables_rails_config.rb', 'config/initializers/ajax_datatables_rails.rb' - end - end - end -end diff --git a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb deleted file mode 100644 index 0199aef8..00000000 --- a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -AjaxDatatablesRails.configure do |config| - # config.nulls_last = true -end From 672cccf150489ce8cbbcfb29acaa8458cb3e6f9a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 31 Dec 2020 18:48:45 +0100 Subject: [PATCH 165/290] Move test --- spec/ajax-datatables-rails/extended_spec.rb | 19 ------------------- .../orm/active_record_filter_records_spec.rb | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 spec/ajax-datatables-rails/extended_spec.rb diff --git a/spec/ajax-datatables-rails/extended_spec.rb b/spec/ajax-datatables-rails/extended_spec.rb deleted file mode 100644 index c5d35284..00000000 --- a/spec/ajax-datatables-rails/extended_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe AjaxDatatablesRails::Base do - describe 'it can transform search value before asking the database' do - let(:datatable) { DatatableWithFormater.new(sample_params) } - - before(:each) do - create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'DOE') - create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'SMITH') - datatable.params[:columns]['3'][:search][:value] = 'doe' - end - - it 'should filter records' do - expect(datatable.data.size).to eq 1 - item = datatable.data.first - expect(item[:last_name]).to eq 'DOE' - end - end -end diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 3518e38c..d1722ad6 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -631,4 +631,20 @@ end end end + + describe 'formatter option' do + let(:datatable) { DatatableWithFormater.new(sample_params) } + + before(:each) do + create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'DOE') + create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'SMITH') + datatable.params[:columns]['3'][:search][:value] = 'doe' + end + + it 'can transform search value before asking the database' do + expect(datatable.data.size).to eq 1 + item = datatable.data.first + expect(item[:last_name]).to eq 'DOE' + end + end end From 56554e6490961900b0583ef88c9e7cc5e9567848 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 1 Jan 2021 17:06:21 +0100 Subject: [PATCH 166/290] Improve spec helpers organization --- spec/spec_helper.rb | 10 +---- spec/support/datatables/complex_datatable.rb | 29 ++++++++++++ .../datatables/complex_datatable_array.rb | 14 ++++++ .../{ => datatables}/datatable_cond_date.rb | 0 .../datatable_cond_numeric.rb | 0 .../{ => datatables}/datatable_cond_proc.rb | 0 .../{ => datatables}/datatable_cond_string.rb | 0 .../datatable_cond_unknown.rb | 0 .../datatable_order_nulls_last.rb | 0 .../{test_helpers.rb => helpers/params.rb} | 45 ------------------- .../{test_models.rb => models/user.rb} | 0 11 files changed, 44 insertions(+), 54 deletions(-) create mode 100644 spec/support/datatables/complex_datatable.rb create mode 100644 spec/support/datatables/complex_datatable_array.rb rename spec/support/{ => datatables}/datatable_cond_date.rb (100%) rename spec/support/{ => datatables}/datatable_cond_numeric.rb (100%) rename spec/support/{ => datatables}/datatable_cond_proc.rb (100%) rename spec/support/{ => datatables}/datatable_cond_string.rb (100%) rename spec/support/{ => datatables}/datatable_cond_unknown.rb (100%) rename spec/support/{ => datatables}/datatable_order_nulls_last.rb (100%) rename spec/support/{test_helpers.rb => helpers/params.rb} (64%) rename spec/support/{test_models.rb => models/user.rb} (100%) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 65889acb..ff968c07 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -72,12 +72,4 @@ ActiveRecord::Base.establish_connection(options) -load File.dirname(__FILE__) + '/support/schema.rb' -load File.dirname(__FILE__) + '/support/test_helpers.rb' -load File.dirname(__FILE__) + '/support/datatable_cond_date.rb' -load File.dirname(__FILE__) + '/support/datatable_cond_numeric.rb' -load File.dirname(__FILE__) + '/support/datatable_cond_proc.rb' -load File.dirname(__FILE__) + '/support/datatable_cond_string.rb' -load File.dirname(__FILE__) + '/support/datatable_cond_unknown.rb' -load File.dirname(__FILE__) + '/support/datatable_order_nulls_last.rb' -require File.dirname(__FILE__) + '/support/test_models.rb' +Dir[File.dirname(__FILE__) + '/support/**/*.rb'].sort.each { |f| require f } diff --git a/spec/support/datatables/complex_datatable.rb b/spec/support/datatables/complex_datatable.rb new file mode 100644 index 00000000..2efd68fd --- /dev/null +++ b/spec/support/datatables/complex_datatable.rb @@ -0,0 +1,29 @@ +class ComplexDatatable < AjaxDatatablesRails::ActiveRecord + def view_columns + @view_columns ||= { + username: { source: 'User.username' }, + email: { source: 'User.email' }, + first_name: { source: 'User.first_name' }, + last_name: { source: 'User.last_name' }, + post_id: { source: 'User.post_id', orderable: false }, + created_at: { source: 'User.created_at' }, + } + end + + def data + records.map do |record| + { + username: record.username, + email: record.email, + first_name: record.first_name, + last_name: record.last_name, + post_id: record.post_id, + created_at: record.created_at, + } + end + end + + def get_raw_records + User.all + end +end diff --git a/spec/support/datatables/complex_datatable_array.rb b/spec/support/datatables/complex_datatable_array.rb new file mode 100644 index 00000000..56773ebf --- /dev/null +++ b/spec/support/datatables/complex_datatable_array.rb @@ -0,0 +1,14 @@ +class ComplexDatatableArray < ComplexDatatable + def data + records.map do |record| + [ + record.username, + record.email, + record.first_name, + record.last_name, + record.post_id, + record.created_at, + ] + end + end +end diff --git a/spec/support/datatable_cond_date.rb b/spec/support/datatables/datatable_cond_date.rb similarity index 100% rename from spec/support/datatable_cond_date.rb rename to spec/support/datatables/datatable_cond_date.rb diff --git a/spec/support/datatable_cond_numeric.rb b/spec/support/datatables/datatable_cond_numeric.rb similarity index 100% rename from spec/support/datatable_cond_numeric.rb rename to spec/support/datatables/datatable_cond_numeric.rb diff --git a/spec/support/datatable_cond_proc.rb b/spec/support/datatables/datatable_cond_proc.rb similarity index 100% rename from spec/support/datatable_cond_proc.rb rename to spec/support/datatables/datatable_cond_proc.rb diff --git a/spec/support/datatable_cond_string.rb b/spec/support/datatables/datatable_cond_string.rb similarity index 100% rename from spec/support/datatable_cond_string.rb rename to spec/support/datatables/datatable_cond_string.rb diff --git a/spec/support/datatable_cond_unknown.rb b/spec/support/datatables/datatable_cond_unknown.rb similarity index 100% rename from spec/support/datatable_cond_unknown.rb rename to spec/support/datatables/datatable_cond_unknown.rb diff --git a/spec/support/datatable_order_nulls_last.rb b/spec/support/datatables/datatable_order_nulls_last.rb similarity index 100% rename from spec/support/datatable_order_nulls_last.rb rename to spec/support/datatables/datatable_order_nulls_last.rb diff --git a/spec/support/test_helpers.rb b/spec/support/helpers/params.rb similarity index 64% rename from spec/support/test_helpers.rb rename to spec/support/helpers/params.rb index 026a7a04..bb524c13 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/helpers/params.rb @@ -53,51 +53,6 @@ def sample_params end # rubocop:enable Metrics/MethodLength -class ComplexDatatable < AjaxDatatablesRails::ActiveRecord - def view_columns - @view_columns ||= { - username: { source: 'User.username' }, - email: { source: 'User.email' }, - first_name: { source: 'User.first_name' }, - last_name: { source: 'User.last_name' }, - post_id: { source: 'User.post_id', orderable: false }, - created_at: { source: 'User.created_at' }, - } - end - - def data - records.map do |record| - { - username: record.username, - email: record.email, - first_name: record.first_name, - last_name: record.last_name, - post_id: record.post_id, - created_at: record.created_at, - } - end - end - - def get_raw_records - User.all - end -end - -class ComplexDatatableArray < ComplexDatatable - def data - records.map do |record| - [ - record.username, - record.email, - record.first_name, - record.last_name, - record.post_id, - record.created_at, - ] - end - end -end - def nulls_last_sql(datatable) case datatable.db_adapter when :pg, :postgresql, :postgres, :oracle diff --git a/spec/support/test_models.rb b/spec/support/models/user.rb similarity index 100% rename from spec/support/test_models.rb rename to spec/support/models/user.rb From b1ecc2bb0895572e0d4502ca5cf65078dda737fb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 05:04:43 +0100 Subject: [PATCH 167/290] Coding style --- lib/ajax-datatables-rails/datatable/column.rb | 2 +- lib/ajax-datatables-rails/datatable/column/date_filter.rb | 2 +- lib/ajax-datatables-rails/orm/active_record.rb | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 179ee580..0469f052 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -97,7 +97,7 @@ def validate_settings! :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in, # Date condition :date_range - ] + ].freeze private_constant :VALID_SEARCH_CONDITIONS diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index 16a3a713..c680f15b 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -55,7 +55,7 @@ def range_start_casted end def range_end_casted - range_end.blank? ? parse_date("9999-12-31 23:59:59") : parse_date("#{range_end} 23:59:59") + range_end.blank? ? parse_date('9999-12-31 23:59:59') : parse_date("#{range_end} 23:59:59") end def parse_date(date) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index 977a2f52..fae27f3a 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -26,13 +26,14 @@ def paginate_records(records) # ----------------- SEARCH HELPER METHODS -------------------- def build_conditions - @criteria ||= begin + @build_conditions ||= begin criteria = [build_conditions_for_selected_columns] criteria << build_conditions_for_datatable if datatable.searchable? criteria.compact.reduce(:and) end end + # rubocop:disable Metrics/AbcSize def build_conditions_for_datatable columns = searchable_columns.reject(&:searched?) criteria = search_for.inject([]) do |crit, atom| @@ -44,6 +45,7 @@ def build_conditions_for_datatable end.compact.reduce(:and) criteria end + # rubocop:enable Metrics/AbcSize def build_conditions_for_selected_columns search_columns.map(&:search_query).compact.reduce(:and) From ace8e8a8c9fba8f471374246e319fa388ace7619 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 05:06:13 +0100 Subject: [PATCH 168/290] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02511ad2..5532d117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371)) * Raise an error when column's `cond:` setting is unknown * Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258)) +* Fix: date_range doesn't support searching by a date greater than today (merge: [#351](https://github.com/jbox-web/ajax-datatables-rails/pull/351)) * `AjaxDatatablesRails.config` is removed with no replacement. The gem is now configless :) * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) From f778e5807bf6003bb3c397da22ea9e4993c7e48a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 05:48:39 +0100 Subject: [PATCH 169/290] Fix undefined method `fetch' for nil:NilClass Fix https://github.com/jbox-web/ajax-datatables-rails/issues/307 --- CHANGELOG.md | 1 + lib/ajax-datatables-rails/datatable/column.rb | 12 ++++++++++- lib/ajax-datatables-rails/error.rb | 1 + .../datatable/column_spec.rb | 20 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5532d117..897debae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Raise an error when column's `cond:` setting is unknown * Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258)) * Fix: date_range doesn't support searching by a date greater than today (merge: [#351](https://github.com/jbox-web/ajax-datatables-rails/pull/351)) +* Fix: undefined method `fetch' for nil:NilClass (fix: [#307](https://github.com/jbox-web/ajax-datatables-rails/issues/307)) * `AjaxDatatablesRails.config` is removed with no replacement. The gem is now configless :) * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 0469f052..bdbee4d8 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -15,10 +15,14 @@ def initialize(datatable, index, options) @datatable = datatable @index = index @options = options - @view_column = datatable.view_columns[options[:data].to_sym] + @view_column = datatable.view_columns[column_name] validate_settings! end + def column_name + @column_name ||= options[:data]&.to_sym + end + def data options[:data].presence || options[:name] end @@ -87,9 +91,15 @@ def casted_column end def validate_settings! + raise AjaxDatatablesRails::Error::InvalidSearchColumn, "Unknown column. Check that `data` field is filled on JS side with the column name" if column_name.empty? + raise AjaxDatatablesRails::Error::InvalidSearchColumn, "Check that column '#{column_name}' exists in view_columns" unless valid_search_column?(column_name) raise AjaxDatatablesRails::Error::InvalidSearchCondition, cond unless valid_search_condition?(cond) end + def valid_search_column?(column_name) + !datatable.view_columns[column_name].nil? + end + VALID_SEARCH_CONDITIONS = [ # String condition :start_with, :end_with, :like, :string_eq, :string_in, :null_value, diff --git a/lib/ajax-datatables-rails/error.rb b/lib/ajax-datatables-rails/error.rb index 22a2665a..20fe0d26 100644 --- a/lib/ajax-datatables-rails/error.rb +++ b/lib/ajax-datatables-rails/error.rb @@ -3,6 +3,7 @@ module AjaxDatatablesRails module Error class BaseError < StandardError; end + class InvalidSearchColumn < BaseError; end class InvalidSearchCondition < BaseError; end end end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 8051f89d..a9ac55ce 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -202,4 +202,24 @@ expect(column.send(:type_cast)).to eq('VARCHAR(4000)') end end + + describe 'when empty column' do + before do + datatable.params[:columns] = {'0'=>{'data'=>'', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} + end + + it 'raises error' do + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Unknown column. Check that `data` field is filled on JS side with the column name") + end + end + + describe 'when unknown column' do + before do + datatable.params[:columns] = {'0'=>{'data'=>'foo', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} + end + + it 'raises error' do + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Check that column 'foo' exists in view_columns") + end + end end From e939ba89ce6c21689fab6384f18520fecfa90431 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 05:50:15 +0100 Subject: [PATCH 170/290] Coding style --- ajax-datatables-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index ec1dc852..8be8c9ec 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| 'homepage_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', 'changelog_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/blob/master/CHANGELOG.md', 'source_code_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', - 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues' + 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues', } s.required_ruby_version = '>= 2.5.0' From dba6dab7bf922bf656d87342b9a77d2de7c849db Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 05:59:43 +0100 Subject: [PATCH 171/290] Improve GA config --- .github/workflows/ci.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae76b071..802f3d8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,25 +94,24 @@ jobs: - name: Setup Ruby cache uses: actions/cache@v2 with: - path: "${GITHUB_WORKSPACE}/vendor/bundle" - key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }} + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}-${{ hashFiles('**/Gemfile.lock') }} restore-keys: | - ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}- + ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}- - name: Bundle env: RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} + BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile run: | - export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile" gem install bundler - # bundle config path "${GITHUB_WORKSPACE}/vendor/bundle" + bundle config path vendor/bundle bundle install --jobs 4 --retry 3 - name: RSpec env: RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} - run: | - export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile" - bundle exec rake + BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile + run: bin/rake From b6151b9660cd9dcb905c707307ae86e260982eeb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 06:07:43 +0100 Subject: [PATCH 172/290] Restore CodeClimate --- .github/workflows/ci.yml | 7 +++++-- ajax-datatables-rails.gemspec | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 802f3d8a..c9805798 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,9 +109,12 @@ jobs: bundle config path vendor/bundle bundle install --jobs 4 --retry 3 - - name: RSpec + - name: RSpec & publish code coverage + uses: paambaati/codeclimate-action@v2.7.5 env: RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile - run: bin/rake + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageCommand: bin/rake diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 8be8c9ec..afe1b300 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -39,5 +39,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec' s.add_development_dependency 'rspec-retry' s.add_development_dependency 'rubocop' - s.add_development_dependency 'simplecov', '~> 0.17.1' + s.add_development_dependency 'simplecov' end From 033d73104c2dab066f8fb9e367a80fab25dae5e2 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 18:12:00 +0100 Subject: [PATCH 173/290] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 897debae..53e5a313 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 1.3.0 (to come) +## 1.3.0 (2021-01-04) * Drop support of Rails 5.0.x and 5.1.x * Drop support of Ruby 2.4 @@ -13,6 +13,7 @@ * Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258)) * Fix: date_range doesn't support searching by a date greater than today (merge: [#351](https://github.com/jbox-web/ajax-datatables-rails/pull/351)) * Fix: undefined method `fetch' for nil:NilClass (fix: [#307](https://github.com/jbox-web/ajax-datatables-rails/issues/307)) +* Add support for json params (merge: [#355](https://github.com/jbox-web/ajax-datatables-rails/pull/355)) * `AjaxDatatablesRails.config` is removed with no replacement. The gem is now configless :) * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364)) From 81662a8f59849de4b8d557488648b6cad7daf852 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Jan 2021 18:12:28 +0100 Subject: [PATCH 174/290] Bump to version 1.3.0 --- lib/ajax-datatables-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 6d5dcee9..f952cf0a 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -8,7 +8,7 @@ def self.gem_version module VERSION MAJOR = 1 - MINOR = 2 + MINOR = 3 TINY = 0 PRE = nil From 7efcedf536ad9f33259923746cb073deeb19e586 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 6 Jan 2021 16:42:36 +0100 Subject: [PATCH 175/290] Update migration doc --- doc/migrate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/migrate.md b/doc/migrate.md index de12ff99..685913bb 100644 --- a/doc/migrate.md +++ b/doc/migrate.md @@ -1,4 +1,4 @@ -## To migrate from `v1.0.x` to `v1.3.0` +## To migrate from `v1.x` to `v1.3.0` The *v1.3.0* version has some breaking changes : From c34ee077afa37dc69441d01794e73b68db172cf6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 8 Jan 2021 01:03:48 +0100 Subject: [PATCH 176/290] Improve DB config in specs --- spec/spec_helper.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff968c07..698db89f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -55,8 +55,7 @@ end end -require 'ajax-datatables-rails' - +# Configure ActiveRecord adapter = ENV.fetch('DB_ADAPTER', 'postgresql') options = { @@ -65,11 +64,22 @@ encoding: 'utf8' } -options = options.merge(host: '127.0.0.1', port: 5432, username: 'postgres', password: 'postgres') if adapter == 'postgresql' -options = options.merge(host: '127.0.0.1', port: 3306, username: 'root', password: 'root') if adapter == 'mysql2' -options = options.merge(username: ENV['USER'], password: ENV['USER'], database: 'xe', host: '127.0.0.1/xe') if adapter == 'oracle_enhanced' -options = options.merge(database: ':memory:') if adapter == 'sqlite3' +options = + case adapter + when 'postgresql' + options.merge(host: '127.0.0.1', port: 5432, username: 'postgres', password: 'postgres') + when 'mysql2' + options.merge(host: '127.0.0.1', port: 3306, username: 'root', password: 'root') + when 'oracle_enhanced' + options.merge(host: '127.0.0.1/xe', username: ENV['USER'], password: ENV['USER'], database: 'xe') + when 'sqlite3' + options.merge(database: ':memory:') + end ActiveRecord::Base.establish_connection(options) +# Require our gem +require 'ajax-datatables-rails' + +# Load test helpers Dir[File.dirname(__FILE__) + '/support/**/*.rb'].sort.each { |f| require f } From d94c08a6e1c1ed4d64b573e73dcb3b98e815a01b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 8 Jan 2021 01:05:56 +0100 Subject: [PATCH 177/290] DRY specs --- .../orm/active_record_filter_records_spec.rb | 45 +++---------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index d1722ad6..aa0faa62 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -307,14 +307,14 @@ end context 'numeric condition' do + before(:each) do + create(:user, first_name: 'john', post_id: 1) + create(:user, first_name: 'mary', post_id: 2) + end + describe 'it can filter records with condition :eq' do let(:datatable) { DatatableCondEq.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 @@ -326,11 +326,6 @@ describe 'it can filter records with condition :not_eq' do let(:datatable) { DatatableCondNotEq.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 @@ -342,11 +337,6 @@ describe 'it can filter records with condition :lt' do let(:datatable) { DatatableCondLt.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = 2 expect(datatable.data.size).to eq 1 @@ -358,11 +348,6 @@ describe 'it can filter records with condition :gt' do let(:datatable) { DatatableCondGt.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 @@ -374,11 +359,6 @@ describe 'it can filter records with condition :lteq' do let(:datatable) { DatatableCondLteq.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = 2 expect(datatable.data.size).to eq 2 @@ -388,11 +368,6 @@ describe 'it can filter records with condition :gteq' do let(:datatable) { DatatableCondGteq.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 2 @@ -402,11 +377,6 @@ describe 'it can filter records with condition :in' do let(:datatable) { DatatableCondIn.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = [1] expect(datatable.data.size).to eq 1 @@ -418,11 +388,6 @@ describe 'it can filter records with condition :in with regex' do let(:datatable) { DatatableCondInWithRegex.new(sample_params) } - before(:each) do - create(:user, first_name: 'john', post_id: 1) - create(:user, first_name: 'mary', post_id: 2) - end - it 'should filter records matching' do datatable.params[:columns]['4'][:search][:value] = '1|2' datatable.params[:order]['0'] = { column: '4', dir: 'asc' } From 99f60aa65dfb793fcf6d4acf18baee7749b90423 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 8 Jan 2021 01:25:24 +0100 Subject: [PATCH 178/290] Improve coding style in specs --- spec/ajax-datatables-rails/base_spec.rb | 20 ++-- .../datatable/column_spec.rb | 54 ++++----- .../datatable/datatable_spec.rb | 18 +-- .../datatable/simple_order_spec.rb | 4 +- .../datatable/simple_search_spec.rb | 4 +- .../orm/active_record_filter_records_spec.rb | 110 +++++++++--------- .../active_record_paginate_records_spec.rb | 4 +- .../orm/active_record_sort_records_spec.rb | 6 +- .../orm/active_record_spec.rb | 4 +- spec/factories/user.rb | 4 +- spec/spec_helper.rb | 12 +- spec/support/datatables/complex_datatable.rb | 2 + .../datatables/complex_datatable_array.rb | 2 + .../support/datatables/datatable_cond_date.rb | 2 + .../datatables/datatable_cond_numeric.rb | 2 + .../support/datatables/datatable_cond_proc.rb | 2 + .../datatables/datatable_cond_string.rb | 6 +- .../datatables/datatable_cond_unknown.rb | 2 + .../datatables/datatable_order_nulls_last.rb | 2 + spec/support/helpers/params.rb | 12 +- spec/support/models/user.rb | 2 + spec/support/schema.rb | 4 +- 22 files changed, 161 insertions(+), 117 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index c98bf581..6e8096da 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::Base do @@ -44,7 +46,7 @@ context 'when data is defined as a hash' do let(:datatable) { ComplexDatatable.new(sample_params) } - it 'should return an array of hashes' do + it 'returns an array of hashes' do create_list(:user, 5) expect(datatable.data).to be_a(Array) expect(datatable.data.size).to eq 5 @@ -52,7 +54,7 @@ expect(item).to be_a(Hash) end - it 'should html escape data' do + it 'htmls escape data' do create(:user, first_name: 'Name ">', last_name: 'Name ">') data = datatable.send(:sanitize_data, datatable.data) item = data.first @@ -64,7 +66,7 @@ context 'when data is defined as a array' do let(:datatable) { ComplexDatatableArray.new(sample_params) } - it 'should return an array of arrays' do + it 'returns an array of arrays' do create_list(:user, 5) expect(datatable.data).to be_a(Array) expect(datatable.data.size).to eq 5 @@ -72,7 +74,7 @@ expect(item).to be_a(Array) end - it 'should html escape data' do + it 'htmls escape data' do create(:user, first_name: 'Name ">', last_name: 'Name ">') data = datatable.send(:sanitize_data, datatable.data) item = data.first @@ -156,7 +158,7 @@ def paginate_records(records) describe '#as_json' do let(:datatable) { ComplexDatatable.new(sample_params) } - it 'should return a hash' do + it 'returns a hash' do create_list(:user, 5) data = datatable.as_json expect(data[:recordsTotal]).to eq 5 @@ -166,9 +168,9 @@ def paginate_records(records) end context 'with additional_data' do - it 'should return a hash' do + it 'returns a hash' do create_list(:user, 5) - expect(datatable).to receive(:additional_data){ { foo: 'bar' } } + expect(datatable).to receive(:additional_data) { { foo: 'bar' } } data = datatable.as_json expect(data[:recordsTotal]).to eq 5 expect(data[:recordsFiltered]).to eq 5 @@ -184,7 +186,7 @@ def paginate_records(records) describe '#column_id' do let(:datatable) { ComplexDatatable.new(sample_params) } - it 'should return column id from view_columns hash' do + it 'returns column id from view_columns hash' do expect(datatable.column_id(:username)).to eq(0) expect(datatable.column_id('username')).to eq(0) end @@ -194,7 +196,7 @@ def paginate_records(records) let(:datatable) { ComplexDatatable.new(sample_params) } before { datatable.params[:columns]['0'][:search][:value] = 'doe' } - it 'should return column data from params' do + it 'returns column data from params' do expect(datatable.column_data(:username)).to eq('doe') expect(datatable.column_data('username')).to eq('doe') end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index a9ac55ce..7eaa389b 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::Datatable::Column do @@ -9,49 +11,49 @@ let(:column) { datatable.datatable.columns.first } before do - datatable.params[:columns] = {'0'=>{'data'=>'username', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} + datatable.params[:columns] = { '0' => { 'data' => 'username', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } end - it 'should be orderable' do + it 'is orderable' do expect(column.orderable?).to eq(true) end - it 'should sort nulls last' do + it 'sorts nulls last' do expect(column.nulls_last?).to eq(false) end - it 'should be searchable' do + it 'is searchable' do expect(column.searchable?).to eq(true) end - it 'should be searched' do + it 'is searched' do expect(column.searched?).to eq(true) end - it 'should have connected to id column' do + it 'has connected to id column' do expect(column.data).to eq('username') end describe '#data' do - it 'should return the data from params' do + it 'returns the data from params' do expect(column.data).to eq 'username' end end describe '#source' do - it 'should return the data source from view_column' do + it 'returns the data source from view_column' do expect(column.source).to eq 'User.username' end end describe '#table' do context 'with ActiveRecord ORM' do - it 'should return the corresponding AR table' do + it 'returns the corresponding AR table' do expect(column.table).to eq User.arel_table end end context 'with other ORM' do - it 'should return the corresponding model' do + it 'returns the corresponding model' do expect(User).to receive(:respond_to?).with(:arel_table).and_return(false) expect(column.table).to eq User end @@ -59,19 +61,19 @@ end describe '#model' do - it 'should return the corresponding AR model' do + it 'returns the corresponding AR model' do expect(column.model).to eq User end end describe '#field' do - it 'should return the corresponding field in DB' do + it 'returns the corresponding field in DB' do expect(column.field).to eq :username end end describe '#custom_field?' do - it 'should return false if field is bound to an AR field' do + it 'returns false if field is bound to an AR field' do expect(column.custom_field?).to be false end end @@ -81,47 +83,47 @@ expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch) end - it 'should have search value' do + it 'has search value' do expect(column.search.value).to eq('searchvalue') end - it 'should not regex' do + it 'does not regex' do expect(column.search.regexp?).to eq false end end describe '#cond' do - it 'should be :like by default' do + it 'is :like by default' do expect(column.cond).to eq(:like) end end describe '#source' do - it 'should be :like by default' do + it 'is :like by default' do expect(column.source).to eq('User.username') end end describe '#search_query' do - it 'should buld search query' do + it 'bulds search query' do expect(column.search_query.to_sql).to include('%searchvalue%') end end describe '#sort_query' do - it 'should build sort query' do + it 'builds sort query' do expect(column.sort_query).to eq('users.username') end end describe '#use_regex?' do - it 'should be true by default' do + it 'is true by default' do expect(column.use_regex?).to be true end end describe '#delimiter' do - it 'should be - by default' do + it 'is - by default' do expect(column.delimiter).to eq('-') end end @@ -131,7 +133,7 @@ let(:datatable) { DatatableWithFormater.new(sample_params) } let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } } - it 'should be a proc' do + it 'is a proc' do expect(column.formatter).to be_a(Proc) end end @@ -140,7 +142,7 @@ let(:datatable) { DatatableCondProc.new(sample_params) } let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } } - it 'should be a proc' do + it 'is a proc' do config = column.instance_variable_get('@view_column') filter = config[:cond] expect(filter).to be_a(Proc) @@ -205,17 +207,17 @@ describe 'when empty column' do before do - datatable.params[:columns] = {'0'=>{'data'=>'', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} + datatable.params[:columns] = { '0' => { 'data' => '', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } end it 'raises error' do - expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Unknown column. Check that `data` field is filled on JS side with the column name") + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message('Unknown column. Check that `data` field is filled on JS side with the column name') end end describe 'when unknown column' do before do - datatable.params[:columns] = {'0'=>{'data'=>'foo', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} + datatable.params[:columns] = { '0' => { 'data' => 'foo', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } end it 'raises error' do diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index c8e2b7dd..0b4fd7c6 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::Datatable::Datatable do let(:datatable) { ComplexDatatable.new(sample_params).datatable } let(:datatable_json) { ComplexDatatable.new(sample_params_json).datatable } - let(:order_option) { {'0'=>{'column'=>'0', 'dir'=>'asc'}, '1'=>{'column'=>'1', 'dir'=>'desc'}} } - let(:order_option_json) { [{'column'=>'0', 'dir'=>'asc'}, {'column'=>'1', 'dir'=>'desc'}] } + let(:order_option) { { '0' => { 'column' => '0', 'dir' => 'asc' }, '1' => { 'column' => '1', 'dir' => 'desc' } } } + let(:order_option_json) { [{ 'column' => '0', 'dir' => 'asc' }, { 'column' => '1', 'dir' => 'desc' }] } shared_examples 'order methods' do - it 'should be orderable' do + it 'is orderable' do expect(datatable.orderable?).to eq(true) end - it 'should not be orderable' do + it 'is not orderable' do datatable.options[:order] = nil expect(datatable.orderable?).to eq(false) end - it 'should have 2 orderable columns' do + it 'has 2 orderable columns' do datatable.options[:order] = order_option expect(datatable.orders.count).to eq(2) end @@ -38,7 +40,7 @@ end shared_examples 'columns methods' do - it 'should have 4 columns' do + it 'has 4 columns' do expect(datatable.columns.count).to eq(6) end @@ -60,12 +62,12 @@ end describe 'search methods' do - it 'should be searchable' do + it 'is searchable' do datatable.options[:search][:value] = 'atom' expect(datatable.searchable?).to eq(true) end - it 'should not be searchable' do + it 'is not searchable' do datatable.options[:search][:value] = nil expect(datatable.searchable?).to eq(false) end diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 55239d74..e385888e 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::Datatable::SimpleOrder do let(:parent) { ComplexDatatable.new(sample_params) } let(:datatable) { parent.datatable } - let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'column' => '1', 'dir' => 'desc'}) } + let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'column' => '1', 'dir' => 'desc' }) } let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) } describe 'option methods' do diff --git a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb b/spec/ajax-datatables-rails/datatable/simple_search_spec.rb index 784d85cf..eedeead5 100644 --- a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_search_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::Datatable::SimpleSearch do - let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'value' => 'search value', 'regex' => 'true'}) } + let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'value' => 'search value', 'regex' => 'true' }) } let(:simple_search) { AjaxDatatablesRails::Datatable::SimpleSearch.new(options) } describe 'option methods' do diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index aa0faa62..5f44a9ff 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::ORM::ActiveRecord do @@ -7,7 +9,7 @@ describe '#filter_records' do it 'requires a records collection as argument' do - expect { datatable.filter_records() }.to raise_error(ArgumentError) + expect { datatable.filter_records }.to raise_error(ArgumentError) end it 'performs a simple search first' do @@ -24,14 +26,14 @@ end describe '#build_conditions' do - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') create(:user, username: 'hsmith', email: 'henry.smith@example.net') end context 'with column and global search' do - before(:each) do + before do datatable.params[:search] = { value: 'example.com', regex: 'false' } datatable.params[:columns]['0'][:search][:value] = 'smith' end @@ -47,7 +49,7 @@ end describe '#build_conditions_for_datatable' do - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') end @@ -66,12 +68,12 @@ end context 'when none of columns are connected' do - before(:each) do + before do allow(datatable).to receive(:searchable_columns) { [] } end context 'when search value is a string' do - before(:each) do + before do datatable.params[:search] = { value: 'msmith' } end @@ -87,7 +89,7 @@ end context 'when search value is space-separated string' do - before(:each) do + before do datatable.params[:search] = { value: 'foo bar' } end @@ -105,7 +107,7 @@ context 'with search query' do context 'when search value is a string' do - before(:each) do + before do datatable.params[:search] = { value: 'john', regex: 'false' } end @@ -118,7 +120,7 @@ end context 'when search value is space-separated string' do - before(:each) do + before do datatable.params[:search] = { value: 'john doe', regex: 'false' } end @@ -134,7 +136,7 @@ context 'when column.search_query returns nil' do let(:datatable) { DatatableCondUnknown.new(sample_params) } - before(:each) do + before do datatable.params[:search] = { value: 'john doe', regex: 'false' } end @@ -150,7 +152,7 @@ end describe '#build_conditions_for_selected_columns' do - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') end @@ -209,7 +211,7 @@ end context 'with search values in columns' do - before(:each) do + before do datatable.params[:columns]['0'][:search][:value] = 'doe' end @@ -227,13 +229,13 @@ describe 'it can filter records with condition :date_range' do let(:datatable) { DatatableCondDate.new(sample_params) } - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000') create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000') end context 'when range is empty' do - it 'should not filter records' do + it 'does not filter records' do datatable.params[:columns]['5'][:search][:value] = '-' expect(datatable.data.size).to eq 2 item = datatable.data.first @@ -242,21 +244,21 @@ end context 'when start date is filled' do - it 'should filter records created after this date' do + it 'filters records created after this date' do datatable.params[:columns]['5'][:search][:value] = '31/12/1999-' expect(datatable.data.size).to eq 2 end end context 'when end date is filled' do - it 'should filter records created before this date' do + it 'filters records created before this date' do datatable.params[:columns]['5'][:search][:value] = '-31/12/1999' expect(datatable.data.size).to eq 0 end end context 'when both date are filled' do - it 'should filter records created between the range' do + it 'filters records created between the range' do datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 end @@ -264,7 +266,7 @@ context 'when another filter is active' do context 'when range is empty' do - it 'should filter records' do + it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['5'][:search][:value] = '-' expect(datatable.data.size).to eq 1 @@ -274,7 +276,7 @@ end context 'when start date is filled' do - it 'should filter records' do + it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['5'][:search][:value] = '01/12/1999-' expect(datatable.data.size).to eq 1 @@ -284,7 +286,7 @@ end context 'when end date is filled' do - it 'should filter records' do + it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['5'][:search][:value] = '-15/01/2000' expect(datatable.data.size).to eq 1 @@ -294,7 +296,7 @@ end context 'when both date are filled' do - it 'should filter records' do + it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 @@ -307,7 +309,7 @@ end context 'numeric condition' do - before(:each) do + before do create(:user, first_name: 'john', post_id: 1) create(:user, first_name: 'mary', post_id: 2) end @@ -315,7 +317,7 @@ describe 'it can filter records with condition :eq' do let(:datatable) { DatatableCondEq.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -326,7 +328,7 @@ describe 'it can filter records with condition :not_eq' do let(:datatable) { DatatableCondNotEq.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -337,7 +339,7 @@ describe 'it can filter records with condition :lt' do let(:datatable) { DatatableCondLt.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = 2 expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -348,7 +350,7 @@ describe 'it can filter records with condition :gt' do let(:datatable) { DatatableCondGt.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -359,7 +361,7 @@ describe 'it can filter records with condition :lteq' do let(:datatable) { DatatableCondLteq.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = 2 expect(datatable.data.size).to eq 2 end @@ -368,7 +370,7 @@ describe 'it can filter records with condition :gteq' do let(:datatable) { DatatableCondGteq.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = 1 expect(datatable.data.size).to eq 2 end @@ -377,7 +379,7 @@ describe 'it can filter records with condition :in' do let(:datatable) { DatatableCondIn.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = [1] expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -388,7 +390,7 @@ describe 'it can filter records with condition :in with regex' do let(:datatable) { DatatableCondInWithRegex.new(sample_params) } - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['4'][:search][:value] = '1|2' datatable.params[:order]['0'] = { column: '4', dir: 'asc' } expect(datatable.data.size).to eq 2 @@ -399,10 +401,10 @@ describe 'Integer overflows' do let(:datatable) { DatatableCondEq.new(sample_params) } - let(:largest_postgresql_integer_value) { 2147483647 } - let(:smallest_postgresql_integer_value) { -2147483648 } + let(:largest_postgresql_integer_value) { 2_147_483_647 } + let(:smallest_postgresql_integer_value) { -2_147_483_648 } - before(:each) do + before do create(:user, first_name: 'john', post_id: 1) create(:user, first_name: 'mary', post_id: 2) create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value) @@ -429,13 +431,13 @@ describe 'it can filter records with lambda/proc condition' do let(:datatable) { DatatableCondProc.new(sample_params) } - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'johndie', email: 'johndie@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') end - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['0'][:search][:value] = 'john' expect(datatable.data.size).to eq 2 item = datatable.data.first @@ -448,12 +450,12 @@ describe 'it can filter records with condition :start_with' do let(:datatable) { DatatableCondStartWith.new(sample_params) } - before(:each) do + before do create(:user, first_name: 'John') create(:user, first_name: 'Mary') end - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['2'][:search][:value] = 'Jo' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -464,14 +466,14 @@ describe 'it can filter records with condition :end_with' do let(:datatable) { DatatableCondEndWith.new(sample_params) } - before(:each) do + before do create(:user, last_name: 'JOHN') create(:user, last_name: 'MARY') end if ENV['DB_ADAPTER'] == 'oracle_enhanced' context 'when db_adapter is oracleenhanced' do - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['3'][:search][:value] = 'RY' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -479,7 +481,7 @@ end end else - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['3'][:search][:value] = 'ry' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -491,12 +493,12 @@ describe 'it can filter records with condition :like' do let(:datatable) { DatatableCondLike.new(sample_params) } - before(:each) do + before do create(:user, email: 'john@foo.com') create(:user, email: 'mary@bar.com') end - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['1'][:search][:value] = 'foo' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -507,12 +509,12 @@ describe 'it can filter records with condition :string_eq' do let(:datatable) { DatatableCondStringEq.new(sample_params) } - before(:each) do + before do create(:user, email: 'john@foo.com') create(:user, email: 'mary@bar.com') end - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -523,20 +525,20 @@ describe 'it can filter records with condition :string_in' do let(:datatable) { DatatableCondStringIn.new(sample_params) } - before(:each) do + before do create(:user, email: 'john@foo.com') create(:user, email: 'mary@bar.com') create(:user, email: 'henry@baz.com') end - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['1'][:search][:value] = 'john@foo.com' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:email]).to eq 'john@foo.com' end - it 'should filter records matching with multiple' do + it 'filters records matching with multiple' do datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry@baz.com' expect(datatable.data.size).to eq 2 items = datatable.data.sort_by { |h| h[:email] } @@ -546,7 +548,7 @@ expect(item_last[:email]).to eq 'john@foo.com' end - it 'should filter records matching with multiple contains not found' do + it 'filters records matching with multiple contains not found' do datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry_not@baz.com' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -557,13 +559,13 @@ describe 'it can filter records with condition :null_value' do let(:datatable) { DatatableCondNullValue.new(sample_params) } - before(:each) do + before do create(:user, first_name: 'john', email: 'foo@bar.com') create(:user, first_name: 'mary', email: nil) end context 'when condition is NULL' do - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['1'][:search][:value] = 'NULL' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -572,7 +574,7 @@ end context 'when condition is !NULL' do - it 'should filter records matching' do + it 'filters records matching' do datatable.params[:columns]['1'][:search][:value] = '!NULL' expect(datatable.data.size).to eq 1 item = datatable.data.first @@ -585,11 +587,11 @@ context 'unknown condition' do let(:datatable) { DatatableCondUnknown.new(sample_params) } - before(:each) do + before do datatable.params[:search] = { value: 'john doe', regex: 'false' } end - it 'should raise error' do + it 'raises error' do expect { datatable.data.size }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchCondition).with_message('foo') @@ -600,7 +602,7 @@ describe 'formatter option' do let(:datatable) { DatatableWithFormater.new(sample_params) } - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'DOE') create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'SMITH') datatable.params[:columns]['3'][:search][:value] = 'doe' diff --git a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb index 51689833..d5b39739 100644 --- a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::ORM::ActiveRecord do @@ -5,7 +7,7 @@ let(:datatable) { ComplexDatatable.new(sample_params) } let(:records) { User.all } - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') end diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index fb10879b..d1947868 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::ORM::ActiveRecord do @@ -6,7 +8,7 @@ let(:nulls_last_datatable) { DatatableOrderNullsLast.new(sample_params) } let(:records) { User.all } - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') end @@ -30,7 +32,7 @@ ) end - it 'should not sort a column which is not orderable' do + it 'does not sort a column which is not orderable' do datatable.params[:order]['0'] = { column: '0', dir: 'asc' } datatable.params[:order]['1'] = { column: '4', dir: 'desc' } diff --git a/spec/ajax-datatables-rails/orm/active_record_spec.rb b/spec/ajax-datatables-rails/orm/active_record_spec.rb index 89792adf..475adc92 100644 --- a/spec/ajax-datatables-rails/orm/active_record_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' describe AjaxDatatablesRails::ORM::ActiveRecord do context 'Private API' do let(:datatable) { ComplexDatatable.new(sample_params) } - before(:each) do + before do create(:user, username: 'johndoe', email: 'johndoe@example.com') create(:user, username: 'msmith', email: 'mary.smith@example.com') end diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 5cd5bf6a..bcecd98d 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + FactoryBot.define do factory :user do |f| f.username { Faker::Internet.user_name } f.email { Faker::Internet.email } f.first_name { Faker::Name.first_name } f.last_name { Faker::Name.last_name } - f.post_id { ((1..100).to_a).sample } + f.post_id { (1..100).to_a.sample } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 698db89f..371abca4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simplecov' require 'rspec' require 'rspec/retry' @@ -36,20 +38,20 @@ DatabaseCleaner.clean_with(:truncation) end - config.before(:each) do + config.before do DatabaseCleaner.strategy = :transaction end - config.before(:each) do + config.before do DatabaseCleaner.start end - config.after(:each) do + config.after do DatabaseCleaner.clean end if ENV.key?('GITHUB_ACTIONS') - config.around(:each) do |ex| + config.around do |ex| ex.run_with_retry retry: 3 end end @@ -61,7 +63,7 @@ options = { adapter: adapter, database: 'ajax_datatables_rails', - encoding: 'utf8' + encoding: 'utf8', } options = diff --git a/spec/support/datatables/complex_datatable.rb b/spec/support/datatables/complex_datatable.rb index 2efd68fd..faa7ce23 100644 --- a/spec/support/datatables/complex_datatable.rb +++ b/spec/support/datatables/complex_datatable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ComplexDatatable < AjaxDatatablesRails::ActiveRecord def view_columns @view_columns ||= { diff --git a/spec/support/datatables/complex_datatable_array.rb b/spec/support/datatables/complex_datatable_array.rb index 56773ebf..bbcbf03a 100644 --- a/spec/support/datatables/complex_datatable_array.rb +++ b/spec/support/datatables/complex_datatable_array.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ComplexDatatableArray < ComplexDatatable def data records.map do |record| diff --git a/spec/support/datatables/datatable_cond_date.rb b/spec/support/datatables/datatable_cond_date.rb index 65af38c1..510f66b5 100644 --- a/spec/support/datatables/datatable_cond_date.rb +++ b/spec/support/datatables/datatable_cond_date.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DatatableCondDate < ComplexDatatable def view_columns super.deep_merge(created_at: { cond: :date_range }) diff --git a/spec/support/datatables/datatable_cond_numeric.rb b/spec/support/datatables/datatable_cond_numeric.rb index c42109fe..12b016aa 100644 --- a/spec/support/datatables/datatable_cond_numeric.rb +++ b/spec/support/datatables/datatable_cond_numeric.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DatatableCondEq < ComplexDatatable def view_columns super.deep_merge(post_id: { cond: :eq }) diff --git a/spec/support/datatables/datatable_cond_proc.rb b/spec/support/datatables/datatable_cond_proc.rb index ff057dd5..3823fd12 100644 --- a/spec/support/datatables/datatable_cond_proc.rb +++ b/spec/support/datatables/datatable_cond_proc.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DatatableCondProc < ComplexDatatable def view_columns super.deep_merge(username: { cond: custom_filter }) diff --git a/spec/support/datatables/datatable_cond_string.rb b/spec/support/datatables/datatable_cond_string.rb index 204ddb9f..42fb4acf 100644 --- a/spec/support/datatables/datatable_cond_string.rb +++ b/spec/support/datatables/datatable_cond_string.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DatatableCondStartWith < ComplexDatatable def view_columns super.deep_merge(first_name: { cond: :start_with }) @@ -24,7 +26,7 @@ def view_columns class DatatableCondStringIn < ComplexDatatable def view_columns - super.deep_merge(email: { cond: :string_in, formatter: -> (o) { o.split("|") } }) + super.deep_merge(email: { cond: :string_in, formatter: ->(o) { o.split('|') } }) end end @@ -36,6 +38,6 @@ def view_columns class DatatableWithFormater < ComplexDatatable def view_columns - super.deep_merge(last_name: { formatter: -> (o) { o.upcase } }) + super.deep_merge(last_name: { formatter: ->(o) { o.upcase } }) end end diff --git a/spec/support/datatables/datatable_cond_unknown.rb b/spec/support/datatables/datatable_cond_unknown.rb index 3894eb39..c730b575 100644 --- a/spec/support/datatables/datatable_cond_unknown.rb +++ b/spec/support/datatables/datatable_cond_unknown.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DatatableCondUnknown < ComplexDatatable def view_columns super.deep_merge(username: { cond: :foo }) diff --git a/spec/support/datatables/datatable_order_nulls_last.rb b/spec/support/datatables/datatable_order_nulls_last.rb index f4d7f6d3..e1b3acdc 100644 --- a/spec/support/datatables/datatable_order_nulls_last.rb +++ b/spec/support/datatables/datatable_order_nulls_last.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DatatableOrderNullsLast < ComplexDatatable def view_columns super.deep_merge(email: { nulls_last: true }) diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index 707116e7..2fb41da6 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable Metrics/MethodLength def sample_params ActionController::Parameters.new( @@ -42,7 +44,7 @@ def sample_params }, }, 'order' => { - '0' => {'column' => '0', 'dir' => 'asc'} + '0' => { 'column' => '0', 'dir' => 'asc' }, }, 'start' => '0', 'length' => '10', 'search' => { 'value' => '', 'regex' => 'false' @@ -54,8 +56,8 @@ def sample_params def sample_params_json hash_params = sample_params.to_unsafe_h - hash_params["columns"] = hash_params["columns"].values - hash_params["order"] = hash_params["order"].values + hash_params['columns'] = hash_params['columns'].values + hash_params['order'] = hash_params['order'].values ActionController::Parameters.new(hash_params) end # rubocop:enable Metrics/MethodLength @@ -63,9 +65,9 @@ def sample_params_json def nulls_last_sql(datatable) case datatable.db_adapter when :pg, :postgresql, :postgres, :oracle - "NULLS LAST" + 'NULLS LAST' when :mysql, :mysql2, :sqlite, :sqlite3 - "IS NULL" + 'IS NULL' else raise 'unsupported database adapter' end diff --git a/spec/support/models/user.rb b/spec/support/models/user.rb index 4a57cf07..b2c40d16 100644 --- a/spec/support/models/user.rb +++ b/spec/support/models/user.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class User < ActiveRecord::Base end diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 8da7e4d1..69a10cb1 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + ActiveRecord::Schema.define do self.verbose = false - create_table :users, :force => true do |t| + create_table :users, force: true do |t| t.string :username t.string :email t.string :first_name From 61feb40493663f09573b77d2340549841b52e3d2 Mon Sep 17 00:00:00 2001 From: Eric-Guo Date: Tue, 5 Jan 2021 13:04:51 +0800 Subject: [PATCH 179/290] Fix Rare case error uninitialized constant AjaxDatatablesRails::ActiveRecord::Base --- lib/ajax-datatables-rails/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index b852c147..6f20a7e0 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -3,7 +3,7 @@ module AjaxDatatablesRails class Base - class_attribute :db_adapter, default: ActiveRecord::Base.connection.adapter_name.downcase.to_sym + class_attribute :db_adapter, default: ::ActiveRecord::Base.connection.adapter_name.downcase.to_sym class_attribute :nulls_last, default: false attr_reader :params, :options, :datatable From b3f297e059bf92d1874e71dbf1e9e40336b6c477 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 8 Jan 2021 20:44:51 +0100 Subject: [PATCH 180/290] Fix example in README --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a365b853..c0e3f866 100644 --- a/README.md +++ b/README.md @@ -532,13 +532,13 @@ available in our datatable to search and sort by. def view_columns @view_columns ||= { - first_name: 'User.first_name', - last_name: 'User.last_name', - order_number: 'PurchaseOrder.number', - order_created_at: 'PurchaseOrder.created_at', - quantity: 'Purchase::LineItem.quantity', - unit_price: 'Purchase::LineItem.unit_price', - item_total: 'Purchase::LineItem.item_total' + first_name: { source: 'User.first_name' }, + last_name: { source: 'User.last_name' }, + order_number: { source: 'PurchaseOrder.number' }, + order_created_at: { source: 'PurchaseOrder.created_at' }, + quantity: { source: 'Purchase::LineItem.quantity' }, + unit_price: { source: 'Purchase::LineItem.unit_price' }, + item_total: { source: 'Purchase::LineItem.item_total }' } end ``` @@ -570,14 +570,14 @@ The related definition would be : ```ruby def view_columns @view_columns ||= { - course_type: 'CourseType.name', - course_name: 'Course.name', - contact_name: 'Contact.full_name', - competency_type: 'CompetencyType.name', - event_title: 'Event.title', - event_start: 'Event.event_start', - event_end: 'Event.event_end', - event_status: 'Event.status', + course_type: { source: 'CourseType.name' }, + course_name: { source: 'Course.name' }, + contact_name: { source: 'Contact.full_name' }, + competency_type: { source: 'CompetencyType.name' }, + event_title: { source: 'Event.title' }, + event_start: { source: 'Event.event_start' }, + event_end: { source: 'Event.event_end' }, + event_status: { source: 'Event.status' }, } end From 551e3aa6cab5d604834c8765f0820798f78dd8c3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 9 Jan 2021 03:26:17 +0100 Subject: [PATCH 181/290] Disable RSpec monkey patching --- spec/ajax-datatables-rails/base_spec.rb | 2 +- spec/ajax-datatables-rails/datatable/column_spec.rb | 2 +- spec/ajax-datatables-rails/datatable/datatable_spec.rb | 2 +- spec/ajax-datatables-rails/datatable/simple_order_spec.rb | 2 +- spec/ajax-datatables-rails/datatable/simple_search_spec.rb | 2 +- .../orm/active_record_filter_records_spec.rb | 2 +- .../orm/active_record_paginate_records_spec.rb | 2 +- .../orm/active_record_sort_records_spec.rb | 2 +- spec/ajax-datatables-rails/orm/active_record_spec.rb | 2 +- spec/spec_helper.rb | 4 ++++ 10 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 6e8096da..794b61eb 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::Base do +RSpec.describe AjaxDatatablesRails::Base do describe 'an instance' do it 'requires a hash of params' do diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 7eaa389b..7ad81270 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::Datatable::Column do +RSpec.describe AjaxDatatablesRails::Datatable::Column do let(:datatable) { ComplexDatatable.new(sample_params) } diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index 0b4fd7c6..69ae816c 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::Datatable::Datatable do +RSpec.describe AjaxDatatablesRails::Datatable::Datatable do let(:datatable) { ComplexDatatable.new(sample_params).datatable } let(:datatable_json) { ComplexDatatable.new(sample_params_json).datatable } diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index e385888e..dc48ffd3 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::Datatable::SimpleOrder do +RSpec.describe AjaxDatatablesRails::Datatable::SimpleOrder do let(:parent) { ComplexDatatable.new(sample_params) } let(:datatable) { parent.datatable } diff --git a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb b/spec/ajax-datatables-rails/datatable/simple_search_spec.rb index eedeead5..fc814802 100644 --- a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_search_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::Datatable::SimpleSearch do +RSpec.describe AjaxDatatablesRails::Datatable::SimpleSearch do let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'value' => 'search value', 'regex' => 'true' }) } let(:simple_search) { AjaxDatatablesRails::Datatable::SimpleSearch.new(options) } diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 5f44a9ff..d198e187 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::ORM::ActiveRecord do +RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do let(:datatable) { ComplexDatatable.new(sample_params) } let(:records) { User.all } diff --git a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb index d5b39739..63425da6 100644 --- a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::ORM::ActiveRecord do +RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do let(:datatable) { ComplexDatatable.new(sample_params) } let(:records) { User.all } diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index d1947868..00be4506 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::ORM::ActiveRecord do +RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do let(:datatable) { ComplexDatatable.new(sample_params) } let(:nulls_last_datatable) { DatatableOrderNullsLast.new(sample_params) } diff --git a/spec/ajax-datatables-rails/orm/active_record_spec.rb b/spec/ajax-datatables-rails/orm/active_record_spec.rb index 475adc92..319fb2af 100644 --- a/spec/ajax-datatables-rails/orm/active_record_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AjaxDatatablesRails::ORM::ActiveRecord do +RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do context 'Private API' do let(:datatable) { ComplexDatatable.new(sample_params) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 371abca4..2141d152 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,6 +50,10 @@ DatabaseCleaner.clean end + # disable monkey patching + # see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode + config.disable_monkey_patching! + if ENV.key?('GITHUB_ACTIONS') config.around do |ex| ex.run_with_retry retry: 3 From 5112c9964dddd2eaa3d81e1cbf52cd26812cd5bb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 9 Jan 2021 03:45:00 +0100 Subject: [PATCH 182/290] Add bundle binstub --- bin/bundle | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 bin/bundle diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 00000000..a71368e3 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,114 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= + env_var_version || cli_arg_version || + lockfile_version + end + + def bundler_requirement + return "#{Gem::Requirement.default}.a" unless bundler_version + + bundler_gem_version = Gem::Version.new(bundler_version) + + requirement = bundler_gem_version.approximate_recommendation + + return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + + requirement += ".a" if bundler_gem_version.prerelease? + + requirement + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end From 58efd2cf910548da1abc186df1935c1a30aa76c5 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 12 Jan 2021 01:07:27 +0100 Subject: [PATCH 183/290] Improve wording in specs --- spec/ajax-datatables-rails/base_spec.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 794b61eb..4cb55864 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -17,9 +17,11 @@ describe 'User API' do describe '#view_columns' do - it 'raises an error if not defined by the user' do - datatable = described_class.new(sample_params) - expect { datatable.view_columns }.to raise_error NotImplementedError + context 'when method is not defined by the user' do + it 'raises an error' do + datatable = described_class.new(sample_params) + expect { datatable.view_columns }.to raise_error NotImplementedError + end end context 'child class implements view_columns' do @@ -31,16 +33,20 @@ end describe '#get_raw_records' do - it 'raises an error if not defined by the user' do - datatable = described_class.new(sample_params) - expect { datatable.get_raw_records }.to raise_error NotImplementedError + context 'when method is not defined by the user' do + it 'raises an error' do + datatable = described_class.new(sample_params) + expect { datatable.get_raw_records }.to raise_error NotImplementedError + end end end describe '#data' do - it 'raises an error if not defined by the user' do - datatable = described_class.new(sample_params) - expect { datatable.data }.to raise_error NotImplementedError + context 'when method is not defined by the user' do + it 'raises an error' do + datatable = described_class.new(sample_params) + expect { datatable.data }.to raise_error NotImplementedError + end end context 'when data is defined as a hash' do From 11e48903052be05fc59c6a831c4767a0218e1397 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 12 Jan 2021 01:07:52 +0100 Subject: [PATCH 184/290] Move spec --- spec/ajax-datatables-rails/base_spec.rb | 12 +++++++++ .../orm/active_record_spec.rb | 26 ------------------- 2 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 spec/ajax-datatables-rails/orm/active_record_spec.rb diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 4cb55864..02ce8acb 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -139,6 +139,18 @@ def paginate_records(records) datatable.new(sample_params) end + describe '#fetch_records' do + it 'calls #get_raw_records' do + expect(datatable).to receive(:get_raw_records) { User.all } + datatable.fetch_records + end + + it 'returns a collection of records' do + expect(datatable).to receive(:get_raw_records) { User.all } + expect(datatable.fetch_records).to be_a(ActiveRecord::Relation) + end + end + describe '#filter_records' do it { expect { datatable.filter_records([]) }.to raise_error(NotImplementedError).with_message('FOO') diff --git a/spec/ajax-datatables-rails/orm/active_record_spec.rb b/spec/ajax-datatables-rails/orm/active_record_spec.rb deleted file mode 100644 index 319fb2af..00000000 --- a/spec/ajax-datatables-rails/orm/active_record_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do - context 'Private API' do - let(:datatable) { ComplexDatatable.new(sample_params) } - - before do - create(:user, username: 'johndoe', email: 'johndoe@example.com') - create(:user, username: 'msmith', email: 'mary.smith@example.com') - end - - describe '#fetch_records' do - it 'calls #get_raw_records' do - expect(datatable).to receive(:get_raw_records) { User.all } - datatable.fetch_records - end - - it 'returns a collection of records' do - expect(datatable).to receive(:get_raw_records) { User.all } - expect(datatable.fetch_records).to be_a(ActiveRecord::Relation) - end - end - end -end From 56298d902e445e3067c5294b88db82f527e19923 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 12 Jan 2021 01:16:02 +0100 Subject: [PATCH 185/290] DRY specs --- spec/ajax-datatables-rails/datatable/column_spec.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 7ad81270..6239d891 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -10,9 +10,7 @@ let(:column) { datatable.datatable.columns.first } - before do - datatable.params[:columns] = { '0' => { 'data' => 'username', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } - end + before { datatable.params[:columns]['0'][:search][:value] = 'searchvalue' } it 'is orderable' do expect(column.orderable?).to eq(true) @@ -52,6 +50,7 @@ expect(column.table).to eq User.arel_table end end + context 'with other ORM' do it 'returns the corresponding model' do expect(User).to receive(:respond_to?).with(:arel_table).and_return(false) @@ -206,9 +205,7 @@ end describe 'when empty column' do - before do - datatable.params[:columns] = { '0' => { 'data' => '', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } - end + before { datatable.params[:columns]['0'][:data] = '' } it 'raises error' do expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message('Unknown column. Check that `data` field is filled on JS side with the column name') @@ -216,9 +213,7 @@ end describe 'when unknown column' do - before do - datatable.params[:columns] = { '0' => { 'data' => 'foo', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } - end + before { datatable.params[:columns]['0'][:data] = 'foo' } it 'raises error' do expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Check that column 'foo' exists in view_columns") From d4f097a5d7660dd845a0d1f98ddbfce5030a78e1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 12 Jan 2021 01:20:37 +0100 Subject: [PATCH 186/290] Coding style --- lib/ajax-datatables-rails/datatable/datatable.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index 63d773d6..ceaf63c2 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -2,7 +2,6 @@ module AjaxDatatablesRails module Datatable - class Datatable attr_reader :options From 9ff803cdc08c36d2abae850f69a369d6a5575146 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 13 Jan 2021 14:58:29 +0100 Subject: [PATCH 187/290] Extract method --- lib/ajax-datatables-rails/datatable/column/search.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 7c89be72..dde62128 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -62,11 +62,11 @@ def non_regex_search when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in searchable_integer? ? raw_search(cond) : empty_search when :start_with - casted_column.matches("#{formatted_value}%") + text_search("#{formatted_value}%") when :end_with - casted_column.matches("%#{formatted_value}") + text_search("%#{formatted_value}") when :like - casted_column.matches("%#{formatted_value}%") + text_search("%#{formatted_value}%") when :string_eq raw_search(:eq) when :string_in @@ -95,6 +95,10 @@ def raw_search(cond) end end + def text_search(value) + casted_column.matches(value) + end + def empty_search casted_column.matches(EMPTY_VALUE) end From 453f0f411d49a2c9af81e4e98de29cbbc8c6491e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 9 Feb 2021 03:19:31 +0100 Subject: [PATCH 188/290] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e5a313..c5a4603d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 1.3.1 (2021-02-09) + +* Fix rare case error `uninitialized constant AjaxDatatablesRails::ActiveRecord::Base` (merge: [#379](https://github.com/jbox-web/ajax-datatables-rails/pull/379)) + ## 1.3.0 (2021-01-04) * Drop support of Rails 5.0.x and 5.1.x From 75e0211977111c5aa11ee1dfc8aaae70529fbe8c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 9 Feb 2021 03:19:51 +0100 Subject: [PATCH 189/290] Bunp to version 1.3.1 --- lib/ajax-datatables-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index f952cf0a..474afce9 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -9,7 +9,7 @@ def self.gem_version module VERSION MAJOR = 1 MINOR = 3 - TINY = 0 + TINY = 1 PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') From c8619f489d6e6f19ac59f0b2d1d7feb497e275c1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 9 Feb 2021 23:03:04 +0100 Subject: [PATCH 190/290] Improve DB detection in spec --- .../datatable/simple_order_spec.rb | 2 +- .../orm/active_record_filter_records_spec.rb | 8 ++++---- .../active_record_paginate_records_spec.rb | 4 ++-- .../orm/active_record_sort_records_spec.rb | 4 ++-- spec/spec_helper.rb | 19 +++++++++++++++++++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index dc48ffd3..c28bfe84 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -21,7 +21,7 @@ after { parent.nulls_last = false } it 'sql query' do - skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' + skip('unsupported database adapter') if RunningSpec.oracle? expect(simple_order.query('email')).to eq( "email DESC #{nulls_last_sql(parent)}" diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index d198e187..2b873af5 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -168,7 +168,7 @@ expect(result).to be_a(Arel::Nodes::And) end - if ENV['DB_ADAPTER'] == 'postgresql' + if RunningSpec.postgresql? context 'when db_adapter is postgresql' do it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns @@ -180,7 +180,7 @@ end end - if ENV['DB_ADAPTER'] == 'oracle_enhanced' + if RunningSpec.oracle? context 'when db_adapter is oracle' do it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns @@ -192,7 +192,7 @@ end end - if ENV['DB_ADAPTER'] == 'mysql2' + if RunningSpec.mysql? context 'when db_adapter is mysql2' do it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns @@ -471,7 +471,7 @@ create(:user, last_name: 'MARY') end - if ENV['DB_ADAPTER'] == 'oracle_enhanced' + if RunningSpec.oracle? context 'when db_adapter is oracleenhanced' do it 'filters records matching' do datatable.params[:columns]['3'][:search][:value] = 'RY' diff --git a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb index 63425da6..e715b2fe 100644 --- a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb @@ -18,7 +18,7 @@ end it 'paginates records properly' do - if ENV['DB_ADAPTER'] == 'oracle_enhanced' + if RunningSpec.oracle? if Rails.version.in? %w[4.2.11] expect(datatable.paginate_records(records).to_sql).to include( 'rownum <= 10' @@ -36,7 +36,7 @@ datatable.params[:start] = '26' datatable.params[:length] = '25' - if ENV['DB_ADAPTER'] == 'oracle_enhanced' + if RunningSpec.oracle? if Rails.version.in? %w[4.2.11] expect(datatable.paginate_records(records).to_sql).to include( 'rownum <= 51' diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb index 00be4506..369d859c 100644 --- a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb @@ -51,7 +51,7 @@ after { datatable.nulls_last = false } it 'can handle multiple sorting columns' do - skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' + skip('unsupported database adapter') if RunningSpec.oracle? # set to order by Users username in ascending order, and # by Users email in descending order @@ -65,7 +65,7 @@ describe '#sort_records with nulls last using column config' do it 'can handle multiple sorting columns' do - skip('unsupported database adapter') if ENV['DB_ADAPTER'] == 'oracle_enhanced' + skip('unsupported database adapter') if RunningSpec.oracle? # set to order by Users username in ascending order, and # by Users email in descending order diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2141d152..72c66b3b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,8 +61,27 @@ end end +class RunningSpec + def self.sqlite? + ENV['DB_ADAPTER'] == 'sqlite3' + end + + def self.oracle? + ENV['DB_ADAPTER'] == 'oracle_enhanced' + end + + def self.mysql? + ENV['DB_ADAPTER'] == 'mysql2' + end + + def self.postgresql? + ENV['DB_ADAPTER'] == 'postgresql' + end +end + # Configure ActiveRecord adapter = ENV.fetch('DB_ADAPTER', 'postgresql') +ENV['DB_ADAPTER'] = adapter options = { adapter: adapter, From dd53c056835855073f38c49a6461d4146cedc5ae Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 13 Jan 2021 15:04:53 +0100 Subject: [PATCH 191/290] Add test data for custom_field feature --- .../datatable/datatable_spec.rb | 4 +- .../orm/active_record_filter_records_spec.rb | 40 +++++++++---------- spec/support/datatables/complex_datatable.rb | 2 + spec/support/helpers/params.rb | 8 +++- spec/support/models/user.rb | 3 ++ 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index 69ae816c..6d266288 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -40,8 +40,8 @@ end shared_examples 'columns methods' do - it 'has 4 columns' do - expect(datatable.columns.count).to eq(6) + it 'has 7 columns' do + expect(datatable.columns.count).to eq(7) end it 'child class' do diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 2b873af5..cbe7538f 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -236,7 +236,7 @@ context 'when range is empty' do it 'does not filter records' do - datatable.params[:columns]['5'][:search][:value] = '-' + datatable.params[:columns]['6'][:search][:value] = '-' expect(datatable.data.size).to eq 2 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -245,21 +245,21 @@ context 'when start date is filled' do it 'filters records created after this date' do - datatable.params[:columns]['5'][:search][:value] = '31/12/1999-' + datatable.params[:columns]['6'][:search][:value] = '31/12/1999-' expect(datatable.data.size).to eq 2 end end context 'when end date is filled' do it 'filters records created before this date' do - datatable.params[:columns]['5'][:search][:value] = '-31/12/1999' + datatable.params[:columns]['6'][:search][:value] = '-31/12/1999' expect(datatable.data.size).to eq 0 end end context 'when both date are filled' do it 'filters records created between the range' do - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' + datatable.params[:columns]['6'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 end end @@ -268,7 +268,7 @@ context 'when range is empty' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '-' + datatable.params[:columns]['6'][:search][:value] = '-' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -278,7 +278,7 @@ context 'when start date is filled' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-' + datatable.params[:columns]['6'][:search][:value] = '01/12/1999-' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -288,7 +288,7 @@ context 'when end date is filled' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '-15/01/2000' + datatable.params[:columns]['6'][:search][:value] = '-15/01/2000' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -298,7 +298,7 @@ context 'when both date are filled' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000' + datatable.params[:columns]['6'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -318,7 +318,7 @@ let(:datatable) { DatatableCondEq.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 + datatable.params[:columns]['5'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:first_name]).to eq 'john' @@ -329,7 +329,7 @@ let(:datatable) { DatatableCondNotEq.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 + datatable.params[:columns]['5'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:first_name]).to eq 'mary' @@ -340,7 +340,7 @@ let(:datatable) { DatatableCondLt.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = 2 + datatable.params[:columns]['5'][:search][:value] = 2 expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:first_name]).to eq 'john' @@ -351,7 +351,7 @@ let(:datatable) { DatatableCondGt.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 + datatable.params[:columns]['5'][:search][:value] = 1 expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:first_name]).to eq 'mary' @@ -362,7 +362,7 @@ let(:datatable) { DatatableCondLteq.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = 2 + datatable.params[:columns]['5'][:search][:value] = 2 expect(datatable.data.size).to eq 2 end end @@ -371,7 +371,7 @@ let(:datatable) { DatatableCondGteq.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = 1 + datatable.params[:columns]['5'][:search][:value] = 1 expect(datatable.data.size).to eq 2 end end @@ -380,7 +380,7 @@ let(:datatable) { DatatableCondIn.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = [1] + datatable.params[:columns]['5'][:search][:value] = [1] expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:first_name]).to eq 'john' @@ -391,8 +391,8 @@ let(:datatable) { DatatableCondInWithRegex.new(sample_params) } it 'filters records matching' do - datatable.params[:columns]['4'][:search][:value] = '1|2' - datatable.params[:order]['0'] = { column: '4', dir: 'asc' } + datatable.params[:columns]['5'][:search][:value] = '1|2' + datatable.params[:order]['0'] = { column: '5', dir: 'asc' } expect(datatable.data.size).to eq 2 item = datatable.data.first expect(item[:first_name]).to eq 'john' @@ -411,17 +411,17 @@ end it 'Returns an empty result if input value is too large' do - datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + 1 + datatable.params[:columns]['5'][:search][:value] = largest_postgresql_integer_value + 1 expect(datatable.data.size).to eq 0 end it 'Returns an empty result if input value is too small' do - datatable.params[:columns]['4'][:search][:value] = smallest_postgresql_integer_value - 1 + datatable.params[:columns]['5'][:search][:value] = smallest_postgresql_integer_value - 1 expect(datatable.data.size).to eq 0 end it 'returns the matching user' do - datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + datatable.params[:columns]['5'][:search][:value] = largest_postgresql_integer_value expect(datatable.data.size).to eq 1 end end diff --git a/spec/support/datatables/complex_datatable.rb b/spec/support/datatables/complex_datatable.rb index faa7ce23..6969f74a 100644 --- a/spec/support/datatables/complex_datatable.rb +++ b/spec/support/datatables/complex_datatable.rb @@ -7,6 +7,7 @@ def view_columns email: { source: 'User.email' }, first_name: { source: 'User.first_name' }, last_name: { source: 'User.last_name' }, + full_name: { source: 'full_name' }, post_id: { source: 'User.post_id', orderable: false }, created_at: { source: 'User.created_at' }, } @@ -19,6 +20,7 @@ def data email: record.email, first_name: record.first_name, last_name: record.last_name, + full_name: record.full_name, post_id: record.post_id, created_at: record.created_at, } diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index 2fb41da6..b127b779 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -31,12 +31,18 @@ def sample_params } }, '4' => { - 'data' => 'post_id', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', + 'data' => 'full_name', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => '', 'regex' => 'false' } }, '5' => { + 'data' => 'post_id', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', + 'search' => { + 'value' => '', 'regex' => 'false' + } + }, + '6' => { 'data' => 'created_at', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => '', 'regex' => 'false' diff --git a/spec/support/models/user.rb b/spec/support/models/user.rb index b2c40d16..7ad18b20 100644 --- a/spec/support/models/user.rb +++ b/spec/support/models/user.rb @@ -1,4 +1,7 @@ # frozen_string_literal: true class User < ActiveRecord::Base + def full_name + "#{first_name} #{last_name}" + end end From b79f3bfc78142516583616e66a37004c7d98fdd4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 9 Feb 2021 22:55:38 +0100 Subject: [PATCH 192/290] Add tests on custom_field feature --- lib/ajax-datatables-rails/datatable/column.rb | 4 +-- .../datatable/column/search.rb | 8 ++---- .../orm/active_record_filter_records_spec.rb | 26 +++++++++++++++++-- .../datatables/datatable_custom_column.rb | 17 ++++++++++++ 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 spec/support/datatables/datatable_custom_column.rb diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index bdbee4d8..2698eec9 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -36,11 +36,11 @@ def table end def model - @model ||= source.split('.').first.constantize + @model ||= custom_field? ? source : source.split('.').first.constantize end def field - @field ||= source.split('.').last.to_sym + @field ||= custom_field? ? source : source.split('.').last.to_sym end def custom_field? diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index dde62128..581165fb 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -88,15 +88,11 @@ def null_value_search end def raw_search(cond) - if custom_field? - ::Arel::Nodes::SqlLiteral.new(field).eq(formatted_value) - else - table[field].send(cond, formatted_value) - end + table[field].send(cond, formatted_value) unless custom_field? end def text_search(value) - casted_column.matches(value) + casted_column.matches(value) unless custom_field? end def empty_search diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index cbe7538f..1dd108a3 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -410,12 +410,12 @@ create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value) end - it 'Returns an empty result if input value is too large' do + it 'returns an empty result if input value is too large' do datatable.params[:columns]['5'][:search][:value] = largest_postgresql_integer_value + 1 expect(datatable.data.size).to eq 0 end - it 'Returns an empty result if input value is too small' do + it 'returns an empty result if input value is too small' do datatable.params[:columns]['5'][:search][:value] = smallest_postgresql_integer_value - 1 expect(datatable.data.size).to eq 0 end @@ -597,6 +597,28 @@ }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchCondition).with_message('foo') end end + + context 'custom column' do + describe 'it can filter records with custom column' do + let(:datatable) { DatatableCustomColumn.new(sample_params) } + + before do + create(:user, username: 'msmith', email: 'mary.smith@example.com', first_name: 'Mary', last_name: 'Smith') + create(:user, username: 'jsmith', email: 'john.smith@example.com', first_name: 'John', last_name: 'Smith') + create(:user, username: 'johndoe', email: 'johndoe@example.com', first_name: 'John', last_name: 'Doe') + end + + it 'filters records' do + skip('unsupported database adapter') if RunningSpec.oracle? || RunningSpec.sqlite? + + datatable.params[:columns]['4'][:search][:value] = 'John' + datatable.params[:order]['0'][:column] = '4' + expect(datatable.data.size).to eq 2 + item = datatable.data.first + expect(item[:full_name]).to eq 'John Doe' + end + end + end end describe 'formatter option' do diff --git a/spec/support/datatables/datatable_custom_column.rb b/spec/support/datatables/datatable_custom_column.rb new file mode 100644 index 00000000..4740adea --- /dev/null +++ b/spec/support/datatables/datatable_custom_column.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class DatatableCustomColumn < ComplexDatatable + def view_columns + super.deep_merge(full_name: { cond: filter_full_name }) + end + + def get_raw_records + User.select("*, CONCAT(first_name, ' ', last_name) as full_name") + end + + private + + def filter_full_name + ->(_column, value) { ::Arel::Nodes::SqlLiteral.new("CONCAT(first_name, ' ', last_name)").matches("#{value}%") } + end +end From 448a754ef98afe5185b00ada052f92b64779d3e0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 7 Sep 2021 17:33:08 +0200 Subject: [PATCH 193/290] Ruby 2.5 is EOL --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9805798..5af6b500 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,6 @@ jobs: - '3.0' - '2.7' - '2.6' - - '2.5' rails: - rails_5.2.4 - rails_6.0.3 From 911a586084f46cfca179dccb6341215bf0aa1eb3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 17 Dec 2021 01:33:22 +0100 Subject: [PATCH 194/290] Ruby 2.5 is EOL (part2) --- .rubocop.yml | 2 +- ajax-datatables-rails.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 13b824c4..52c489f1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ AllCops: NewCops: enable SuggestExtensions: false - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.6 Exclude: - bin/* - lib/generators/**/*.rb diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index afe1b300..266332b9 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues', } - s.required_ruby_version = '>= 2.5.0' + s.required_ruby_version = '>= 2.6.0' s.files = `git ls-files`.split("\n") From be2ad4f196bc9ec02bc671edbed338680be4f3b3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 1 Jan 2021 18:46:33 +0100 Subject: [PATCH 195/290] Improve appraisal config --- Appraisals | 43 +++++++++++++++--------------------- Gemfile | 2 ++ appraisal.yml | 42 +++++++++++++++++++++++++++++++++++ gemfiles/rails_5.2.4.gemfile | 18 +++++++++++---- gemfiles/rails_6.0.3.gemfile | 18 +++++++++++---- gemfiles/rails_6.1.0.gemfile | 18 +++++++++++---- 6 files changed, 104 insertions(+), 37 deletions(-) create mode 100644 appraisal.yml diff --git a/Appraisals b/Appraisals index 801a5a17..90973ec5 100644 --- a/Appraisals +++ b/Appraisals @@ -1,34 +1,27 @@ # frozen_string_literal: true -RAILS_VERSIONS = { - '5.2.4' => { - 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', - 'sqlite3' => '~> 1.3.0', - 'mysql2' => '', - 'ruby-oci8' => '', - }, - '6.0.3' => { - 'activerecord-oracle_enhanced-adapter' => '~> 6.0.0', - 'sqlite3' => '~> 1.4.0', - 'mysql2' => '', - 'ruby-oci8' => '', - }, - '6.1.0' => { - 'activerecord-oracle_enhanced-adapter' => '~> 6.1.0', - 'sqlite3' => '~> 1.4.0', - 'mysql2' => '', - 'ruby-oci8' => '', - }, -}.freeze +require 'yaml' -RAILS_VERSIONS.each do |version, gems| +rails_versions = YAML.load(File.read('appraisal.yml')) + +rails_versions.each do |version, gems| appraise "rails_#{version}" do gem 'rails', version - gems.each do |name, gem_version| - if gem_version.empty? - gem name + gems.each do |name, opts| + if opts['install_if'] + install_if opts['install_if'] do + if opts['version'].empty? + gem name + else + gem name, opts['version'] + end + end else - gem name, gem_version + if opts['version'].empty? + gem name + else + gem name, opts['version'] + end end end end diff --git a/Gemfile b/Gemfile index 7f4f5e95..dc0861f5 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,5 @@ source 'https://rubygems.org' gemspec + +gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' diff --git a/appraisal.yml b/appraisal.yml new file mode 100644 index 00000000..cdf03723 --- /dev/null +++ b/appraisal.yml @@ -0,0 +1,42 @@ +--- +5.2.4: + sqlite3: + version: ~> 1.3.0 + install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' + mysql2: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-oracle_enhanced-adapter: + version: ~> 5.2.0 + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + ruby-oci8: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + +6.0.3: + sqlite3: + version: ~> 1.4.0 + install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' + mysql2: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-oracle_enhanced-adapter: + version: ~> 6.0.0 + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + ruby-oci8: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + +6.1.0: + sqlite3: + version: ~> 1.4.0 + install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' + mysql2: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-oracle_enhanced-adapter: + version: ~> 6.1.0 + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + ruby-oci8: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' diff --git a/gemfiles/rails_5.2.4.gemfile b/gemfiles/rails_5.2.4.gemfile index cb28c74f..9cc774f7 100644 --- a/gemfiles/rails_5.2.4.gemfile +++ b/gemfiles/rails_5.2.4.gemfile @@ -2,10 +2,20 @@ source "https://rubygems.org" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/install_if" gem "rails", "5.2.4" -gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" -gem "sqlite3", "~> 1.3.0" -gem "mysql2" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" + +install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do + gem "sqlite3", "~> 1.3.0" +end + +install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do + gem "mysql2" +end + +install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do + gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" + gem "ruby-oci8" +end gemspec path: "../" diff --git a/gemfiles/rails_6.0.3.gemfile b/gemfiles/rails_6.0.3.gemfile index c8169539..7aa6f2ef 100644 --- a/gemfiles/rails_6.0.3.gemfile +++ b/gemfiles/rails_6.0.3.gemfile @@ -2,10 +2,20 @@ source "https://rubygems.org" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/install_if" gem "rails", "6.0.3" -gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" -gem "sqlite3", "~> 1.4.0" -gem "mysql2" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" + +install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do + gem "sqlite3", "~> 1.4.0" +end + +install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do + gem "mysql2" +end + +install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do + gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" + gem "ruby-oci8" +end gemspec path: "../" diff --git a/gemfiles/rails_6.1.0.gemfile b/gemfiles/rails_6.1.0.gemfile index 6161d04e..329d2b4c 100644 --- a/gemfiles/rails_6.1.0.gemfile +++ b/gemfiles/rails_6.1.0.gemfile @@ -2,10 +2,20 @@ source "https://rubygems.org" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/install_if" gem "rails", "6.1.0" -gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0" -gem "sqlite3", "~> 1.4.0" -gem "mysql2" -gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" + +install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do + gem "sqlite3", "~> 1.4.0" +end + +install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do + gem "mysql2" +end + +install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do + gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0" + gem "ruby-oci8" +end gemspec path: "../" From 5e50b18cfe0022d62a857e45ead389f4276e3d1b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 17 Dec 2021 01:37:36 +0100 Subject: [PATCH 196/290] Test with latest Rails versions --- .github/workflows/ci.yml | 8 ++++---- appraisal.yml | 6 +++--- gemfiles/{rails_5.2.4.gemfile => rails_5.2.6.gemfile} | 4 ++-- gemfiles/{rails_6.0.3.gemfile => rails_6.0.4.gemfile} | 4 ++-- gemfiles/{rails_6.1.0.gemfile => rails_6.1.4.gemfile} | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) rename gemfiles/{rails_5.2.4.gemfile => rails_5.2.6.gemfile} (76%) rename gemfiles/{rails_6.0.3.gemfile => rails_6.0.4.gemfile} (76%) rename gemfiles/{rails_6.1.0.gemfile => rails_6.1.4.gemfile} (76%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5af6b500..54cec50c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,9 +50,9 @@ jobs: - '2.7' - '2.6' rails: - - rails_5.2.4 - - rails_6.0.3 - - rails_6.1.0 + - rails_5.2.6 + - rails_6.0.4 + - rails_6.1.4 adapter: - sqlite3 - postgresql @@ -60,7 +60,7 @@ jobs: - oracle_enhanced exclude: - ruby: '3.0' - rails: rails_5.2.4 + rails: rails_5.2.6 steps: - name: Checkout diff --git a/appraisal.yml b/appraisal.yml index cdf03723..7d8e82f7 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -1,5 +1,5 @@ --- -5.2.4: +5.2.6: sqlite3: version: ~> 1.3.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' @@ -13,7 +13,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' -6.0.3: +6.0.4: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' @@ -27,7 +27,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' -6.1.0: +6.1.4: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' diff --git a/gemfiles/rails_5.2.4.gemfile b/gemfiles/rails_5.2.6.gemfile similarity index 76% rename from gemfiles/rails_5.2.4.gemfile rename to gemfiles/rails_5.2.6.gemfile index 9cc774f7..98ac4e84 100644 --- a/gemfiles/rails_5.2.4.gemfile +++ b/gemfiles/rails_5.2.6.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/install_if" -gem "rails", "5.2.4" +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "rails", "5.2.6" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.3.0" diff --git a/gemfiles/rails_6.0.3.gemfile b/gemfiles/rails_6.0.4.gemfile similarity index 76% rename from gemfiles/rails_6.0.3.gemfile rename to gemfiles/rails_6.0.4.gemfile index 7aa6f2ef..dd59011e 100644 --- a/gemfiles/rails_6.0.3.gemfile +++ b/gemfiles/rails_6.0.4.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/install_if" -gem "rails", "6.0.3" +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "rails", "6.0.4" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" diff --git a/gemfiles/rails_6.1.0.gemfile b/gemfiles/rails_6.1.4.gemfile similarity index 76% rename from gemfiles/rails_6.1.0.gemfile rename to gemfiles/rails_6.1.4.gemfile index 329d2b4c..dfe79ac3 100644 --- a/gemfiles/rails_6.1.0.gemfile +++ b/gemfiles/rails_6.1.4.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/install_if" -gem "rails", "6.1.0" +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "rails", "6.1.4" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" From b6569e33e3eb8210ddeeeb0769fadcd5a24fcfa7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 17 Dec 2021 01:43:42 +0100 Subject: [PATCH 197/290] Rails 7 is out \o/ --- .github/workflows/ci.yml | 3 +++ appraisal.yml | 14 ++++++++++++++ gemfiles/rails_7.0.0.gemfile | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 gemfiles/rails_7.0.0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54cec50c..7356bb66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,12 +53,15 @@ jobs: - rails_5.2.6 - rails_6.0.4 - rails_6.1.4 + - rails_7.0.0 adapter: - sqlite3 - postgresql - mysql2 - oracle_enhanced exclude: + - ruby: '2.6' + rails: rails_7.0.0 - ruby: '3.0' rails: rails_5.2.6 diff --git a/appraisal.yml b/appraisal.yml index 7d8e82f7..6e9ee5ca 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -40,3 +40,17 @@ ruby-oci8: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + +7.0.0: + sqlite3: + version: ~> 1.4.0 + install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' + mysql2: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-oracle_enhanced-adapter: + version: ~> 7.0.0 + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + ruby-oci8: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' diff --git a/gemfiles/rails_7.0.0.gemfile b/gemfiles/rails_7.0.0.gemfile new file mode 100644 index 00000000..c3b960ec --- /dev/null +++ b/gemfiles/rails_7.0.0.gemfile @@ -0,0 +1,21 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "rails", "7.0.0" + +install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do + gem "sqlite3", "~> 1.4.0" +end + +install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do + gem "mysql2" +end + +install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do + gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" + gem "ruby-oci8" +end + +gemspec path: "../" From d28ceed379a6df9263cebcbb3a385cebe0604bfc Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 9 Jan 2022 00:33:54 +0100 Subject: [PATCH 198/290] Test with Rails 7.0.1 --- .github/workflows/ci.yml | 4 ++-- appraisal.yml | 2 +- gemfiles/{rails_7.0.0.gemfile => rails_7.0.1.gemfile} | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename gemfiles/{rails_7.0.0.gemfile => rails_7.0.1.gemfile} (95%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7356bb66..a1064bcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: - rails_5.2.6 - rails_6.0.4 - rails_6.1.4 - - rails_7.0.0 + - rails_7.0.1 adapter: - sqlite3 - postgresql @@ -61,7 +61,7 @@ jobs: - oracle_enhanced exclude: - ruby: '2.6' - rails: rails_7.0.0 + rails: rails_7.0.1 - ruby: '3.0' rails: rails_5.2.6 diff --git a/appraisal.yml b/appraisal.yml index 6e9ee5ca..5463d734 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -41,7 +41,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' -7.0.0: +7.0.1: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' diff --git a/gemfiles/rails_7.0.0.gemfile b/gemfiles/rails_7.0.1.gemfile similarity index 95% rename from gemfiles/rails_7.0.0.gemfile rename to gemfiles/rails_7.0.1.gemfile index c3b960ec..4a8c4bfb 100644 --- a/gemfiles/rails_7.0.0.gemfile +++ b/gemfiles/rails_7.0.1.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "rails", "7.0.0" +gem "rails", "7.0.1" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" From f3008c6f98a2fa3f23076e02111608640efe945d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 9 Jan 2022 01:27:39 +0100 Subject: [PATCH 199/290] Ruby 3.1 is out \o/ --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1064bcb..54f5a548 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,7 @@ jobs: fail-fast: false matrix: ruby: + - '3.1' - '3.0' - '2.7' - '2.6' @@ -64,6 +65,8 @@ jobs: rails: rails_7.0.1 - ruby: '3.0' rails: rails_5.2.6 + - ruby: '3.1' + rails: rails_5.2.6 steps: - name: Checkout From 195be6dcb23364ab76f3adf8c97b01bfc07d9293 Mon Sep 17 00:00:00 2001 From: Marcus Ilgner Date: Wed, 23 Feb 2022 10:21:46 +0100 Subject: [PATCH 200/290] fix: prevent establishing ActiveRecord connection on startup Instead of creating a connection and looking at its database adapter, look at the configured adapter instead. This prevents issues when trying to compile assets or running other rake tasks in `RAILS_ENV=production` that are supposed to work without a running database. --- lib/ajax-datatables-rails/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 6f20a7e0..e2fecfc6 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -3,7 +3,7 @@ module AjaxDatatablesRails class Base - class_attribute :db_adapter, default: ::ActiveRecord::Base.connection.adapter_name.downcase.to_sym + class_attribute :db_adapter, default: ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.adapter.downcase.to_sym class_attribute :nulls_last, default: false attr_reader :params, :options, :datatable From 5b81aed17e15d975f2d9eb3462a533941e63f5aa Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 7 Sep 2022 02:35:22 +0200 Subject: [PATCH 201/290] Run CI once a month --- .github/workflows/ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54f5a548..4e537981 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,14 @@ name: CI on: - - push - - pull_request + push: + branches: + - '**' + pull_request: + branches: + - '**' + schedule: + - cron: '0 4 1 * *' jobs: rspec: From e3a798c1dfc5c9cbd4840e66ad88796896792d75 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 26 Oct 2022 01:04:43 +0200 Subject: [PATCH 202/290] Use Combustion gem to run tests --- .gitignore | 9 ++++--- Gemfile | 2 +- ajax-datatables-rails.gemspec | 5 +++- bin/rackup | 27 ++++++++++++++++++++ config.ru | 7 ++++++ gemfiles/rails_5.2.6.gemfile | 2 +- gemfiles/rails_6.0.4.gemfile | 2 +- gemfiles/rails_6.1.4.gemfile | 2 +- gemfiles/rails_7.0.1.gemfile | 2 +- spec/dummy/app/assets/config/manifest.js | 0 spec/dummy/config/database.yml | 25 ++++++++++++++++++ spec/dummy/config/routes.rb | 5 ++++ spec/dummy/config/storage.yml | 3 +++ spec/{support => dummy/db}/schema.rb | 3 --- spec/dummy/log/.gitignore | 1 + spec/dummy/public/favicon.ico | 0 spec/spec_helper.rb | 32 ++++-------------------- 17 files changed, 88 insertions(+), 39 deletions(-) create mode 100755 bin/rackup create mode 100644 config.ru create mode 100644 spec/dummy/app/assets/config/manifest.js create mode 100644 spec/dummy/config/database.yml create mode 100644 spec/dummy/config/routes.rb create mode 100644 spec/dummy/config/storage.yml rename spec/{support => dummy/db}/schema.rb (91%) create mode 100644 spec/dummy/log/.gitignore create mode 100644 spec/dummy/public/favicon.ico diff --git a/.gitignore b/.gitignore index 431da6a1..5c8920df 100644 --- a/.gitignore +++ b/.gitignore @@ -10,11 +10,14 @@ /coverage /tmp -# Ignore sqlite db file -/ajax_datatables_rails - # RVM files /.ruby-version # Gem files /*.gem + +# Ignore dummy app files +spec/dummy/db/*.sqlite3 +spec/dummy/db/*.sqlite3-journal +spec/dummy/log/*.log +spec/dummy/tmp/ diff --git a/Gemfile b/Gemfile index dc0861f5..063266df 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ source 'https://rubygems.org' gemspec -gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' +gem 'appraisal', git: 'https://github.com/n-rodriguez/appraisal.git', branch: 'wip/combustion' diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 266332b9..fb73982b 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -23,21 +23,24 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") + s.add_runtime_dependency 'rails', '>= 5.2' s.add_runtime_dependency 'zeitwerk' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' s.add_development_dependency 'appraisal' + s.add_development_dependency 'combustion', '~> 1.3' s.add_development_dependency 'database_cleaner' s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' s.add_development_dependency 'generator_spec' s.add_development_dependency 'guard-rspec' s.add_development_dependency 'pg' + s.add_development_dependency 'puma' s.add_development_dependency 'pry' - s.add_development_dependency 'rails', '>= 5.2' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'rspec-retry' s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov' + s.add_development_dependency 'sqlite3', '~> 1.4.0' end diff --git a/bin/rackup b/bin/rackup new file mode 100755 index 00000000..7023745e --- /dev/null +++ b/bin/rackup @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rackup' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rack", "rackup") diff --git a/config.ru b/config.ru new file mode 100644 index 00000000..8e5bee22 --- /dev/null +++ b/config.ru @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +Bundler.require :default, :development + +Combustion.path = 'spec/dummy' +Combustion.initialize! :all +run Combustion::Application diff --git a/gemfiles/rails_5.2.6.gemfile b/gemfiles/rails_5.2.6.gemfile index 98ac4e84..4e1978ce 100644 --- a/gemfiles/rails_5.2.6.gemfile +++ b/gemfiles/rails_5.2.6.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" gem "rails", "5.2.6" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/gemfiles/rails_6.0.4.gemfile b/gemfiles/rails_6.0.4.gemfile index dd59011e..eded71aa 100644 --- a/gemfiles/rails_6.0.4.gemfile +++ b/gemfiles/rails_6.0.4.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" gem "rails", "6.0.4" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/gemfiles/rails_6.1.4.gemfile b/gemfiles/rails_6.1.4.gemfile index dfe79ac3..cbf8c975 100644 --- a/gemfiles/rails_6.1.4.gemfile +++ b/gemfiles/rails_6.1.4.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" gem "rails", "6.1.4" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/gemfiles/rails_7.0.1.gemfile b/gemfiles/rails_7.0.1.gemfile index 4a8c4bfb..0d10d4d7 100644 --- a/gemfiles/rails_7.0.1.gemfile +++ b/gemfiles/rails_7.0.1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" gem "rails", "7.0.1" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js new file mode 100644 index 00000000..e69de29b diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml new file mode 100644 index 00000000..949cea8e --- /dev/null +++ b/spec/dummy/config/database.yml @@ -0,0 +1,25 @@ +<% adapter = ENV.fetch('DB_ADAPTER', 'postgresql') %> +test: + adapter: <%= adapter %> + database: ajax_datatables_rails + encoding: utf8 + +<% if adapter == 'postgresql' %> + host: '127.0.0.1' + port: 5432 + username: 'postgres' + password: 'postgres' +<% elsif adapter == 'mysql2' %> + host: '127.0.0.1' + port: 3306 + username: 'root' + password: 'root' +<% elsif adapter == 'oracle_enhanced' %> + host: '127.0.0.1/xe' + username: <%= ENV.fetch('USER') %> + password: <%= ENV.fetch('USER') %> + database: 'xe' +<% elsif adapter == 'sqlite3' %> + # database: ':memory:' + database: db/ajax_datatables_rails.sqlite3 +<% end %> diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb new file mode 100644 index 00000000..878c8133 --- /dev/null +++ b/spec/dummy/config/routes.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Rails.application.routes.draw do + # Add your own routes here, or remove this file if you don't have need for it. +end diff --git a/spec/dummy/config/storage.yml b/spec/dummy/config/storage.yml new file mode 100644 index 00000000..5226545b --- /dev/null +++ b/spec/dummy/config/storage.yml @@ -0,0 +1,3 @@ +test: + service: Disk + root: /tmp/ajax-datatables-rails/tmp/storage diff --git a/spec/support/schema.rb b/spec/dummy/db/schema.rb similarity index 91% rename from spec/support/schema.rb rename to spec/dummy/db/schema.rb index 69a10cb1..653121e2 100644 --- a/spec/support/schema.rb +++ b/spec/dummy/db/schema.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true ActiveRecord::Schema.define do - self.verbose = false - create_table :users, force: true do |t| t.string :username t.string :email @@ -12,5 +10,4 @@ t.timestamps null: false end - end diff --git a/spec/dummy/log/.gitignore b/spec/dummy/log/.gitignore new file mode 100644 index 00000000..397b4a76 --- /dev/null +++ b/spec/dummy/log/.gitignore @@ -0,0 +1 @@ +*.log diff --git a/spec/dummy/public/favicon.ico b/spec/dummy/public/favicon.ico new file mode 100644 index 00000000..e69de29b diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 72c66b3b..d0420151 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,10 @@ # frozen_string_literal: true +require 'combustion' + +Combustion.path = 'spec/dummy' +Combustion.initialize! :active_record, :action_controller + require 'simplecov' require 'rspec' require 'rspec/retry' @@ -7,9 +12,6 @@ require 'factory_bot' require 'faker' require 'pry' -require 'rails' -require 'active_record' -require 'action_controller' # Start Simplecov SimpleCov.start do @@ -79,30 +81,6 @@ def self.postgresql? end end -# Configure ActiveRecord -adapter = ENV.fetch('DB_ADAPTER', 'postgresql') -ENV['DB_ADAPTER'] = adapter - -options = { - adapter: adapter, - database: 'ajax_datatables_rails', - encoding: 'utf8', -} - -options = - case adapter - when 'postgresql' - options.merge(host: '127.0.0.1', port: 5432, username: 'postgres', password: 'postgres') - when 'mysql2' - options.merge(host: '127.0.0.1', port: 3306, username: 'root', password: 'root') - when 'oracle_enhanced' - options.merge(host: '127.0.0.1/xe', username: ENV['USER'], password: ENV['USER'], database: 'xe') - when 'sqlite3' - options.merge(database: ':memory:') - end - -ActiveRecord::Base.establish_connection(options) - # Require our gem require 'ajax-datatables-rails' From 5c0e274ff2aa750f4198d4a9bff851895908c9c1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 26 Oct 2022 16:12:54 +0200 Subject: [PATCH 203/290] Improve previous patch to support older versions of Rails --- lib/ajax-datatables-rails/base.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index e2fecfc6..989f57eb 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -3,7 +3,27 @@ module AjaxDatatablesRails class Base - class_attribute :db_adapter, default: ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.adapter.downcase.to_sym + class << self + def rails_52? + Rails.gem_version >= Gem::Version.new('5.2') && Rails.gem_version <= Gem::Version.new('6.0') + end + + def rails_60? + Rails.gem_version >= Gem::Version.new('6.0') && Rails.gem_version <= Gem::Version.new('6.1') + end + + def default_db_adapter + if rails_52? + ::ActiveRecord::Base.configurations.dig(Rails.env, 'adapter').downcase.to_sym + elsif rails_60? + ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.config['adapter'].downcase.to_sym + else + ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.adapter.downcase.to_sym + end + end + end + + class_attribute :db_adapter, default: default_db_adapter class_attribute :nulls_last, default: false attr_reader :params, :options, :datatable From ff31842a68cf3906bf86bc04f82e41fb7906dc2d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 27 Oct 2022 02:08:23 +0200 Subject: [PATCH 204/290] Add missing Oracle adapter name --- lib/ajax-datatables-rails/datatable/column.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 2698eec9..1c169d24 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -66,13 +66,14 @@ def formatted_value TYPE_CAST_SQLSERVER = 'VARCHAR(4000)' DB_ADAPTER_TYPE_CAST = { - mysql: TYPE_CAST_MYSQL, - mysql2: TYPE_CAST_MYSQL, - sqlite: TYPE_CAST_SQLITE, - sqlite3: TYPE_CAST_SQLITE, - oracle: TYPE_CAST_ORACLE, - oracleenhanced: TYPE_CAST_ORACLE, - sqlserver: TYPE_CAST_SQLSERVER, + mysql: TYPE_CAST_MYSQL, + mysql2: TYPE_CAST_MYSQL, + sqlite: TYPE_CAST_SQLITE, + sqlite3: TYPE_CAST_SQLITE, + oracle: TYPE_CAST_ORACLE, + oracleenhanced: TYPE_CAST_ORACLE, + oracle_enhanced: TYPE_CAST_ORACLE, + sqlserver: TYPE_CAST_SQLSERVER, }.freeze private_constant :TYPE_CAST_DEFAULT From 8c906e4001ca1c4bd35191a8a23eea1843412e19 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 27 Oct 2022 02:18:25 +0200 Subject: [PATCH 205/290] Improve CodeClimate config --- .codeclimate.yml | 28 +++++----------------------- ajax-datatables-rails.gemspec | 2 +- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 42a049b1..6cdba48a 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,26 +1,8 @@ --- -engines: - duplication: - enabled: true - config: - languages: - - ruby - - javascript - - python - - php - fixme: - enabled: true +plugins: rubocop: enabled: true -ratings: - paths: - - "**.inc" - - "**.js" - - "**.jsx" - - "**.module" - - "**.php" - - "**.py" - - "**.rb" -exclude_paths: -- spec/ -- lib/generators/rails/templates/ + channel: rubocop-1-31-0 +exclude_patterns: + - spec/ + - lib/generators/rails/templates/ diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index fb73982b..6921d716 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -35,8 +35,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'generator_spec' s.add_development_dependency 'guard-rspec' s.add_development_dependency 'pg' - s.add_development_dependency 'puma' s.add_development_dependency 'pry' + s.add_development_dependency 'puma' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'rspec-retry' From 8d73e45b297652757dfa0ee53d190f1677a41b44 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Dec 2022 16:33:53 +0100 Subject: [PATCH 206/290] Drop support of Ruby 2.6, test with latest Rails versions --- .github/workflows/ci.yml | 15 ++++++--------- .rubocop.yml | 2 +- ajax-datatables-rails.gemspec | 2 +- appraisal.yml | 8 ++++---- .../{rails_5.2.6.gemfile => rails_5.2.8.gemfile} | 2 +- .../{rails_6.0.4.gemfile => rails_6.0.6.gemfile} | 2 +- .../{rails_6.1.4.gemfile => rails_6.1.7.gemfile} | 2 +- .../{rails_7.0.1.gemfile => rails_7.0.4.gemfile} | 2 +- 8 files changed, 16 insertions(+), 19 deletions(-) rename gemfiles/{rails_5.2.6.gemfile => rails_5.2.8.gemfile} (95%) rename gemfiles/{rails_6.0.4.gemfile => rails_6.0.6.gemfile} (95%) rename gemfiles/{rails_6.1.4.gemfile => rails_6.1.7.gemfile} (95%) rename gemfiles/{rails_7.0.1.gemfile => rails_7.0.4.gemfile} (95%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e537981..08534ca1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,24 +55,21 @@ jobs: - '3.1' - '3.0' - '2.7' - - '2.6' rails: - - rails_5.2.6 - - rails_6.0.4 - - rails_6.1.4 - - rails_7.0.1 + - rails_5.2.8 + - rails_6.0.6 + - rails_6.1.7 + - rails_7.0.4 adapter: - sqlite3 - postgresql - mysql2 - oracle_enhanced exclude: - - ruby: '2.6' - rails: rails_7.0.1 - ruby: '3.0' - rails: rails_5.2.6 + rails: rails_5.2.8 - ruby: '3.1' - rails: rails_5.2.6 + rails: rails_5.2.8 steps: - name: Checkout diff --git a/.rubocop.yml b/.rubocop.yml index 52c489f1..ba60a761 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ AllCops: NewCops: enable SuggestExtensions: false - TargetRubyVersion: 2.6 + TargetRubyVersion: 2.7 Exclude: - bin/* - lib/generators/**/*.rb diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 6921d716..2bca6f1b 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues', } - s.required_ruby_version = '>= 2.6.0' + s.required_ruby_version = '>= 2.7.0' s.files = `git ls-files`.split("\n") diff --git a/appraisal.yml b/appraisal.yml index 5463d734..69b3b873 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -1,5 +1,5 @@ --- -5.2.6: +5.2.8: sqlite3: version: ~> 1.3.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' @@ -13,7 +13,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' -6.0.4: +6.0.6: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' @@ -27,7 +27,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' -6.1.4: +6.1.7: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' @@ -41,7 +41,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' -7.0.1: +7.0.4: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' diff --git a/gemfiles/rails_5.2.6.gemfile b/gemfiles/rails_5.2.8.gemfile similarity index 95% rename from gemfiles/rails_5.2.6.gemfile rename to gemfiles/rails_5.2.8.gemfile index 4e1978ce..6bd2b296 100644 --- a/gemfiles/rails_5.2.6.gemfile +++ b/gemfiles/rails_5.2.8.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "rails", "5.2.6" +gem "rails", "5.2.8" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.3.0" diff --git a/gemfiles/rails_6.0.4.gemfile b/gemfiles/rails_6.0.6.gemfile similarity index 95% rename from gemfiles/rails_6.0.4.gemfile rename to gemfiles/rails_6.0.6.gemfile index eded71aa..0c23f5dd 100644 --- a/gemfiles/rails_6.0.4.gemfile +++ b/gemfiles/rails_6.0.6.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "rails", "6.0.4" +gem "rails", "6.0.6" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" diff --git a/gemfiles/rails_6.1.4.gemfile b/gemfiles/rails_6.1.7.gemfile similarity index 95% rename from gemfiles/rails_6.1.4.gemfile rename to gemfiles/rails_6.1.7.gemfile index cbf8c975..19b7fbd6 100644 --- a/gemfiles/rails_6.1.4.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "rails", "6.1.4" +gem "rails", "6.1.7" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" diff --git a/gemfiles/rails_7.0.1.gemfile b/gemfiles/rails_7.0.4.gemfile similarity index 95% rename from gemfiles/rails_7.0.1.gemfile rename to gemfiles/rails_7.0.4.gemfile index 0d10d4d7..0ec19b30 100644 --- a/gemfiles/rails_7.0.1.gemfile +++ b/gemfiles/rails_7.0.4.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "rails", "7.0.1" +gem "rails", "7.0.4" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" From 55fca0508dcda8eb0d312ae51d0a1c2af9511982 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Dec 2022 16:35:20 +0100 Subject: [PATCH 207/290] Update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a4603d..4557ade2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # CHANGELOG +## 1.4.0 + +* Improve tests +* Add tests on custom_field feature +* Drop support of Ruby 2.5 +* Drop support of Ruby 2.6 +* Add support of Ruby 3.1 +* Add support of Rails 7 +* Fix: prevent establishing ActiveRecord connection on startup + ## 1.3.1 (2021-02-09) * Fix rare case error `uninitialized constant AjaxDatatablesRails::ActiveRecord::Base` (merge: [#379](https://github.com/jbox-web/ajax-datatables-rails/pull/379)) From 3b7fef16f2b2c1d74fe0a0d48d269c3108977987 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Dec 2022 16:47:49 +0100 Subject: [PATCH 208/290] Bump to version 1.4.0 --- lib/ajax-datatables-rails/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 474afce9..3e926b16 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -8,8 +8,8 @@ def self.gem_version module VERSION MAJOR = 1 - MINOR = 3 - TINY = 1 + MINOR = 4 + TINY = 0 PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') From bb5381d76e17504132fdf82d0d7bf90c75c4a42f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Dec 2022 16:51:08 +0100 Subject: [PATCH 209/290] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4557ade2..cf677fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 1.4.0 +## 1.4.0 (2022-12-18) * Improve tests * Add tests on custom_field feature From 8db7932f276b2628399d78dacf02ec3d97538223 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Dec 2022 17:04:03 +0100 Subject: [PATCH 210/290] Drop support of Rails 5.2 --- .github/workflows/ci.yml | 6 ------ README.md | 4 ++-- ajax-datatables-rails.gemspec | 2 +- appraisal.yml | 14 -------------- gemfiles/rails_5.2.8.gemfile | 21 --------------------- 5 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 gemfiles/rails_5.2.8.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08534ca1..ca5965ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,6 @@ jobs: - '3.0' - '2.7' rails: - - rails_5.2.8 - rails_6.0.6 - rails_6.1.7 - rails_7.0.4 @@ -65,11 +64,6 @@ jobs: - postgresql - mysql2 - oracle_enhanced - exclude: - - ruby: '3.0' - rails: rails_5.2.8 - - ruby: '3.1' - rails: rails_5.2.8 steps: - name: Checkout diff --git a/README.md b/README.md index c0e3f866..6577bd97 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ It's tested against : -* Rails 5.2.4 / 6.0.3 / 6.1.0 -* Ruby 2.5.x / 2.6.x / 2.7.x +* Rails 6.0.6 / 6.1.7 / 7.0.4 +* Ruby 2.7 / 3.0 / 3.1 * SQLite3 * Postgresql 13 * MySQL 8 diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 2bca6f1b..09facdcf 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_runtime_dependency 'rails', '>= 5.2' + s.add_runtime_dependency 'rails', '>= 6.0' s.add_runtime_dependency 'zeitwerk' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' diff --git a/appraisal.yml b/appraisal.yml index 69b3b873..d0baf6e2 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -1,18 +1,4 @@ --- -5.2.8: - sqlite3: - version: ~> 1.3.0 - install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' - mysql2: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' - activerecord-oracle_enhanced-adapter: - version: ~> 5.2.0 - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - ruby-oci8: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - 6.0.6: sqlite3: version: ~> 1.4.0 diff --git a/gemfiles/rails_5.2.8.gemfile b/gemfiles/rails_5.2.8.gemfile deleted file mode 100644 index 6bd2b296..00000000 --- a/gemfiles/rails_5.2.8.gemfile +++ /dev/null @@ -1,21 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "rails", "5.2.8" - -install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.3.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do - gem "mysql2" -end - -install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0" - gem "ruby-oci8" -end - -gemspec path: "../" From 7f19dc6d255a508cd43310a0d42134af0db85b77 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Dec 2022 17:05:55 +0100 Subject: [PATCH 211/290] Test with Ruby 3.2 rc --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca5965ae..8506bda5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,13 +52,15 @@ jobs: fail-fast: false matrix: ruby: + - '3.2' - '3.1' - '3.0' - '2.7' + - 'head' rails: - - rails_6.0.6 - - rails_6.1.7 - rails_7.0.4 + - rails_6.1.7 + - rails_6.0.6 adapter: - sqlite3 - postgresql From eae8844986847b43e224eae889cf66f116d1175d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 18 Mar 2023 01:39:10 +0100 Subject: [PATCH 212/290] Bump to ubuntu-latest, fix Github Actions warnings --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8506bda5..805300ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ on: jobs: rspec: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest env: ORACLE_COOKIE: sqldev @@ -69,7 +69,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -96,7 +96,7 @@ jobs: fi - name: Setup Ruby cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: vendor/bundle key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}-${{ hashFiles('**/Gemfile.lock') }} @@ -114,7 +114,7 @@ jobs: bundle install --jobs 4 --retry 3 - name: RSpec & publish code coverage - uses: paambaati/codeclimate-action@v2.7.5 + uses: paambaati/codeclimate-action@v3.2.0 env: RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} From 582238e1bd2af7221904c8da752f9825182797a5 Mon Sep 17 00:00:00 2001 From: Dave Morehouse Date: Wed, 19 Apr 2023 08:03:18 -0500 Subject: [PATCH 213/290] Fix server-side out of order ajax responses by returning the passed in draw (counter) parameter. --- lib/ajax-datatables-rails/base.rb | 4 +++- spec/ajax-datatables-rails/base_spec.rb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 989f57eb..83dc2067 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -73,11 +73,13 @@ def additional_data # JSON structure sent to jQuery DataTables def as_json(*) + draw_resp = (params[:draw].present?) ? { draw: params[:draw].to_i } : { } + { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, data: sanitize_data(data), - }.merge(additional_data) + }.merge(draw_resp).merge(additional_data) end # User helper methods diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 02ce8acb..17d3738b 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -181,6 +181,7 @@ def paginate_records(records) data = datatable.as_json expect(data[:recordsTotal]).to eq 5 expect(data[:recordsFiltered]).to eq 5 + expect(data[:draw]).to eq 1 expect(data[:data]).to be_a(Array) expect(data[:data].size).to eq 5 end @@ -192,6 +193,7 @@ def paginate_records(records) data = datatable.as_json expect(data[:recordsTotal]).to eq 5 expect(data[:recordsFiltered]).to eq 5 + expect(data[:draw]).to eq 1 expect(data[:data]).to be_a(Array) expect(data[:data].size).to eq 5 expect(data[:foo]).to eq 'bar' From febe5ba08fb655db13202a4b0383798b33827ec7 Mon Sep 17 00:00:00 2001 From: Dave Morehouse Date: Wed, 19 Apr 2023 09:21:28 -0500 Subject: [PATCH 214/290] Add support for grouped results --- lib/ajax-datatables-rails/base.rb | 8 +++- .../orm/active_record_count_records_spec.rb | 42 +++++++++++++++++++ .../datatables/grouped_datatable_array.rb | 8 ++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb create mode 100644 spec/support/datatables/grouped_datatable_array.rb diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 989f57eb..38f467ca 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -137,11 +137,15 @@ def retrieve_records end def records_total_count - fetch_records.count(:all) + numeric_count(fetch_records.count(:all)) end def records_filtered_count - filter_records(fetch_records).count(:all) + numeric_count(filter_records(fetch_records).count(:all)) + end + + def numeric_count(count) + count.is_a?(Hash) ? count.values.size : count end def global_search_delimiter diff --git a/spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb new file mode 100644 index 00000000..4c5c2be3 --- /dev/null +++ b/spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do + + let(:datatable) { ComplexDatatable.new(sample_params) } + let(:records) { User.all } + + describe '#records_total_count' do + context 'ungrouped results' do + it 'returns the count' do + expect(datatable.send(:records_total_count)).to eq records.count + end + end + + context 'grouped results' do + let(:datatable) { GroupedDatatable.new(sample_params) } + + it 'returns the count' do + expect(datatable.send(:records_total_count)).to eq records.count + end + end + end + + + describe '#records_filtered_count' do + context 'ungrouped results' do + it 'returns the count' do + expect(datatable.send(:records_filtered_count)).to eq records.count + end + end + + context 'grouped results' do + let(:datatable) { GroupedDatatable.new(sample_params) } + + it 'returns the count' do + expect(datatable.send(:records_filtered_count)).to eq records.count + end + end + end +end diff --git a/spec/support/datatables/grouped_datatable_array.rb b/spec/support/datatables/grouped_datatable_array.rb new file mode 100644 index 00000000..e4547adf --- /dev/null +++ b/spec/support/datatables/grouped_datatable_array.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class GroupedDatatable < ComplexDatatable + + def get_raw_records + User.all.group(:id) + end +end From 9b6f949a1ff9a288304b16cedce0d2cc7331f22e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 19 Apr 2023 20:46:13 +0200 Subject: [PATCH 215/290] Extract method --- lib/ajax-datatables-rails/base.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 58fbd6e5..e653b7ec 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -73,13 +73,11 @@ def additional_data # JSON structure sent to jQuery DataTables def as_json(*) - draw_resp = (params[:draw].present?) ? { draw: params[:draw].to_i } : { } - { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, data: sanitize_data(data), - }.merge(draw_resp).merge(additional_data) + }.merge(draw_id).merge(additional_data) end # User helper methods @@ -154,6 +152,11 @@ def global_search_delimiter GLOBAL_SEARCH_DELIMITER end + # See: https://datatables.net/manual/server-side#Returned-data + def draw_id + params[:draw].present? ? { draw: params[:draw].to_i } : {} + end + def raw_records_error_text <<-ERROR From 714a6c7b9bc9e98358231c9005a2487619102c3c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 19 Apr 2023 20:48:14 +0200 Subject: [PATCH 216/290] Coding style --- Appraisals | 2 +- lib/ajax-datatables-rails/base.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Appraisals b/Appraisals index 90973ec5..4d4315de 100644 --- a/Appraisals +++ b/Appraisals @@ -2,7 +2,7 @@ require 'yaml' -rails_versions = YAML.load(File.read('appraisal.yml')) +rails_versions = YAML.safe_load(File.read('appraisal.yml')) rails_versions.each do |version, gems| appraise "rails_#{version}" do diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index e653b7ec..208f1204 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -137,11 +137,11 @@ def retrieve_records end def records_total_count - numeric_count(fetch_records.count(:all)) + numeric_count fetch_records.count(:all) end def records_filtered_count - numeric_count(filter_records(fetch_records).count(:all)) + numeric_count filter_records(fetch_records).count(:all) end def numeric_count(count) From 518b0162588bccb6bcf4f64c82f1391e958bc826 Mon Sep 17 00:00:00 2001 From: Adrian Hooper Date: Fri, 9 Dec 2022 10:57:52 +0000 Subject: [PATCH 217/290] 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' From 7ed2bcca0c7560e4393db53c8a8f279c302ef159 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 9 Oct 2023 13:10:56 +0200 Subject: [PATCH 218/290] Test with latest Rails versions --- .github/workflows/ci.yml | 2 +- appraisal.yml | 2 +- gemfiles/{rails_7.0.4.gemfile => rails_7.0.8.gemfile} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename gemfiles/{rails_7.0.4.gemfile => rails_7.0.8.gemfile} (96%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 805300ac..a67bd6e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - '2.7' - 'head' rails: - - rails_7.0.4 + - rails_7.0.8 - rails_6.1.7 - rails_6.0.6 adapter: diff --git a/appraisal.yml b/appraisal.yml index 51610ce8..b0ddc99d 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -33,7 +33,7 @@ version: '' install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' -7.0.4: +7.0.8: sqlite3: version: ~> 1.4.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' diff --git a/gemfiles/rails_7.0.4.gemfile b/gemfiles/rails_7.0.8.gemfile similarity index 96% rename from gemfiles/rails_7.0.4.gemfile rename to gemfiles/rails_7.0.8.gemfile index 29c06cd1..8f02aebe 100644 --- a/gemfiles/rails_7.0.4.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "rails", "7.0.4" +gem "rails", "7.0.8" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do gem "sqlite3", "~> 1.4.0" From 82064090510662607e49b7fb02ae50f088cc87c3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 9 Oct 2023 13:18:40 +0200 Subject: [PATCH 219/290] Rails 7.1 is out --- .github/workflows/ci.yml | 1 + appraisal.yml | 17 +++++++++++++++++ gemfiles/rails_7.1.0.gemfile | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 gemfiles/rails_7.1.0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a67bd6e3..b04e7e6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,7 @@ jobs: - '2.7' - 'head' rails: + - rails_7.1.0 - rails_7.0.8 - rails_6.1.7 - rails_6.0.6 diff --git a/appraisal.yml b/appraisal.yml index b0ddc99d..e5de3f2e 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -49,3 +49,20 @@ activerecord-postgis-adapter: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' + +7.1.0: + sqlite3: + version: ~> 1.4.0 + install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' + mysql2: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + # activerecord-oracle_enhanced-adapter: + # version: ~> 7.0.0 + # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + # 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_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile new file mode 100644 index 00000000..4f58f57f --- /dev/null +++ b/gemfiles/rails_7.1.0.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "rails", "7.1.0" + +install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do + gem "sqlite3", "~> 1.4.0" +end + +install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do + gem "mysql2" +end + +install_if -> { ENV["DB_ADAPTER"] == "postgis" } do + gem "activerecord-postgis-adapter" +end + +gemspec path: "../" From 6f7f5be84f55c8af1d978a6296742d96e7f0faa2 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 09:07:44 +0000 Subject: [PATCH 220/290] Add support for trilogy adapter --- lib/ajax-datatables-rails/datatable/column.rb | 1 + lib/ajax-datatables-rails/datatable/simple_order.rb | 2 +- spec/ajax-datatables-rails/datatable/column_spec.rb | 5 +++++ .../orm/active_record_filter_records_spec.rb | 10 ++++++++++ spec/dummy/config/database.yml | 5 +++++ spec/spec_helper.rb | 2 +- spec/support/helpers/params.rb | 2 +- 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 1c169d24..747e546c 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -68,6 +68,7 @@ def formatted_value DB_ADAPTER_TYPE_CAST = { mysql: TYPE_CAST_MYSQL, mysql2: TYPE_CAST_MYSQL, + trilogy: TYPE_CAST_MYSQL, sqlite: TYPE_CAST_SQLITE, sqlite3: TYPE_CAST_SQLITE, oracle: TYPE_CAST_ORACLE, diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 840a7a99..b7824b69 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -47,7 +47,7 @@ def nulls_last_sql case @adapter when :pg, :postgresql, :postgres, :oracle, :postgis 'NULLS LAST' - when :mysql, :mysql2, :sqlite, :sqlite3 + when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3 'IS NULL' else raise "unsupported database adapter: #{@adapter}" diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index ec3409d2..772694a6 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -188,6 +188,11 @@ expect(column.send(:type_cast)).to eq('CHAR') end + it 'returns CHAR if :db_adapter is :trilogy' do + expect(datatable).to receive(:db_adapter) { :trilogy } + expect(column.send(:type_cast)).to eq('CHAR') + end + it 'returns CHAR if :db_adapter is :mysql' do expect(datatable).to receive(:db_adapter) { :mysql } expect(column.send(:type_cast)).to eq('CHAR') diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 1dd108a3..6ee96bb7 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -202,6 +202,16 @@ ) end end + + context 'when db_adapter is trilogy' do + it 'can call #to_sql on returned object' do + result = datatable.build_conditions_for_selected_columns + expect(result).to respond_to(:to_sql) + expect(result.to_sql).to eq( + "CAST(`users`.`username` AS CHAR) LIKE '%doe%' AND CAST(`users`.`email` AS CHAR) LIKE '%example%'" + ) + end + end end end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 949cea8e..a879c294 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -14,6 +14,11 @@ test: port: 3306 username: 'root' password: 'root' +<% elsif adapter == 'trilogy' %> + host: '127.0.0.1' + port: 3306 + username: 'root' + password: 'root' <% elsif adapter == 'oracle_enhanced' %> host: '127.0.0.1/xe' username: <%= ENV.fetch('USER') %> diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0420151..9ecc3efc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -73,7 +73,7 @@ def self.oracle? end def self.mysql? - ENV['DB_ADAPTER'] == 'mysql2' + ENV['DB_ADAPTER'] == 'mysql2' || ENV['DB_ADAPTER'] == 'trilogy' end def self.postgresql? diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index 0d85bb2c..406b0380 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -72,7 +72,7 @@ def nulls_last_sql(datatable) case datatable.db_adapter when :pg, :postgresql, :postgres, :oracle, :postgis 'NULLS LAST' - when :mysql, :mysql2, :sqlite, :sqlite3 + when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3 'IS NULL' else raise 'unsupported database adapter' From 1739989ed780023d4abd95413184cae7caae2149 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 10:30:25 +0000 Subject: [PATCH 221/290] Install trilogy adapter for rails <= 7.0 --- .github/workflows/ci.yml | 3 ++- appraisal.yml | 9 +++++++++ gemfiles/rails_6.0.6.gemfile | 4 ++++ gemfiles/rails_6.1.7.gemfile | 4 ++++ gemfiles/rails_7.0.8.gemfile | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b04e7e6f..9fa05f93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,7 @@ jobs: - sqlite3 - postgresql - mysql2 + - trilogy - oracle_enhanced steps: @@ -85,7 +86,7 @@ jobs: # See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql run: | - if [ "${DB_ADAPTER}" = "mysql2" ]; then + if [ "${DB_ADAPTER}" = "mysql2" ] || [ "${DB_ADAPTER}" = "trilogy" ]; then sudo systemctl start mysql.service mysql -u root -proot -e 'create database ajax_datatables_rails;' fi diff --git a/appraisal.yml b/appraisal.yml index e5de3f2e..3e31e0b6 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -6,6 +6,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' activerecord-oracle_enhanced-adapter: version: ~> 6.0.0 install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' @@ -23,6 +26,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' activerecord-oracle_enhanced-adapter: version: ~> 6.1.0 install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' @@ -40,6 +46,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' activerecord-oracle_enhanced-adapter: version: ~> 7.0.0 install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' diff --git a/gemfiles/rails_6.0.6.gemfile b/gemfiles/rails_6.0.6.gemfile index 71493716..4fd11c27 100644 --- a/gemfiles/rails_6.0.6.gemfile +++ b/gemfiles/rails_6.0.6.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" gem "ruby-oci8" diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile index 39ab3aad..339cbe40 100644 --- a/gemfiles/rails_6.1.7.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0" gem "ruby-oci8" diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index 8f02aebe..2fa3b03e 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" gem "ruby-oci8" From e27ba3f82d755e6b4132c0911a61da38a54bd756 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 23:46:02 +0530 Subject: [PATCH 222/290] Added trilogy gem for Rails 7.1 --- appraisal.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appraisal.yml b/appraisal.yml index 3e31e0b6..fbc476ab 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -66,6 +66,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' # activerecord-oracle_enhanced-adapter: # version: ~> 7.0.0 # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' From 78a6760fa75b800e2342acbc9cad15ffe844b6e5 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 23:52:41 +0530 Subject: [PATCH 223/290] Add dependency in 7.1 gemfile --- gemfiles/rails_7.1.0.gemfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index 4f58f57f..3a5bd4a5 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end From e3679699503166aab9aebbea9950cdb2072db306 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 17:23:27 +0200 Subject: [PATCH 224/290] Use upstream version of Combustion which is compatible with Trilogy See: https://github.com/pat/combustion/commit/c2b32b2bd3353c28894b61a1a69ff3de1c385085 --- Gemfile | 1 + gemfiles/rails_6.0.6.gemfile | 1 + gemfiles/rails_6.1.7.gemfile | 1 + gemfiles/rails_7.0.8.gemfile | 1 + gemfiles/rails_7.1.0.gemfile | 1 + 5 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index 063266df..e1453533 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,4 @@ source 'https://rubygems.org' gemspec gem 'appraisal', git: 'https://github.com/n-rodriguez/appraisal.git', branch: 'wip/combustion' +gem 'combustion', git: 'https://github.com/pat/combustion.git' diff --git a/gemfiles/rails_6.0.6.gemfile b/gemfiles/rails_6.0.6.gemfile index 4fd11c27..2407d4c3 100644 --- a/gemfiles/rails_6.0.6.gemfile +++ b/gemfiles/rails_6.0.6.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "combustion", git: "https://github.com/pat/combustion.git" gem "rails", "6.0.6" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile index 339cbe40..fe161f09 100644 --- a/gemfiles/rails_6.1.7.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "combustion", git: "https://github.com/pat/combustion.git" gem "rails", "6.1.7" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index 2fa3b03e..c90f9844 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "combustion", git: "https://github.com/pat/combustion.git" gem "rails", "7.0.8" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index 3a5bd4a5..68e4e347 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "combustion", git: "https://github.com/pat/combustion.git" gem "rails", "7.1.0" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do From a3481189739ca5dda52aa574bad8298113209348 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 17:40:11 +0200 Subject: [PATCH 225/290] Don't install latest bundler version in Ruby 2.7 --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fa05f93..4b786330 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,11 +107,14 @@ jobs: - name: Bundle env: + RUBY_VERSION: ${{ matrix.ruby }} RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile run: | - gem install bundler + if [[ "${RUBY_VERSION}" != "2.7" ]]; then + gem install bundler + fi bundle config path vendor/bundle bundle install --jobs 4 --retry 3 From fa18e6dcca1e674413ceb4c9dda59a038fa798aa Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 17:48:32 +0200 Subject: [PATCH 226/290] Disable tests with Trilogy adapter for now due to unknown error ArgumentError: unknown keyword: :uses_transaction --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b786330..7d5250fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,8 +66,8 @@ jobs: - sqlite3 - postgresql - mysql2 - - trilogy - oracle_enhanced + # - trilogy steps: - name: Checkout From b0ad3beefe979f3cc8583e3a74fc46b59654f57e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 17:53:10 +0200 Subject: [PATCH 227/290] Fix GithubActions warnings --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d5250fd..17763eab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -98,7 +98,7 @@ jobs: fi - name: Setup Ruby cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: vendor/bundle key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}-${{ hashFiles('**/Gemfile.lock') }} @@ -119,7 +119,7 @@ jobs: bundle install --jobs 4 --retry 3 - name: RSpec & publish code coverage - uses: paambaati/codeclimate-action@v3.2.0 + uses: paambaati/codeclimate-action@v5.0.0 env: RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} From d1c7f4670b60ced36634a0832ba3ab5305760042 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 17:57:31 +0200 Subject: [PATCH 228/290] Exclude some broken jobs with Oracle for now --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17763eab..ac3aa3a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,9 @@ jobs: - mysql2 - oracle_enhanced # - trilogy + exclude: + - rails: rails_7.1.0 + adapter: oracle_enhanced steps: - name: Checkout From c1091336e9b992b9beaaa58132074be1701db74c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:00:52 +0200 Subject: [PATCH 229/290] Fix tests with Ruby head --- appraisal.yml | 51 ++++++++++++++++++++++++++++++++++++ gemfiles/rails_6.0.6.gemfile | 7 +++++ gemfiles/rails_6.1.7.gemfile | 7 +++++ gemfiles/rails_7.0.8.gemfile | 7 +++++ gemfiles/rails_7.1.0.gemfile | 7 +++++ 5 files changed, 79 insertions(+) diff --git a/appraisal.yml b/appraisal.yml index fbc476ab..d0cdb888 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -18,6 +18,19 @@ activerecord-postgis-adapter: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' + base64: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + bigdecimal: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + mutex_m: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + drb: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + 6.1.7: sqlite3: @@ -38,6 +51,19 @@ activerecord-postgis-adapter: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' + base64: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + bigdecimal: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + mutex_m: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + drb: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + 7.0.8: sqlite3: @@ -58,6 +84,19 @@ activerecord-postgis-adapter: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' + base64: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + bigdecimal: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + mutex_m: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + drb: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + 7.1.0: sqlite3: @@ -78,3 +117,15 @@ activerecord-postgis-adapter: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' + base64: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + bigdecimal: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + mutex_m: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + drb: + version: '' + install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' diff --git a/gemfiles/rails_6.0.6.gemfile b/gemfiles/rails_6.0.6.gemfile index 2407d4c3..b7162e17 100644 --- a/gemfiles/rails_6.0.6.gemfile +++ b/gemfiles/rails_6.0.6.gemfile @@ -27,4 +27,11 @@ install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "mutex_m" + gem "drb" +end + gemspec path: "../" diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile index fe161f09..5d03cbfe 100644 --- a/gemfiles/rails_6.1.7.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -27,4 +27,11 @@ install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "mutex_m" + gem "drb" +end + gemspec path: "../" diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index c90f9844..95f76e65 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -27,4 +27,11 @@ install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "mutex_m" + gem "drb" +end + gemspec path: "../" diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index 68e4e347..d1af3c98 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -22,4 +22,11 @@ install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "mutex_m" + gem "drb" +end + gemspec path: "../" From 0b496a3e11a5629ffbc3c8d2d14fc67b876111e2 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:22:18 +0200 Subject: [PATCH 230/290] Improve bash snippets --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac3aa3a3..31b78c88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,12 +89,12 @@ jobs: # See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql run: | - if [ "${DB_ADAPTER}" = "mysql2" ] || [ "${DB_ADAPTER}" = "trilogy" ]; then + if [[ "${DB_ADAPTER}" == "mysql2" ]] || [[ "${DB_ADAPTER}" == "trilogy" ]]; then sudo systemctl start mysql.service mysql -u root -proot -e 'create database ajax_datatables_rails;' fi - if [ "${DB_ADAPTER}" = "oracle_enhanced" ]; then + if [[ "${DB_ADAPTER}" == "oracle_enhanced" ]]; then ./spec/install_oracle.sh # Fix error : libnnz11.so: cannot open shared object file: No such file or directory sudo ln -s ${ORACLE_HOME}/lib/libnnz11.so /usr/lib/libnnz11.so From e9dbcf4869084d9445539fc1b86adc777c68ee18 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:27:26 +0200 Subject: [PATCH 231/290] Test with Ruby 3.3 --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31b78c88..8d37f563 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,7 @@ jobs: fail-fast: false matrix: ruby: + - '3.3' - '3.2' - '3.1' - '3.0' From a84353e0bd051fb033ddb6f656860d8ed6e2f1e1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:36:11 +0200 Subject: [PATCH 232/290] DRY config/database.yml --- spec/dummy/config/database.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index a879c294..7c02f2a1 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -9,12 +9,7 @@ test: port: 5432 username: 'postgres' password: 'postgres' -<% elsif adapter == 'mysql2' %> - host: '127.0.0.1' - port: 3306 - username: 'root' - password: 'root' -<% elsif adapter == 'trilogy' %> +<% elsif adapter == 'mysql2' || adapter == 'trilogy' %> host: '127.0.0.1' port: 3306 username: 'root' From e03f5b9637f8749895c4d754ebec5bd3016e85b8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:39:32 +0200 Subject: [PATCH 233/290] Use Postgres 16 in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d37f563..816d8e5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: services: postgres: - image: 'postgres:13' + image: 'postgres:16' ports: ['5432:5432'] env: POSTGRES_PASSWORD: postgres From 23a3bc66c7aef3c8c423fc6aea6765aad530d905 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:46:10 +0200 Subject: [PATCH 234/290] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf677fbb..3ee11294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # CHANGELOG +## 1.5.0 (2024-04-xx) + +* Drop support of Rails 5.2 +* Add support for grouped results (merge: [#419](https://github.com/jbox-web/ajax-datatables-rails/pull/419)) +* Fix server-side out of order ajax responses (merge: [#418](https://github.com/jbox-web/ajax-datatables-rails/pull/418)) +* Add support for postgis adapter (merge: [#417](https://github.com/jbox-web/ajax-datatables-rails/pull/417)) +* Add support for trilogy adapter (merge: [#423](https://github.com/jbox-web/ajax-datatables-rails/pull/423)) +* Add support for Rails 7.1 +* Add support for Ruby 3.3 + +This is the last version to support Rails 6.0.x and Ruby 2.7.x. + ## 1.4.0 (2022-12-18) * Improve tests From eb9ccef4765e670d8ca79716f55222b0ebc91a6e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 18:53:56 +0200 Subject: [PATCH 235/290] Run CI with postgis adapter --- .github/workflows/ci.yml | 5 +++++ spec/dummy/config/database.yml | 2 +- spec/spec_helper.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 816d8e5f..e98bb51e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,11 +68,16 @@ jobs: - postgresql - mysql2 - oracle_enhanced + - postgis # - trilogy exclude: - rails: rails_7.1.0 adapter: oracle_enhanced + - rails: rails_7.1.0 + adapter: postgis + ruby: 2.7' + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 7c02f2a1..7f6a6759 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -4,7 +4,7 @@ test: database: ajax_datatables_rails encoding: utf8 -<% if adapter == 'postgresql' %> +<% if adapter == 'postgresql' || adapter == 'postgis' %> host: '127.0.0.1' port: 5432 username: 'postgres' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9ecc3efc..cd6970d5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -77,7 +77,7 @@ def self.mysql? end def self.postgresql? - ENV['DB_ADAPTER'] == 'postgresql' + ENV['DB_ADAPTER'] == 'postgresql' || ENV['DB_ADAPTER'] == 'postgis' end end From 608a6b366afc9d7743a5d3afc62d4875369fec0f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 19:15:07 +0200 Subject: [PATCH 236/290] Bump to version 1.5.0 --- CHANGELOG.md | 2 +- lib/ajax-datatables-rails/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee11294..f915a5ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 1.5.0 (2024-04-xx) +## 1.5.0 (2024-04-08) * Drop support of Rails 5.2 * Add support for grouped results (merge: [#419](https://github.com/jbox-web/ajax-datatables-rails/pull/419)) diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 3e926b16..3e9a1320 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -8,7 +8,7 @@ def self.gem_version module VERSION MAJOR = 1 - MINOR = 4 + MINOR = 5 TINY = 0 PRE = nil From d104c2ce07c21d8e23834abfa41f9f27642762d2 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 19:22:17 +0200 Subject: [PATCH 237/290] Update README --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6577bd97..a3fc869f 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,10 @@ It's tested against : -* Rails 6.0.6 / 6.1.7 / 7.0.4 -* Ruby 2.7 / 3.0 / 3.1 -* SQLite3 -* Postgresql 13 -* MySQL 8 -* Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) +* Rails: 6.0.6 / 6.1.7 / 7.0.4 / 7.1.0 +* Ruby: 2.7 / 3.0 / 3.1 / 3.2 / 3.3 +* Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) +* Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle ## Description From 51ce060c5becac23f974203cc92653a1e4250d2b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 19:24:04 +0200 Subject: [PATCH 238/290] Drop support for Ruby 2.7 --- .github/workflows/ci.yml | 9 +-------- .rubocop.yml | 2 +- README.md | 2 +- ajax-datatables-rails.gemspec | 2 +- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e98bb51e..af7784bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,6 @@ jobs: - '3.2' - '3.1' - '3.0' - - '2.7' - 'head' rails: - rails_7.1.0 @@ -74,10 +73,6 @@ jobs: - rails: rails_7.1.0 adapter: oracle_enhanced - - rails: rails_7.1.0 - adapter: postgis - ruby: 2.7' - steps: - name: Checkout uses: actions/checkout@v4 @@ -121,9 +116,7 @@ jobs: DB_ADAPTER: ${{ matrix.adapter }} BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile run: | - if [[ "${RUBY_VERSION}" != "2.7" ]]; then - gem install bundler - fi + gem install bundler bundle config path vendor/bundle bundle install --jobs 4 --retry 3 diff --git a/.rubocop.yml b/.rubocop.yml index ba60a761..308bd07f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ AllCops: NewCops: enable SuggestExtensions: false - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.0 Exclude: - bin/* - lib/generators/**/*.rb diff --git a/README.md b/README.md index a3fc869f..bc22ecaf 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It's tested against : * Rails: 6.0.6 / 6.1.7 / 7.0.4 / 7.1.0 -* Ruby: 2.7 / 3.0 / 3.1 / 3.2 / 3.3 +* Ruby: 3.0 / 3.1 / 3.2 / 3.3 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 09facdcf..b1450e05 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues', } - s.required_ruby_version = '>= 2.7.0' + s.required_ruby_version = '>= 3.0.0' s.files = `git ls-files`.split("\n") From 470f1368e22e9711168af8d46836837e63a1c41e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 19:30:46 +0200 Subject: [PATCH 239/290] Drop support for Rails 6.0.x --- .github/workflows/ci.yml | 1 - README.md | 2 +- ajax-datatables-rails.gemspec | 2 +- appraisal.yml | 33 ------------------------------- gemfiles/rails_6.0.6.gemfile | 37 ----------------------------------- 5 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 gemfiles/rails_6.0.6.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af7784bd..9b6488ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,6 @@ jobs: - rails_7.1.0 - rails_7.0.8 - rails_6.1.7 - - rails_6.0.6 adapter: - sqlite3 - postgresql diff --git a/README.md b/README.md index bc22ecaf..5a81fd53 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails: 6.0.6 / 6.1.7 / 7.0.4 / 7.1.0 +* Rails: 6.1.7 / 7.0.4 / 7.1.0 * Ruby: 3.0 / 3.1 / 3.2 / 3.3 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index b1450e05..dcdb9a65 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_runtime_dependency 'rails', '>= 6.0' + s.add_runtime_dependency 'rails', '>= 6.1' s.add_runtime_dependency 'zeitwerk' s.add_development_dependency 'activerecord-oracle_enhanced-adapter' diff --git a/appraisal.yml b/appraisal.yml index d0cdb888..ebda6011 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -1,37 +1,4 @@ --- -6.0.6: - sqlite3: - version: ~> 1.4.0 - install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' - mysql2: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' - activerecord-trilogy-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' - activerecord-oracle_enhanced-adapter: - version: ~> 6.0.0 - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - ruby-oci8: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - activerecord-postgis-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' - base64: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - bigdecimal: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - mutex_m: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - drb: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - - 6.1.7: sqlite3: version: ~> 1.4.0 diff --git a/gemfiles/rails_6.0.6.gemfile b/gemfiles/rails_6.0.6.gemfile deleted file mode 100644 index b7162e17..00000000 --- a/gemfiles/rails_6.0.6.gemfile +++ /dev/null @@ -1,37 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "combustion", git: "https://github.com/pat/combustion.git" -gem "rails", "6.0.6" - -install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.4.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do - gem "mysql2" -end - -install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do - gem "activerecord-trilogy-adapter" -end - -install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" - gem "ruby-oci8" -end - -install_if -> { ENV["DB_ADAPTER"] == "postgis" } do - gem "activerecord-postgis-adapter" -end - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "mutex_m" - gem "drb" -end - -gemspec path: "../" From 2a44b9867ec79d94ad10144ea89a1dbf2d223e2e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 19:43:39 +0200 Subject: [PATCH 240/290] Remove dead code --- lib/ajax-datatables-rails/base.rb | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 208f1204..3d8c421a 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -4,22 +4,8 @@ module AjaxDatatablesRails class Base class << self - def rails_52? - Rails.gem_version >= Gem::Version.new('5.2') && Rails.gem_version <= Gem::Version.new('6.0') - end - - def rails_60? - Rails.gem_version >= Gem::Version.new('6.0') && Rails.gem_version <= Gem::Version.new('6.1') - end - def default_db_adapter - if rails_52? - ::ActiveRecord::Base.configurations.dig(Rails.env, 'adapter').downcase.to_sym - elsif rails_60? - ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.config['adapter'].downcase.to_sym - else - ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.adapter.downcase.to_sym - end + ::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first.adapter.downcase.to_sym end end From cdf2e6d00e02c5e837f49fc30d6d1f7c8f1a1397 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:12:36 +0200 Subject: [PATCH 241/290] Improve objects shape --- lib/ajax-datatables-rails/base.rb | 6 ++++++ lib/ajax-datatables-rails/datatable/column.rb | 10 ++++++++++ lib/ajax-datatables-rails/datatable/datatable.rb | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 3d8c421a..27c8529d 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -20,6 +20,12 @@ def initialize(params, options = {}) @params = params @options = options @datatable = Datatable::Datatable.new(self) + + @connected_columns = nil + @searchable_columns = nil + @search_columns = nil + @records = nil + @build_conditions = nil end # User defined methods diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 747e546c..24edc84a 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -16,6 +16,16 @@ def initialize(datatable, index, options) @index = index @options = options @view_column = datatable.view_columns[column_name] + + @model = nil + @field = nil + @type_cast = nil + @casted_column = nil + @search = nil + @delimiter = nil + @range_start = nil + @range_end = nil + validate_settings! end diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index ceaf63c2..0d4e4d6f 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -8,6 +8,10 @@ class Datatable def initialize(datatable) @datatable = datatable @options = datatable.params + + @orders = nil + @search = nil + @columns = nil end # ----------------- ORDER METHODS -------------------- From 7faacef64e0557499014f9cdd5b29dd6eaf2ef09 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:21:01 +0200 Subject: [PATCH 242/290] Replace case/when by a hash lookup --- .../datatable/simple_order.rb | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index b7824b69..b817a586 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -41,17 +41,29 @@ def sort_nulls_last? column.nulls_last? || @nulls_last == true end + PG_NULL_STYLE = 'NULLS LAST' + MYSQL_NULL_STYLE = 'IS NULL' + private_constant :PG_NULL_STYLE + private_constant :MYSQL_NULL_STYLE + + NULL_STYLE_MAP = { + pg: PG_NULL_STYLE, + postgresql: PG_NULL_STYLE, + postgres: PG_NULL_STYLE, + postgis: PG_NULL_STYLE, + oracle: PG_NULL_STYLE, + mysql: MYSQL_NULL_STYLE, + mysql2: MYSQL_NULL_STYLE, + trilogy: MYSQL_NULL_STYLE, + sqlite: MYSQL_NULL_STYLE, + sqlite3: MYSQL_NULL_STYLE, + }.freeze + private_constant :NULL_STYLE_MAP + def nulls_last_sql return unless sort_nulls_last? - case @adapter - when :pg, :postgresql, :postgres, :oracle, :postgis - 'NULLS LAST' - when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3 - 'IS NULL' - else - raise "unsupported database adapter: #{@adapter}" - end + NULL_STYLE_MAP[@adapter] || raise("unsupported database adapter: #{@adapter}") end end From fab2908f5e12edde7dd2d8f1fb4207df11778f46 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:21:46 +0200 Subject: [PATCH 243/290] Improve objects shape --- lib/ajax-datatables-rails/datatable/column.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 24edc84a..4b23d4ad 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -8,14 +8,15 @@ class Column include Order include DateFilter - attr_reader :datatable, :index, :options + attr_reader :datatable, :index, :options, :column_name attr_writer :search def initialize(datatable, index, options) @datatable = datatable @index = index @options = options - @view_column = datatable.view_columns[column_name] + @column_name = options[:data]&.to_sym + @view_column = datatable.view_columns[@column_name] @model = nil @field = nil @@ -29,10 +30,6 @@ def initialize(datatable, index, options) validate_settings! end - def column_name - @column_name ||= options[:data]&.to_sym - end - def data options[:data].presence || options[:name] end From dd899e25abc58c82150f0a2a0cc399304045c2ba Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:25:11 +0200 Subject: [PATCH 244/290] Fix Rubocop offenses --- lib/ajax-datatables-rails/orm/active_record.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index fae27f3a..b57ac9f8 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -35,15 +35,14 @@ def build_conditions # rubocop:disable Metrics/AbcSize def build_conditions_for_datatable - columns = searchable_columns.reject(&:searched?) - criteria = search_for.inject([]) do |crit, atom| + columns = searchable_columns.reject(&:searched?) + search_for.inject([]) do |crit, atom| search = Datatable::SimpleSearch.new(value: atom, regex: datatable.search.regexp?) crit << columns.map do |simple_column| simple_column.search = search simple_column.search_query end.compact.reduce(:or) end.compact.reduce(:and) - criteria end # rubocop:enable Metrics/AbcSize From 92fa3441018e7bccde39994c19c803a4ecaa4994 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:25:46 +0200 Subject: [PATCH 245/290] Remove useless local variable --- lib/ajax-datatables-rails/orm/active_record.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index b57ac9f8..0ae8248b 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -37,9 +37,8 @@ def build_conditions def build_conditions_for_datatable columns = searchable_columns.reject(&:searched?) search_for.inject([]) do |crit, atom| - search = Datatable::SimpleSearch.new(value: atom, regex: datatable.search.regexp?) crit << columns.map do |simple_column| - simple_column.search = search + simple_column.search = Datatable::SimpleSearch.new(value: atom, regex: datatable.search.regexp?) simple_column.search_query end.compact.reduce(:or) end.compact.reduce(:and) From 70e673cdee5315d648df29f1af933194c0c91b43 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:35:23 +0200 Subject: [PATCH 246/290] Add tests on exceptions messages --- lib/ajax-datatables-rails/base.rb | 6 +++--- spec/ajax-datatables-rails/base_spec.rb | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 27c8529d..e3f2b75c 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -150,7 +150,7 @@ def draw_id end def raw_records_error_text - <<-ERROR + <<~ERROR You should implement this method in your class and specify how records are going to be retrieved from the database. @@ -158,7 +158,7 @@ def raw_records_error_text end def data_error_text - <<-ERROR + <<~ERROR You should implement this method in your class and return an array of arrays, or an array of hashes, as defined in the jQuery.dataTables @@ -167,7 +167,7 @@ def data_error_text end def view_columns_error_text - <<-ERROR + <<~ERROR You should implement this method in your class and return an array of database columns based on the columns displayed in the HTML view. diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 17d3738b..1936ab79 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -20,7 +20,13 @@ context 'when method is not defined by the user' do it 'raises an error' do datatable = described_class.new(sample_params) - expect { datatable.view_columns }.to raise_error NotImplementedError + expect { datatable.view_columns }.to raise_error(NotImplementedError).with_message(<<~ERROR) + + You should implement this method in your class and return an array + of database columns based on the columns displayed in the HTML view. + These columns should be represented in the ModelName.column_name, + or aliased_join_table.column_name notation. + ERROR end end @@ -36,7 +42,11 @@ context 'when method is not defined by the user' do it 'raises an error' do datatable = described_class.new(sample_params) - expect { datatable.get_raw_records }.to raise_error NotImplementedError + expect { datatable.get_raw_records }.to raise_error(NotImplementedError).with_message(<<~ERROR) + + You should implement this method in your class and specify + how records are going to be retrieved from the database. + ERROR end end end @@ -45,7 +55,12 @@ context 'when method is not defined by the user' do it 'raises an error' do datatable = described_class.new(sample_params) - expect { datatable.data }.to raise_error NotImplementedError + expect { datatable.data }.to raise_error(NotImplementedError).with_message(<<~ERROR) + + You should implement this method in your class and return an array + of arrays, or an array of hashes, as defined in the jQuery.dataTables + plugin documentation. + ERROR end end From f342bab7429a4c945d37f0ded12830a29bb9ea54 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:36:03 +0200 Subject: [PATCH 247/290] Remove *_error_text methods --- lib/ajax-datatables-rails/base.rb | 48 ++++++++++++------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index e3f2b75c..da6624a9 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -30,15 +30,30 @@ def initialize(params, options = {}) # User defined methods def view_columns - raise(NotImplementedError, view_columns_error_text) + raise(NotImplementedError, <<~ERROR) + + You should implement this method in your class and return an array + of database columns based on the columns displayed in the HTML view. + These columns should be represented in the ModelName.column_name, + or aliased_join_table.column_name notation. + ERROR end def get_raw_records - raise(NotImplementedError, raw_records_error_text) + raise(NotImplementedError, <<~ERROR) + + You should implement this method in your class and specify + how records are going to be retrieved from the database. + ERROR end def data - raise(NotImplementedError, data_error_text) + raise(NotImplementedError, <<~ERROR) + + You should implement this method in your class and return an array + of arrays, or an array of hashes, as defined in the jQuery.dataTables + plugin documentation. + ERROR end # ORM defined methods @@ -149,32 +164,5 @@ def draw_id params[:draw].present? ? { draw: params[:draw].to_i } : {} end - def raw_records_error_text - <<~ERROR - - You should implement this method in your class and specify - how records are going to be retrieved from the database. - ERROR - end - - def data_error_text - <<~ERROR - - You should implement this method in your class and return an array - of arrays, or an array of hashes, as defined in the jQuery.dataTables - plugin documentation. - ERROR - end - - def view_columns_error_text - <<~ERROR - - You should implement this method in your class and return an array - of database columns based on the columns displayed in the HTML view. - These columns should be represented in the ModelName.column_name, - or aliased_join_table.column_name notation. - ERROR - end - end end From db76973aba267054780319dd6e11d7fecdc4fbfa Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:36:55 +0200 Subject: [PATCH 248/290] Fix Rubocop offenses --- .rubocop.yml | 3 +++ lib/ajax-datatables-rails/base.rb | 14 +++----------- lib/ajax-datatables-rails/datatable/column.rb | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 308bd07f..2dce9689 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,6 +8,9 @@ AllCops: - gemfiles/* - spec/**/* +Gemspec/DevelopmentDependencies: + Enabled: false + Style/Documentation: Enabled: false diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index da6624a9..be075f30 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -101,23 +101,15 @@ def column_data(column) # helper methods def connected_columns - @connected_columns ||= begin - view_columns.keys.map do |field_name| - datatable.column_by(:data, field_name.to_s) - end.compact - end + @connected_columns ||= view_columns.keys.map { |field_name| datatable.column_by(:data, field_name.to_s) }.compact end def searchable_columns - @searchable_columns ||= begin - connected_columns.select(&:searchable?) - end + @searchable_columns ||= connected_columns.select(&:searchable?) end def search_columns - @search_columns ||= begin - searchable_columns.select(&:searched?) - end + @search_columns ||= searchable_columns.select(&:searched?) end def sanitize_data(data) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 4b23d4ad..921c76c7 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -100,7 +100,7 @@ def casted_column end def validate_settings! - raise AjaxDatatablesRails::Error::InvalidSearchColumn, "Unknown column. Check that `data` field is filled on JS side with the column name" if column_name.empty? + raise AjaxDatatablesRails::Error::InvalidSearchColumn, 'Unknown column. Check that `data` field is filled on JS side with the column name' if column_name.empty? raise AjaxDatatablesRails::Error::InvalidSearchColumn, "Check that column '#{column_name}' exists in view_columns" unless valid_search_column?(column_name) raise AjaxDatatablesRails::Error::InvalidSearchCondition, cond unless valid_search_condition?(cond) end From cbf654ef7e5f12c3ffc31aee3e39d68c839ccd03 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 8 Apr 2024 23:43:19 +0200 Subject: [PATCH 249/290] Fix Rubocop MFA offense --- ajax-datatables-rails.gemspec | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index dcdb9a65..a0c861f0 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -13,10 +13,11 @@ Gem::Specification.new do |s| s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app" s.license = 'MIT' s.metadata = { - 'homepage_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', - 'changelog_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/blob/master/CHANGELOG.md', - 'source_code_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', - 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues', + 'homepage_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', + 'changelog_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/blob/master/CHANGELOG.md', + 'source_code_uri' => 'https://github.com/jbox-web/ajax-datatables-rails', + 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues', + 'rubygems_mfa_required' => 'true', } s.required_ruby_version = '>= 3.0.0' From ff85109c8a2f5f934d92fd2a9a91706736f7ca15 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 9 Apr 2024 00:39:18 +0200 Subject: [PATCH 250/290] Improve object shape --- lib/ajax-datatables-rails/base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index be075f30..fba400cb 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -21,6 +21,7 @@ def initialize(params, options = {}) @options = options @datatable = Datatable::Datatable.new(self) + @view_columns = nil @connected_columns = nil @searchable_columns = nil @search_columns = nil From 74da2c50b370ef0d40bd795cc51d854e718e3f01 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Tue, 19 Mar 2024 21:56:42 -0500 Subject: [PATCH 251/290] Adding searchable false test case --- CHANGELOG.md | 2 ++ .../datatable/column_spec.rb | 8 +++++ .../datatable/datatable_spec.rb | 4 +-- .../orm/active_record_filter_records_spec.rb | 35 ++++++++++++------- spec/support/datatables/complex_datatable.rb | 2 ++ spec/support/helpers/params.rb | 6 ++++ spec/support/models/user.rb | 8 +++++ 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f915a5ef..ca0e88a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # CHANGELOG +* Implementing `searchable: false` tests + ## 1.5.0 (2024-04-08) * Drop support of Rails 5.2 diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 772694a6..69738ab4 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -128,6 +128,14 @@ end end + describe 'unsearchable column' do + let(:column) { datatable.datatable.columns.find{ |c| c.data == 'email_hash' } } + + it 'is not searchable' do + expect(column.searchable?).to eql(false) + end + end + describe '#formatter' do let(:datatable) { DatatableWithFormater.new(sample_params) } let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } } diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index 6d266288..7e8f977a 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -40,8 +40,8 @@ end shared_examples 'columns methods' do - it 'has 7 columns' do - expect(datatable.columns.count).to eq(7) + it 'has 8 columns' do + expect(datatable.columns.count).to eq(8) end it 'child class' do diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 6ee96bb7..8f59020b 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -12,12 +12,23 @@ expect { datatable.filter_records }.to raise_error(ArgumentError) end - it 'performs a simple search first' do - datatable.params[:search] = { value: 'msmith' } - expect(datatable).to receive(:build_conditions_for_datatable) - datatable.filter_records(records) + context 'with simple search' do + before do + datatable.params[:search] = { value: 'msmith' } + end + + it 'performs a simple search first' do + expect(datatable).to receive(:build_conditions_for_datatable) + datatable.filter_records(records) + end + + it 'does not search unsearchable fields' do + criteria = datatable.filter_records(records) + expect(criteria.to_sql).not_to include('email_hash') + end end + it 'performs a composite search second' do datatable.params[:search] = { value: '' } expect(datatable).to receive(:build_conditions_for_selected_columns) @@ -246,7 +257,7 @@ context 'when range is empty' do it 'does not filter records' do - datatable.params[:columns]['6'][:search][:value] = '-' + datatable.params[:columns]['7'][:search][:value] = '-' expect(datatable.data.size).to eq 2 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -255,21 +266,21 @@ context 'when start date is filled' do it 'filters records created after this date' do - datatable.params[:columns]['6'][:search][:value] = '31/12/1999-' + datatable.params[:columns]['7'][:search][:value] = '31/12/1999-' expect(datatable.data.size).to eq 2 end end context 'when end date is filled' do it 'filters records created before this date' do - datatable.params[:columns]['6'][:search][:value] = '-31/12/1999' + datatable.params[:columns]['7'][:search][:value] = '-31/12/1999' expect(datatable.data.size).to eq 0 end end context 'when both date are filled' do it 'filters records created between the range' do - datatable.params[:columns]['6'][:search][:value] = '01/12/1999-15/01/2000' + datatable.params[:columns]['7'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 end end @@ -278,7 +289,7 @@ context 'when range is empty' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['6'][:search][:value] = '-' + datatable.params[:columns]['7'][:search][:value] = '-' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -288,7 +299,7 @@ context 'when start date is filled' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['6'][:search][:value] = '01/12/1999-' + datatable.params[:columns]['7'][:search][:value] = '01/12/1999-' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -298,7 +309,7 @@ context 'when end date is filled' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['6'][:search][:value] = '-15/01/2000' + datatable.params[:columns]['7'][:search][:value] = '-15/01/2000' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' @@ -308,7 +319,7 @@ context 'when both date are filled' do it 'filters records' do datatable.params[:columns]['0'][:search][:value] = 'doe' - datatable.params[:columns]['6'][:search][:value] = '01/12/1999-15/01/2000' + datatable.params[:columns]['7'][:search][:value] = '01/12/1999-15/01/2000' expect(datatable.data.size).to eq 1 item = datatable.data.first expect(item[:last_name]).to eq 'Doe' diff --git a/spec/support/datatables/complex_datatable.rb b/spec/support/datatables/complex_datatable.rb index 6969f74a..ece7ee49 100644 --- a/spec/support/datatables/complex_datatable.rb +++ b/spec/support/datatables/complex_datatable.rb @@ -9,6 +9,7 @@ def view_columns last_name: { source: 'User.last_name' }, full_name: { source: 'full_name' }, post_id: { source: 'User.post_id', orderable: false }, + email_hash: { source: 'email_hash', searchable: false }, created_at: { source: 'User.created_at' }, } end @@ -22,6 +23,7 @@ def data last_name: record.last_name, full_name: record.full_name, post_id: record.post_id, + email_hash: record.email_hash, created_at: record.created_at, } end diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index 406b0380..dff2e791 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -43,6 +43,12 @@ def sample_params } }, '6' => { + 'data' => 'email_hash', 'name' => '', 'searchable' => 'false', 'orderable' => 'true', + 'search' => { + 'value' => '', 'regex' => 'false' + } + }, + '7' => { 'data' => 'created_at', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => '', 'regex' => 'false' diff --git a/spec/support/models/user.rb b/spec/support/models/user.rb index 7ad18b20..887efd98 100644 --- a/spec/support/models/user.rb +++ b/spec/support/models/user.rb @@ -1,7 +1,15 @@ # frozen_string_literal: true +require 'digest' + class User < ActiveRecord::Base def full_name "#{first_name} #{last_name}" end + + def email_hash + return nil if email.nil? + + Digest::SHA256.hexdigest email + end end From aab8d990cde8f44e3a0cb9df315c8e8b484872cf Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 2 Aug 2024 00:58:58 +0200 Subject: [PATCH 252/290] Update sqlite3 development dependency --- ajax-datatables-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index a0c861f0..cebd0352 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -43,5 +43,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec-retry' s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov' - s.add_development_dependency 'sqlite3', '~> 1.4.0' + s.add_development_dependency 'sqlite3', '~> 1.5.0' end From ef74896adcf6b14e6e40df2e5e2a45f1e2369656 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 2 Aug 2024 01:26:12 +0200 Subject: [PATCH 253/290] Update GithubActions actions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b6488ba..380b4529 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,7 +120,7 @@ jobs: bundle install --jobs 4 --retry 3 - name: RSpec & publish code coverage - uses: paambaati/codeclimate-action@v5.0.0 + uses: paambaati/codeclimate-action@v8.0.0 env: RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} From 17514718790d95ab00eb35a79ceb6819e71dbe69 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 2 Aug 2024 02:31:21 +0200 Subject: [PATCH 254/290] Remove actions/cache@v4 from GithubActions --- .github/workflows/ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 380b4529..60ca205f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,14 +100,6 @@ jobs: sudo ln -s ${ORACLE_HOME}/lib/libnnz11.so /usr/lib/libnnz11.so fi - - name: Setup Ruby cache - uses: actions/cache@v4 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}- - - name: Bundle env: RUBY_VERSION: ${{ matrix.ruby }} From f808c158c04bd3d1cc457c488b1423827c82f6e9 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 5 Aug 2024 02:02:41 +0200 Subject: [PATCH 255/290] Improve dependencies settings --- Gemfile | 17 ++++++++++++++++- ajax-datatables-rails.gemspec | 22 ++-------------------- appraisal.yml | 6 +++--- gemfiles/rails_6.1.7.gemfile | 17 +++++++++++++++-- gemfiles/rails_7.0.8.gemfile | 17 +++++++++++++++-- gemfiles/rails_7.1.0.gemfile | 17 +++++++++++++++-- 6 files changed, 66 insertions(+), 30 deletions(-) diff --git a/Gemfile b/Gemfile index e1453533..11ed6645 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,19 @@ source 'https://rubygems.org' gemspec gem 'appraisal', git: 'https://github.com/n-rodriguez/appraisal.git', branch: 'wip/combustion' -gem 'combustion', git: 'https://github.com/pat/combustion.git' + +# gem 'activerecord-oracle_enhanced-adapter' +gem 'combustion' +gem 'database_cleaner' +gem 'factory_bot' +gem 'faker' +gem 'generator_spec' +gem 'guard-rspec' +gem 'pg' +gem 'pry' +gem 'puma' +gem 'rake' +gem 'rspec' +gem 'rspec-retry' +gem 'rubocop' +gem 'simplecov' diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index cebd0352..4d982731 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -24,24 +24,6 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_runtime_dependency 'rails', '>= 6.1' - s.add_runtime_dependency 'zeitwerk' - - s.add_development_dependency 'activerecord-oracle_enhanced-adapter' - s.add_development_dependency 'appraisal' - s.add_development_dependency 'combustion', '~> 1.3' - s.add_development_dependency 'database_cleaner' - s.add_development_dependency 'factory_bot' - s.add_development_dependency 'faker' - s.add_development_dependency 'generator_spec' - s.add_development_dependency 'guard-rspec' - s.add_development_dependency 'pg' - s.add_development_dependency 'pry' - s.add_development_dependency 'puma' - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec' - s.add_development_dependency 'rspec-retry' - s.add_development_dependency 'rubocop' - s.add_development_dependency 'simplecov' - s.add_development_dependency 'sqlite3', '~> 1.5.0' + s.add_dependency 'rails', '>= 6.1' + s.add_dependency 'zeitwerk' end diff --git a/appraisal.yml b/appraisal.yml index ebda6011..7622cce4 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -1,7 +1,7 @@ --- 6.1.7: sqlite3: - version: ~> 1.4.0 + version: ~> 1.5.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' mysql2: version: '' @@ -34,7 +34,7 @@ 7.0.8: sqlite3: - version: ~> 1.4.0 + version: ~> 1.5.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' mysql2: version: '' @@ -67,7 +67,7 @@ 7.1.0: sqlite3: - version: ~> 1.4.0 + version: ~> 1.5.0 install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' mysql2: version: '' diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile index 5d03cbfe..894773d7 100644 --- a/gemfiles/rails_6.1.7.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -3,11 +3,24 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "combustion", git: "https://github.com/pat/combustion.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pg" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "simplecov" gem "rails", "6.1.7" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.4.0" + gem "sqlite3", "~> 1.5.0" end install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index 95f76e65..bc42438b 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -3,11 +3,24 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "combustion", git: "https://github.com/pat/combustion.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pg" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "simplecov" gem "rails", "7.0.8" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.4.0" + gem "sqlite3", "~> 1.5.0" end install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index d1af3c98..fa72c32f 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -3,11 +3,24 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "combustion", git: "https://github.com/pat/combustion.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pg" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "simplecov" gem "rails", "7.1.0" install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.4.0" + gem "sqlite3", "~> 1.5.0" end install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do From d77e38210b39983c6ff95f7462bd1ee19b109299 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 5 Aug 2024 02:09:39 +0200 Subject: [PATCH 256/290] Remove useless file --- .rspec | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .rspec diff --git a/.rspec b/.rspec deleted file mode 100644 index 4e1e0d2f..00000000 --- a/.rspec +++ /dev/null @@ -1 +0,0 @@ ---color From 1a6ec89554a1820ff848144bae7587e845b8f7f1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 5 Aug 2024 02:10:04 +0200 Subject: [PATCH 257/290] Improve GithubActions settings --- .github/workflows/ci.yml | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60ca205f..ef59763e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,8 @@ jobs: rspec: runs-on: ubuntu-latest - env: + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.rails }}.gemfile ORACLE_COOKIE: sqldev ORACLE_FILE: oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip ORACLE_HOME: /u01/app/oracle/product/11.2.0/xe @@ -76,14 +77,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - - name: Set DB Adapter env: - RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} CUSTOM_ORACLE_FILE: ${{ secrets.CUSTOM_ORACLE_FILE }} @@ -100,23 +95,18 @@ jobs: sudo ln -s ${ORACLE_HOME}/lib/libnnz11.so /usr/lib/libnnz11.so fi - - name: Bundle + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true env: - RUBY_VERSION: ${{ matrix.ruby }} - RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} - BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile - run: | - gem install bundler - bundle config path vendor/bundle - bundle install --jobs 4 --retry 3 - name: RSpec & publish code coverage uses: paambaati/codeclimate-action@v8.0.0 env: - RAILS_VERSION: ${{ matrix.rails }} DB_ADAPTER: ${{ matrix.adapter }} - BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} with: coverageCommand: bin/rake From a0d7389d19571975a061f0191bbbf2661cb1b961 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 11 Aug 2024 05:28:37 +0200 Subject: [PATCH 258/290] Ignore MacOS files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5c8920df..bb537c9d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ spec/dummy/db/*.sqlite3 spec/dummy/db/*.sqlite3-journal spec/dummy/log/*.log spec/dummy/tmp/ + +# Ignore MacOS files +.DS_Store From a2d1efbd27fd55b2af7ab713a6b6993f6aff2335 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:04:55 +0200 Subject: [PATCH 259/290] Minor change --- Guardfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Guardfile b/Guardfile index 15175960..5a44087b 100644 --- a/Guardfile +++ b/Guardfile @@ -1,6 +1,6 @@ # frozen_string_literal: true -guard :rspec, cmd: 'bundle exec rspec' do +guard :rspec, cmd: 'bin/rspec' do require 'guard/rspec/dsl' dsl = Guard::RSpec::Dsl.new(self) From db0356ca49ec98ab730b44647307cf755306182a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:07:32 +0200 Subject: [PATCH 260/290] Drop support for Rails 6.1 --- .github/workflows/ci.yml | 1 - ajax-datatables-rails.gemspec | 2 +- appraisal.yml | 33 ----------------------- gemfiles/rails_6.1.7.gemfile | 50 ----------------------------------- 4 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 gemfiles/rails_6.1.7.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef59763e..8961a081 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,6 @@ jobs: rails: - rails_7.1.0 - rails_7.0.8 - - rails_6.1.7 adapter: - sqlite3 - postgresql diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 4d982731..1c2ddb16 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -24,6 +24,6 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") - s.add_dependency 'rails', '>= 6.1' + s.add_dependency 'rails', '>= 7.0' s.add_dependency 'zeitwerk' end diff --git a/appraisal.yml b/appraisal.yml index 7622cce4..0b1c73f6 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -1,37 +1,4 @@ --- -6.1.7: - sqlite3: - version: ~> 1.5.0 - install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' - mysql2: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' - activerecord-trilogy-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' - activerecord-oracle_enhanced-adapter: - version: ~> 6.1.0 - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - ruby-oci8: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - activerecord-postgis-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' - base64: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - bigdecimal: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - mutex_m: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - drb: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - - 7.0.8: sqlite3: version: ~> 1.5.0 diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile deleted file mode 100644 index 894773d7..00000000 --- a/gemfiles/rails_6.1.7.gemfile +++ /dev/null @@ -1,50 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "guard-rspec" -gem "pg" -gem "pry" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "rubocop" -gem "simplecov" -gem "rails", "6.1.7" - -install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.5.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do - gem "mysql2" -end - -install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do - gem "activerecord-trilogy-adapter" -end - -install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0" - gem "ruby-oci8" -end - -install_if -> { ENV["DB_ADAPTER"] == "postgis" } do - gem "activerecord-postgis-adapter" -end - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "mutex_m" - gem "drb" -end - -gemspec path: "../" From 761758b6590a3fd82b62bb09faf083e20d070764 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:12:46 +0200 Subject: [PATCH 261/290] Add some Rubocop extensions --- .rubocop.yml | 8 +++++++- Gemfile | 4 ++++ gemfiles/rails_7.0.8.gemfile | 4 ++++ gemfiles/rails_7.1.0.gemfile | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2dce9689..209a1638 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,12 @@ +--- +require: + - rubocop-factory_bot + - rubocop-performance + - rubocop-rake + - rubocop-rspec + AllCops: NewCops: enable - SuggestExtensions: false TargetRubyVersion: 3.0 Exclude: - bin/* diff --git a/Gemfile b/Gemfile index 11ed6645..f6dbad75 100644 --- a/Gemfile +++ b/Gemfile @@ -20,4 +20,8 @@ gem 'rake' gem 'rspec' gem 'rspec-retry' gem 'rubocop' +gem 'rubocop-factory_bot' +gem 'rubocop-performance' +gem 'rubocop-rake' +gem 'rubocop-rspec' gem 'simplecov' diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index bc42438b..f986146f 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -16,6 +16,10 @@ gem "rake" gem "rspec" gem "rspec-retry" gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" gem "simplecov" gem "rails", "7.0.8" diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index fa72c32f..441f5057 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -16,6 +16,10 @@ gem "rake" gem "rspec" gem "rspec-retry" gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" gem "simplecov" gem "rails", "7.1.0" From 5b6ffee499efc28be95c94b3b25fb022f99f9315 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:16:46 +0200 Subject: [PATCH 262/290] Fix Rubocop offenses --- Appraisals | 10 ++++------ Rakefile | 1 + lib/ajax-datatables-rails/base.rb | 2 +- lib/ajax-datatables-rails/orm/active_record.rb | 9 +++------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Appraisals b/Appraisals index 4d4315de..7536e568 100644 --- a/Appraisals +++ b/Appraisals @@ -2,7 +2,7 @@ require 'yaml' -rails_versions = YAML.safe_load(File.read('appraisal.yml')) +rails_versions = YAML.safe_load_file('appraisal.yml') rails_versions.each do |version, gems| appraise "rails_#{version}" do @@ -16,12 +16,10 @@ rails_versions.each do |version, gems| gem name, opts['version'] end end + elsif opts['version'].empty? + gem name else - if opts['version'].empty? - gem name - else - gem name, opts['version'] - end + gem name, opts['version'] end end end diff --git a/Rakefile b/Rakefile index 5ae06112..5de361c0 100644 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,7 @@ require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task default: :spec +desc 'Open a Ruby irb console with the gem loaded' task :console do require 'pry' require 'rails' diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index fba400cb..059e6986 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -102,7 +102,7 @@ def column_data(column) # helper methods def connected_columns - @connected_columns ||= view_columns.keys.map { |field_name| datatable.column_by(:data, field_name.to_s) }.compact + @connected_columns ||= view_columns.keys.filter_map { |field_name| datatable.column_by(:data, field_name.to_s) } end def searchable_columns diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index 0ae8248b..6ed48a92 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -33,20 +33,17 @@ def build_conditions end end - # rubocop:disable Metrics/AbcSize def build_conditions_for_datatable columns = searchable_columns.reject(&:searched?) search_for.inject([]) do |crit, atom| - crit << columns.map do |simple_column| + crit << columns.filter_map do |simple_column| simple_column.search = Datatable::SimpleSearch.new(value: atom, regex: datatable.search.regexp?) simple_column.search_query - end.compact.reduce(:or) + end.reduce(:or) end.compact.reduce(:and) end - # rubocop:enable Metrics/AbcSize - def build_conditions_for_selected_columns - search_columns.map(&:search_query).compact.reduce(:and) + search_columns.filter_map(&:search_query).reduce(:and) end def search_for From 2fd1569b8f5ae56132d444457b0324912e5a2fa6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:23:31 +0200 Subject: [PATCH 263/290] Cleanup Rubocop config, fix offenses --- .rubocop.yml | 54 +++++++++---------- lib/ajax-datatables-rails/base.rb | 4 +- lib/ajax-datatables-rails/datatable/column.rb | 4 +- .../datatable/column/search.rb | 2 +- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 209a1638..c576291b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,54 +14,50 @@ AllCops: - gemfiles/* - spec/**/* -Gemspec/DevelopmentDependencies: - Enabled: false +######### +# STYLE # +######### Style/Documentation: Enabled: false -Layout/HashAlignment: - Enabled: false +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma -Layout/EmptyLines: - Enabled: false +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma -Layout/EmptyLinesAroundClassBody: - Enabled: false +########## +# LAYOUT # +########## -Layout/EmptyLinesAroundBlockBody: - Enabled: false +Layout/LineLength: + Exclude: + - ajax-datatables-rails.gemspec -Layout/EmptyLinesAroundModuleBody: +Layout/EmptyLines: Enabled: false Layout/EmptyLineBetweenDefs: Enabled: false -Metrics/CyclomaticComplexity: - Max: 7 +Layout/EmptyLinesAroundClassBody: + Enabled: false -Metrics/LineLength: +Layout/EmptyLinesAroundBlockBody: Enabled: false -Metrics/BlockLength: - Max: 30 +Layout/EmptyLinesAroundModuleBody: + Enabled: false -Metrics/MethodLength: - Max: 15 +Layout/HashAlignment: + EnforcedColonStyle: table + EnforcedHashRocketStyle: table -Metrics/ClassLength: - Max: 130 - -Naming/AccessorMethodName: - Enabled: false +########## +# NAMING # +########## Naming/FileName: Exclude: - lib/ajax-datatables-rails.rb - -Style/TrailingCommaInArrayLiteral: - EnforcedStyleForMultiline: comma - -Style/TrailingCommaInHashLiteral: - EnforcedStyleForMultiline: comma diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 059e6986..4d52feee 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module AjaxDatatablesRails - class Base + class Base # rubocop:disable Metrics/ClassLength class << self def default_db_adapter @@ -40,7 +40,7 @@ def view_columns ERROR end - def get_raw_records + def get_raw_records # rubocop:disable Naming/AccessorMethodName raise(NotImplementedError, <<~ERROR) You should implement this method in your class and specify diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 921c76c7..2179a4da 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -11,7 +11,7 @@ class Column attr_reader :datatable, :index, :options, :column_name attr_writer :search - def initialize(datatable, index, options) + def initialize(datatable, index, options) # rubocop:disable Metrics/MethodLength @datatable = datatable @index = index @options = options @@ -99,11 +99,13 @@ def casted_column @casted_column ||= ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(type_cast)]) end + # rubocop:disable Layout/LineLength def validate_settings! raise AjaxDatatablesRails::Error::InvalidSearchColumn, 'Unknown column. Check that `data` field is filled on JS side with the column name' if column_name.empty? raise AjaxDatatablesRails::Error::InvalidSearchColumn, "Check that column '#{column_name}' exists in view_columns" unless valid_search_column?(column_name) raise AjaxDatatablesRails::Error::InvalidSearchCondition, cond unless valid_search_condition?(cond) end + # rubocop:enable Layout/LineLength def valid_search_column?(column_name) !datatable.view_columns[column_name].nil? diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 581165fb..735f8cc8 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -48,7 +48,7 @@ def use_regex? # The solution is to bypass regex_search and use non_regex_search with :in operator def regex_search if use_regex? - ::Arel::Nodes::Regexp.new((custom_field? ? field : table[field]), ::Arel::Nodes.build_quoted(formatted_value)) + ::Arel::Nodes::Regexp.new((custom_field? ? field : table[field]), ::Arel::Nodes.build_quoted(formatted_value)) # rubocop:disable Layout/LineLength else non_regex_search end From 07f6fd177fa46723d454d697f2b5ef70232f811c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:26:05 +0200 Subject: [PATCH 264/290] Run Rubocop in CI --- .github/workflows/ci.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8961a081..02de24eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,24 @@ on: - cron: '0 4 1 * *' jobs: + rubocop: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + + - name: Bundler + run: bundle install + + - name: Rubocop + run: bin/rubocop + rspec: runs-on: ubuntu-latest @@ -108,4 +126,4 @@ jobs: DB_ADAPTER: ${{ matrix.adapter }} CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} with: - coverageCommand: bin/rake + coverageCommand: bin/rspec From ff83656f24460b38feb6e4d065521d9b5ed3097b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:27:13 +0200 Subject: [PATCH 265/290] Minor change --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index c576291b..f31beda2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,9 +10,9 @@ AllCops: TargetRubyVersion: 3.0 Exclude: - bin/* - - lib/generators/**/*.rb - gemfiles/* - spec/**/* + - lib/generators/**/*.rb ######### # STYLE # From a8fab0ecf7cf67b21df4a4e16875e74c86caec4c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:27:36 +0200 Subject: [PATCH 266/290] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a81fd53..228d3180 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails: 6.1.7 / 7.0.4 / 7.1.0 +* Rails: 7.0.4 / 7.1.0 * Ruby: 3.0 / 3.1 / 3.2 / 3.3 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle From 571dd9e785a1d823d4d7acf6467167ec503f4382 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 17:33:57 +0200 Subject: [PATCH 267/290] Add support for Rails 7.2 --- .github/workflows/ci.yml | 5 +++++ README.md | 2 +- appraisal.yml | 21 ++++++++++++++++++ gemfiles/rails_7.2.0.gemfile | 42 ++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 gemfiles/rails_7.2.0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02de24eb..fb864ab1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,7 @@ jobs: - '3.0' - 'head' rails: + - rails_7.2.0 - rails_7.1.0 - rails_7.0.8 adapter: @@ -87,6 +88,10 @@ jobs: - postgis # - trilogy exclude: + - rails: rails_7.2.0 + adapter: oracle_enhanced + - rails: rails_7.2.0 + ruby: '3.0' - rails: rails_7.1.0 adapter: oracle_enhanced diff --git a/README.md b/README.md index 228d3180..0cef164d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails: 7.0.4 / 7.1.0 +* Rails: 7.0.4 / 7.1.0 / 7.2.0 * Ruby: 3.0 / 3.1 / 3.2 / 3.3 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle diff --git a/appraisal.yml b/appraisal.yml index 0b1c73f6..35e4f41b 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -63,3 +63,24 @@ drb: version: '' install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' + + +7.2.0: + sqlite3: + version: ~> 1.5.0 + install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' + mysql2: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' + # activerecord-oracle_enhanced-adapter: + # version: ~> 7.0.0 + # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' + # 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_7.2.0.gemfile b/gemfiles/rails_7.2.0.gemfile new file mode 100644 index 00000000..652e461c --- /dev/null +++ b/gemfiles/rails_7.2.0.gemfile @@ -0,0 +1,42 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pg" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" + +install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do + gem "sqlite3", "~> 1.5.0" +end + +install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do + gem "mysql2" +end + +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + +install_if -> { ENV["DB_ADAPTER"] == "postgis" } do + gem "activerecord-postgis-adapter" +end + +gemspec path: "../" From 7c8025f5cebdf720f66a048699aa7d576412b023 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 21:34:47 +0200 Subject: [PATCH 268/290] Cleanup Appraisals file --- .github/workflows/ci.yml | 17 ++- .rubocop.yml | 1 + Appraisals | 115 ++++++++++++++---- appraisal.yml | 86 ------------- gemfiles/rails_7.0.8.gemfile | 7 +- gemfiles/rails_7.1.0.gemfile | 13 +- gemfiles/rails_7.2.0.gemfile | 7 +- .../datatable/column/search.rb | 2 +- 8 files changed, 129 insertions(+), 119 deletions(-) delete mode 100644 appraisal.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb864ab1..ab63d87d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,10 +88,23 @@ jobs: - postgis # - trilogy exclude: - - rails: rails_7.2.0 - adapter: oracle_enhanced + # Rails 7.2 needs Ruby > 3.1 - rails: rails_7.2.0 ruby: '3.0' + + # Disabled for now because of build error: + # /opt/hostedtoolcache/Ruby/3.0.7/x64/lib/ruby/3.0.0/psych.rb:457:in + # `parse_stream': undefined method `parse' for #>, + # @external_encoding=0> (NoMethodError) + # from + # /home/runner/work/ajax-datatables-rails/ajax-datatables-rails/vendor/bundle/ruby/3.0.0/gems/ruby-oci8-2.2.14/ext/oci8/apiwrap.rb:64:in + # `create_apiwrap' + - rails: rails_7.2.0 + adapter: oracle_enhanced - rails: rails_7.1.0 adapter: oracle_enhanced diff --git a/.rubocop.yml b/.rubocop.yml index f31beda2..40b6bdd9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -32,6 +32,7 @@ Style/TrailingCommaInHashLiteral: ########## Layout/LineLength: + Max: 125 Exclude: - ajax-datatables-rails.gemspec diff --git a/Appraisals b/Appraisals index 7536e568..53eb9ac3 100644 --- a/Appraisals +++ b/Appraisals @@ -1,26 +1,97 @@ # frozen_string_literal: true -require 'yaml' - -rails_versions = YAML.safe_load_file('appraisal.yml') - -rails_versions.each do |version, gems| - appraise "rails_#{version}" do - gem 'rails', version - gems.each do |name, opts| - if opts['install_if'] - install_if opts['install_if'] do - if opts['version'].empty? - gem name - else - gem name, opts['version'] - end - end - elsif opts['version'].empty? - gem name - else - gem name, opts['version'] - end - end +appraise 'rails_7.0.8' do # rubocop:disable Metrics/BlockLength + gem 'rails', '7.0.8' + + install_if '-> { ENV["DB_ADAPTER"] == "sqlite3" }' do + gem 'sqlite3', '~> 1.5.0' + end + + install_if '-> { ENV["DB_ADAPTER"] == "mysql2" }' do + gem 'mysql2' + end + + install_if '-> { ENV["DB_ADAPTER"] == "trilogy" }' do + gem 'activerecord-trilogy-adapter' + end + + install_if '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' do + gem 'ruby-oci8' + gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' + end + + install_if '-> { ENV["DB_ADAPTER"] == "postgis" }' do + gem 'activerecord-postgis-adapter' + end + + # Fix: + # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 + # Add logger to your Gemfile or gemspec. + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do + gem 'base64' + gem 'bigdecimal' + gem 'benchmark' + gem 'drb' + gem 'logger' + gem 'mutex_m' + gem 'ostruct' + end +end + +appraise 'rails_7.1.0' do + gem 'rails', '7.1.0' + + install_if '-> { ENV["DB_ADAPTER"] == "sqlite3" }' do + gem 'sqlite3', '~> 1.5.0' + end + + install_if '-> { ENV["DB_ADAPTER"] == "mysql2" }' do + gem 'mysql2' + end + + install_if '-> { ENV["DB_ADAPTER"] == "trilogy" }' do + gem 'activerecord-trilogy-adapter' + end + + install_if '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' do + gem 'ruby-oci8' + gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + end + + install_if '-> { ENV["DB_ADAPTER"] == "postgis" }' do + gem 'activerecord-postgis-adapter' + end + + # Fix: + # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 + # Add logger to your Gemfile or gemspec. + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") }' do + gem 'logger' + gem 'ostruct' + end +end + +appraise 'rails_7.2.0' do + gem 'rails', '7.2.0' + + install_if '-> { ENV["DB_ADAPTER"] == "sqlite3" }' do + gem 'sqlite3', '~> 1.5.0' + end + + install_if '-> { ENV["DB_ADAPTER"] == "mysql2" }' do + gem 'mysql2' + end + + install_if '-> { ENV["DB_ADAPTER"] == "trilogy" }' do + gem 'activerecord-trilogy-adapter' + end + + install_if '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' do + gem 'ruby-oci8' + gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + end + + install_if '-> { ENV["DB_ADAPTER"] == "postgis" }' do + gem 'activerecord-postgis-adapter', git: 'https://github.com/rgeo/activerecord-postgis-adapter.git' end end diff --git a/appraisal.yml b/appraisal.yml deleted file mode 100644 index 35e4f41b..00000000 --- a/appraisal.yml +++ /dev/null @@ -1,86 +0,0 @@ ---- -7.0.8: - sqlite3: - version: ~> 1.5.0 - install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' - mysql2: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' - activerecord-trilogy-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' - activerecord-oracle_enhanced-adapter: - version: ~> 7.0.0 - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - ruby-oci8: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - activerecord-postgis-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' - base64: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - bigdecimal: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - mutex_m: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - drb: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - - -7.1.0: - sqlite3: - version: ~> 1.5.0 - install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' - mysql2: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' - activerecord-trilogy-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' - # activerecord-oracle_enhanced-adapter: - # version: ~> 7.0.0 - # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - # ruby-oci8: - # version: '' - # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - activerecord-postgis-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "postgis" }' - base64: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - bigdecimal: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - mutex_m: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - drb: - version: '' - install_if: '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' - - -7.2.0: - sqlite3: - version: ~> 1.5.0 - install_if: '-> { ENV["DB_ADAPTER"] == "sqlite3" }' - mysql2: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' - activerecord-trilogy-adapter: - version: '' - install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' - # activerecord-oracle_enhanced-adapter: - # version: ~> 7.0.0 - # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' - # 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_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index f986146f..1f491efa 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -36,8 +36,8 @@ install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do end install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" gem "ruby-oci8" + gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" end install_if -> { ENV["DB_ADAPTER"] == "postgis" } do @@ -47,8 +47,11 @@ end install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do gem "base64" gem "bigdecimal" - gem "mutex_m" + gem "benchmark" gem "drb" + gem "logger" + gem "mutex_m" + gem "ostruct" end gemspec path: "../" diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index 441f5057..97ecb805 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -35,15 +35,18 @@ install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do gem "activerecord-trilogy-adapter" end +install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do + gem "ruby-oci8" + gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" +end + install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "mutex_m" - gem "drb" +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") } do + gem "logger" + gem "ostruct" end gemspec path: "../" diff --git a/gemfiles/rails_7.2.0.gemfile b/gemfiles/rails_7.2.0.gemfile index 652e461c..ee0697dc 100644 --- a/gemfiles/rails_7.2.0.gemfile +++ b/gemfiles/rails_7.2.0.gemfile @@ -35,8 +35,13 @@ install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do gem "activerecord-trilogy-adapter" end +install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do + gem "ruby-oci8" + gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" +end + install_if -> { ENV["DB_ADAPTER"] == "postgis" } do - gem "activerecord-postgis-adapter" + gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" end gemspec path: "../" diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb index 735f8cc8..581165fb 100644 --- a/lib/ajax-datatables-rails/datatable/column/search.rb +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -48,7 +48,7 @@ def use_regex? # The solution is to bypass regex_search and use non_regex_search with :in operator def regex_search if use_regex? - ::Arel::Nodes::Regexp.new((custom_field? ? field : table[field]), ::Arel::Nodes.build_quoted(formatted_value)) # rubocop:disable Layout/LineLength + ::Arel::Nodes::Regexp.new((custom_field? ? field : table[field]), ::Arel::Nodes.build_quoted(formatted_value)) else non_regex_search end From a47cfef715f5726bc0090fbe6ada6c5227230f6c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 7 Sep 2024 00:54:33 +0200 Subject: [PATCH 269/290] Update Rubocop config, fix offenses --- .rubocop.yml | 26 +++++++- .../orm/active_record.rb | 1 + .../base_spec.rb | 26 ++++---- .../datatable/column_spec.rb | 59 +++++++++---------- .../datatable/datatable_spec.rb | 9 +-- .../datatable/simple_order_spec.rb | 4 +- .../datatable/simple_search_spec.rb | 2 +- .../orm/active_record_count_records_spec.rb | 9 ++- .../orm/active_record_filter_records_spec.rb | 50 ++++++++-------- .../active_record_paginate_records_spec.rb | 8 ++- .../orm/active_record_sort_records_spec.rb | 0 spec/spec_helper.rb | 2 +- spec/support/datatables/complex_datatable.rb | 4 +- .../datatables/datatable_cond_string.rb | 2 +- .../datatables/datatable_custom_column.rb | 2 +- .../datatables/grouped_datatable_array.rb | 2 +- spec/support/helpers/params.rb | 10 ++-- spec/support/models/user.rb | 4 +- 18 files changed, 125 insertions(+), 95 deletions(-) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/base_spec.rb (91%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/datatable/column_spec.rb (74%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/datatable/datatable_spec.rb (94%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/datatable/simple_order_spec.rb (90%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/datatable/simple_search_spec.rb (83%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/orm/active_record_count_records_spec.rb (85%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/orm/active_record_filter_records_spec.rb (93%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/orm/active_record_paginate_records_spec.rb (83%) rename spec/{ajax-datatables-rails => ajax_datatables_rails}/orm/active_record_sort_records_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 40b6bdd9..f97f2160 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,7 @@ AllCops: Exclude: - bin/* - gemfiles/* - - spec/**/* + - spec/dummy/**/* - lib/generators/**/*.rb ######### @@ -27,12 +27,15 @@ Style/TrailingCommaInArrayLiteral: Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: comma +Style/BlockDelimiters: + AllowedPatterns: ['expect'] + ########## # LAYOUT # ########## Layout/LineLength: - Max: 125 + Max: 150 Exclude: - ajax-datatables-rails.gemspec @@ -62,3 +65,22 @@ Layout/HashAlignment: Naming/FileName: Exclude: - lib/ajax-datatables-rails.rb + +######### +# RSPEC # +######### + +RSpec/MultipleExpectations: + Max: 7 + +RSpec/NestedGroups: + Max: 6 + +RSpec/ExampleLength: + Max: 9 + +RSpec/MultipleMemoizedHelpers: + Max: 6 + +RSpec/NotToNot: + EnforcedStyle: to_not diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index 6ed48a92..8da0895d 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -42,6 +42,7 @@ def build_conditions_for_datatable end.reduce(:or) end.compact.reduce(:and) end + def build_conditions_for_selected_columns search_columns.filter_map(&:search_query).reduce(:and) end diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax_datatables_rails/base_spec.rb similarity index 91% rename from spec/ajax-datatables-rails/base_spec.rb rename to spec/ajax_datatables_rails/base_spec.rb index 1936ab79..28915792 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax_datatables_rails/base_spec.rb @@ -30,7 +30,7 @@ end end - context 'child class implements view_columns' do + context 'when child class implements view_columns' do it 'expects a hash based defining columns' do datatable = ComplexDatatable.new(sample_params) expect(datatable.view_columns).to be_a(Hash) @@ -108,7 +108,7 @@ describe 'ORM API' do context 'when ORM is not implemented' do - let(:datatable) { AjaxDatatablesRails::Base.new(sample_params) } + let(:datatable) { described_class.new(sample_params) } describe '#fetch_records' do it 'raises an error if it does not include an ORM module' do @@ -139,16 +139,16 @@ describe 'it allows method override' do let(:datatable) do datatable = Class.new(ComplexDatatable) do - def filter_records(records) - raise NotImplementedError.new('FOO') + def filter_records(_records) + raise NotImplementedError, 'FOO' end - def sort_records(records) - raise NotImplementedError.new('FOO') + def sort_records(_records) + raise NotImplementedError, 'FOO' end - def paginate_records(records) - raise NotImplementedError.new('FOO') + def paginate_records(_records) + raise NotImplementedError, 'FOO' end end datatable.new(sample_params) @@ -156,12 +156,13 @@ def paginate_records(records) describe '#fetch_records' do it 'calls #get_raw_records' do - expect(datatable).to receive(:get_raw_records) { User.all } + allow(datatable).to receive(:get_raw_records) { User.all } datatable.fetch_records + expect(datatable).to have_received(:get_raw_records) end it 'returns a collection of records' do - expect(datatable).to receive(:get_raw_records) { User.all } + allow(datatable).to receive(:get_raw_records) { User.all } expect(datatable.fetch_records).to be_a(ActiveRecord::Relation) end end @@ -204,7 +205,7 @@ def paginate_records(records) context 'with additional_data' do it 'returns a hash' do create_list(:user, 5) - expect(datatable).to receive(:additional_data) { { foo: 'bar' } } + allow(datatable).to receive(:additional_data).and_return({ foo: 'bar' }) data = datatable.as_json expect(data[:recordsTotal]).to eq 5 expect(data[:recordsFiltered]).to eq 5 @@ -228,9 +229,10 @@ def paginate_records(records) end describe '#column_data' do - let(:datatable) { ComplexDatatable.new(sample_params) } before { datatable.params[:columns]['0'][:search][:value] = 'doe' } + let(:datatable) { ComplexDatatable.new(sample_params) } + it 'returns column data from params' do expect(datatable.column_data(:username)).to eq('doe') expect(datatable.column_data('username')).to eq('doe') diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax_datatables_rails/datatable/column_spec.rb similarity index 74% rename from spec/ajax-datatables-rails/datatable/column_spec.rb rename to spec/ajax_datatables_rails/datatable/column_spec.rb index 69738ab4..21dc66f0 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax_datatables_rails/datatable/column_spec.rb @@ -13,19 +13,19 @@ before { datatable.params[:columns]['0'][:search][:value] = 'searchvalue' } it 'is orderable' do - expect(column.orderable?).to eq(true) + expect(column.orderable?).to be(true) end it 'sorts nulls last' do - expect(column.nulls_last?).to eq(false) + expect(column.nulls_last?).to be(false) end it 'is searchable' do - expect(column.searchable?).to eq(true) + expect(column.searchable?).to be(true) end it 'is searched' do - expect(column.searched?).to eq(true) + expect(column.searched?).to be(true) end it 'has connected to id column' do @@ -53,7 +53,7 @@ context 'with other ORM' do it 'returns the corresponding model' do - expect(User).to receive(:respond_to?).with(:arel_table).and_return(false) + allow(User).to receive(:respond_to?).with(:arel_table).and_return(false) expect(column.table).to eq User end end @@ -87,7 +87,7 @@ end it 'does not regex' do - expect(column.search.regexp?).to eq false + expect(column.search.regexp?).to be false end end @@ -97,12 +97,6 @@ end end - describe '#source' do - it 'is :like by default' do - expect(column.source).to eq('User.username') - end - end - describe '#search_query' do it 'bulds search query' do expect(column.search_query.to_sql).to include('%searchvalue%') @@ -129,10 +123,10 @@ end describe 'unsearchable column' do - let(:column) { datatable.datatable.columns.find{ |c| c.data == 'email_hash' } } + let(:column) { datatable.datatable.columns.find { |c| c.data == 'email_hash' } } it 'is not searchable' do - expect(column.searchable?).to eql(false) + expect(column.searchable?).to be(false) end end @@ -150,11 +144,12 @@ let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } } it 'is a proc' do - config = column.instance_variable_get('@view_column') + config = column.instance_variable_get(:@view_column) filter = config[:cond] expect(filter).to be_a(Proc) - expect(filter).to receive(:call).with(column, column.formatted_value) + allow(filter).to receive(:call).with(column, column.formatted_value) column.filter + expect(filter).to have_received(:call).with(column, column.formatted_value) end end @@ -162,62 +157,62 @@ let(:column) { datatable.datatable.columns.first } it 'returns VARCHAR if :db_adapter is :pg' do - expect(datatable).to receive(:db_adapter) { :pg } + allow(datatable).to receive(:db_adapter).and_return(:pg) expect(column.send(:type_cast)).to eq('VARCHAR') end it 'returns VARCHAR if :db_adapter is :postgre' do - expect(datatable).to receive(:db_adapter) { :postgre } + allow(datatable).to receive(:db_adapter).and_return(:postgre) expect(column.send(:type_cast)).to eq('VARCHAR') end it 'returns VARCHAR if :db_adapter is :postgresql' do - expect(datatable).to receive(:db_adapter) { :postgresql } + allow(datatable).to receive(:db_adapter).and_return(:postgresql) 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 } + allow(datatable).to receive(:db_adapter).and_return(: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 } + allow(datatable).to receive(:db_adapter).and_return(:oracle) expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') end it 'returns VARCHAR2(4000) if :db_adapter is :oracleenhanced' do - expect(datatable).to receive(:db_adapter) { :oracleenhanced } + allow(datatable).to receive(:db_adapter).and_return(:oracleenhanced) expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') end it 'returns CHAR if :db_adapter is :mysql2' do - expect(datatable).to receive(:db_adapter) { :mysql2 } + allow(datatable).to receive(:db_adapter).and_return(:mysql2) expect(column.send(:type_cast)).to eq('CHAR') end it 'returns CHAR if :db_adapter is :trilogy' do - expect(datatable).to receive(:db_adapter) { :trilogy } + allow(datatable).to receive(:db_adapter).and_return(:trilogy) expect(column.send(:type_cast)).to eq('CHAR') end it 'returns CHAR if :db_adapter is :mysql' do - expect(datatable).to receive(:db_adapter) { :mysql } + allow(datatable).to receive(:db_adapter).and_return(:mysql) expect(column.send(:type_cast)).to eq('CHAR') end it 'returns TEXT if :db_adapter is :sqlite' do - expect(datatable).to receive(:db_adapter) { :sqlite } + allow(datatable).to receive(:db_adapter).and_return(:sqlite) expect(column.send(:type_cast)).to eq('TEXT') end it 'returns TEXT if :db_adapter is :sqlite3' do - expect(datatable).to receive(:db_adapter) { :sqlite3 } + allow(datatable).to receive(:db_adapter).and_return(:sqlite3) expect(column.send(:type_cast)).to eq('TEXT') end it 'returns VARCHAR(4000) if :db_adapter is :sqlserver' do - expect(datatable).to receive(:db_adapter) { :sqlserver } + allow(datatable).to receive(:db_adapter).and_return(:sqlserver) expect(column.send(:type_cast)).to eq('VARCHAR(4000)') end end @@ -225,16 +220,20 @@ describe 'when empty column' do before { datatable.params[:columns]['0'][:data] = '' } + let(:message) { 'Unknown column. Check that `data` field is filled on JS side with the column name' } + it 'raises error' do - expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message('Unknown column. Check that `data` field is filled on JS side with the column name') + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message(message) end end describe 'when unknown column' do before { datatable.params[:columns]['0'][:data] = 'foo' } + let(:message) { "Check that column 'foo' exists in view_columns" } + it 'raises error' do - expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Check that column 'foo' exists in view_columns") + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message(message) end end end diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax_datatables_rails/datatable/datatable_spec.rb similarity index 94% rename from spec/ajax-datatables-rails/datatable/datatable_spec.rb rename to spec/ajax_datatables_rails/datatable/datatable_spec.rb index 7e8f977a..fa12005d 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax_datatables_rails/datatable/datatable_spec.rb @@ -11,12 +11,12 @@ shared_examples 'order methods' do it 'is orderable' do - expect(datatable.orderable?).to eq(true) + expect(datatable.orderable?).to be(true) end it 'is not orderable' do datatable.options[:order] = nil - expect(datatable.orderable?).to eq(false) + expect(datatable.orderable?).to be(false) end it 'has 2 orderable columns' do @@ -57,6 +57,7 @@ describe 'with json params' do let(:order_option) { order_option_json } let(:datatable) { datatable_json } + it_behaves_like 'order methods' it_behaves_like 'columns methods' end @@ -64,12 +65,12 @@ describe 'search methods' do it 'is searchable' do datatable.options[:search][:value] = 'atom' - expect(datatable.searchable?).to eq(true) + expect(datatable.searchable?).to be(true) end it 'is not searchable' do datatable.options[:search][:value] = nil - expect(datatable.searchable?).to eq(false) + expect(datatable.searchable?).to be(false) end it 'child class' do diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax_datatables_rails/datatable/simple_order_spec.rb similarity index 90% rename from spec/ajax-datatables-rails/datatable/simple_order_spec.rb rename to spec/ajax_datatables_rails/datatable/simple_order_spec.rb index 71de756d..36d2260f 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax_datatables_rails/datatable/simple_order_spec.rb @@ -7,7 +7,7 @@ let(:parent) { ComplexDatatable.new(sample_params) } let(:datatable) { parent.datatable } let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'column' => '1', 'dir' => 'desc' }) } - let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) } + let(:simple_order) { described_class.new(datatable, options) } describe 'option methods' do it 'sql query' do @@ -32,7 +32,7 @@ describe 'using column option' do let(:parent) { DatatableOrderNullsLast.new(sample_params) } let(:sorted_datatable) { parent.datatable } - let(:nulls_last_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(sorted_datatable, options) } + let(:nulls_last_order) { described_class.new(sorted_datatable, options) } context 'with postgres database adapter' do before { parent.db_adapter = :pg } diff --git a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb b/spec/ajax_datatables_rails/datatable/simple_search_spec.rb similarity index 83% rename from spec/ajax-datatables-rails/datatable/simple_search_spec.rb rename to spec/ajax_datatables_rails/datatable/simple_search_spec.rb index fc814802..a13bed72 100644 --- a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +++ b/spec/ajax_datatables_rails/datatable/simple_search_spec.rb @@ -5,7 +5,7 @@ RSpec.describe AjaxDatatablesRails::Datatable::SimpleSearch do let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'value' => 'search value', 'regex' => 'true' }) } - let(:simple_search) { AjaxDatatablesRails::Datatable::SimpleSearch.new(options) } + let(:simple_search) { described_class.new(options) } describe 'option methods' do it 'regexp?' do diff --git a/spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb b/spec/ajax_datatables_rails/orm/active_record_count_records_spec.rb similarity index 85% rename from spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb rename to spec/ajax_datatables_rails/orm/active_record_count_records_spec.rb index 4c5c2be3..70c4de4c 100644 --- a/spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb +++ b/spec/ajax_datatables_rails/orm/active_record_count_records_spec.rb @@ -8,13 +8,13 @@ let(:records) { User.all } describe '#records_total_count' do - context 'ungrouped results' do + context 'when ungrouped results' do it 'returns the count' do expect(datatable.send(:records_total_count)).to eq records.count end end - context 'grouped results' do + context 'when grouped results' do let(:datatable) { GroupedDatatable.new(sample_params) } it 'returns the count' do @@ -23,15 +23,14 @@ end end - describe '#records_filtered_count' do - context 'ungrouped results' do + context 'when ungrouped results' do it 'returns the count' do expect(datatable.send(:records_filtered_count)).to eq records.count end end - context 'grouped results' do + context 'when grouped results' do let(:datatable) { GroupedDatatable.new(sample_params) } it 'returns the count' do diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax_datatables_rails/orm/active_record_filter_records_spec.rb similarity index 93% rename from spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb rename to spec/ajax_datatables_rails/orm/active_record_filter_records_spec.rb index 8f59020b..2d6a4bb6 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax_datatables_rails/orm/active_record_filter_records_spec.rb @@ -18,21 +18,22 @@ end it 'performs a simple search first' do - expect(datatable).to receive(:build_conditions_for_datatable) + allow(datatable).to receive(:build_conditions_for_datatable) datatable.filter_records(records) + expect(datatable).to have_received(:build_conditions_for_datatable) end it 'does not search unsearchable fields' do criteria = datatable.filter_records(records) - expect(criteria.to_sql).not_to include('email_hash') + expect(criteria.to_sql).to_not include('email_hash') end end - it 'performs a composite search second' do datatable.params[:search] = { value: '' } - expect(datatable).to receive(:build_conditions_for_selected_columns) + allow(datatable).to receive(:build_conditions_for_selected_columns) datatable.filter_records(records) + expect(datatable).to have_received(:build_conditions_for_selected_columns) end end @@ -53,8 +54,8 @@ query = datatable.build_conditions results = records.where(query).map(&:username) expect(results).to include('msmith') - expect(results).not_to include('johndoe') - expect(results).not_to include('hsmith') + expect(results).to_not include('johndoe') + expect(results).to_not include('hsmith') end end end @@ -71,7 +72,7 @@ expect(result).to be_a(Arel::Nodes::Grouping) end - context 'no search query' do + context 'when no search query' do it 'returns empty query' do datatable.params[:search] = { value: '' } expect(datatable.build_conditions_for_datatable).to be_blank @@ -80,7 +81,7 @@ context 'when none of columns are connected' do before do - allow(datatable).to receive(:searchable_columns) { [] } + allow(datatable).to receive(:searchable_columns).and_return([]) end context 'when search value is a string' do @@ -95,7 +96,7 @@ it 'returns filtered results' do query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) - expect(results).to eq ['johndoe', 'msmith'] + expect(results).to eq %w[johndoe msmith] end end @@ -111,7 +112,7 @@ it 'returns filtered results' do query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) - expect(results).to eq ['johndoe', 'msmith'] + expect(results).to eq %w[johndoe msmith] end end end @@ -126,7 +127,7 @@ query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) expect(results).to include('johndoe') - expect(results).not_to include('msmith') + expect(results).to_not include('msmith') end end @@ -139,7 +140,7 @@ query = datatable.build_conditions_for_datatable results = records.where(query).map(&:username) expect(results).to eq ['johndoe'] - expect(results).not_to include('msmith') + expect(results).to_not include('msmith') end end @@ -152,7 +153,7 @@ end it 'does not raise error' do - allow_any_instance_of(AjaxDatatablesRails::Datatable::Column).to receive(:valid_search_condition?).and_return(true) + allow_any_instance_of(AjaxDatatablesRails::Datatable::Column).to receive(:valid_search_condition?).and_return(true) # rubocop:disable RSpec/AnyInstance expect { datatable.data.size @@ -168,7 +169,7 @@ create(:user, username: 'msmith', email: 'mary.smith@example.com') end - context 'columns include search query' do + context 'when columns include search query' do before do datatable.params[:columns]['0'][:search][:value] = 'doe' datatable.params[:columns]['1'][:search][:value] = 'example' @@ -204,7 +205,7 @@ end if RunningSpec.mysql? - context 'when db_adapter is mysql2' do + context 'when db_adapter is mysql2' do # rubocop:disable RSpec/RepeatedExampleGroupBody it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns expect(result).to respond_to(:to_sql) @@ -214,7 +215,7 @@ end end - context 'when db_adapter is trilogy' do + context 'when db_adapter is trilogy' do # rubocop:disable RSpec/RepeatedExampleGroupBody it 'can call #to_sql on returned object' do result = datatable.build_conditions_for_selected_columns expect(result).to respond_to(:to_sql) @@ -227,8 +228,9 @@ end it 'calls #build_conditions_for_selected_columns' do - expect(datatable).to receive(:build_conditions_for_selected_columns) + allow(datatable).to receive(:build_conditions_for_selected_columns) datatable.build_conditions + expect(datatable).to have_received(:build_conditions_for_selected_columns) end context 'with search values in columns' do @@ -240,13 +242,13 @@ query = datatable.build_conditions_for_selected_columns results = records.where(query).map(&:username) expect(results).to include('johndoe') - expect(results).not_to include('msmith') + expect(results).to_not include('msmith') end end end describe 'filter conditions' do - context 'date condition' do + context 'with date condition' do describe 'it can filter records with condition :date_range' do let(:datatable) { DatatableCondDate.new(sample_params) } @@ -329,7 +331,7 @@ end end - context 'numeric condition' do + context 'with numeric condition' do before do create(:user, first_name: 'john', post_id: 1) create(:user, first_name: 'mary', post_id: 2) @@ -448,7 +450,7 @@ end end - context 'proc condition' do + context 'with proc condition' do describe 'it can filter records with lambda/proc condition' do let(:datatable) { DatatableCondProc.new(sample_params) } @@ -467,7 +469,7 @@ end end - context 'string condition' do + context 'with string condition' do describe 'it can filter records with condition :start_with' do let(:datatable) { DatatableCondStartWith.new(sample_params) } @@ -605,7 +607,7 @@ end end - context 'unknown condition' do + context 'with unknown condition' do let(:datatable) { DatatableCondUnknown.new(sample_params) } before do @@ -619,7 +621,7 @@ end end - context 'custom column' do + context 'with custom column' do describe 'it can filter records with custom column' do let(:datatable) { DatatableCustomColumn.new(sample_params) } diff --git a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb b/spec/ajax_datatables_rails/orm/active_record_paginate_records_spec.rb similarity index 83% rename from spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb rename to spec/ajax_datatables_rails/orm/active_record_paginate_records_spec.rb index e715b2fe..a33c834d 100644 --- a/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +++ b/spec/ajax_datatables_rails/orm/active_record_paginate_records_spec.rb @@ -17,7 +17,7 @@ expect { datatable.paginate_records }.to raise_error(ArgumentError) end - it 'paginates records properly' do + it 'paginates records properly' do # rubocop:disable RSpec/ExampleLength if RunningSpec.oracle? if Rails.version.in? %w[4.2.11] expect(datatable.paginate_records(records).to_sql).to include( @@ -54,13 +54,15 @@ end it 'depends on the value of #offset' do - expect(datatable.datatable).to receive(:offset) + allow(datatable.datatable).to receive(:offset) datatable.paginate_records(records) + expect(datatable.datatable).to have_received(:offset) end it 'depends on the value of #per_page' do - expect(datatable.datatable).to receive(:per_page).at_least(:once) { 10 } + allow(datatable.datatable).to receive(:per_page).at_least(:once).and_return(10) datatable.paginate_records(records) + expect(datatable.datatable).to have_received(:per_page).at_least(:once) end end diff --git a/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb b/spec/ajax_datatables_rails/orm/active_record_sort_records_spec.rb similarity index 100% rename from spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb rename to spec/ajax_datatables_rails/orm/active_record_sort_records_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cd6970d5..eb3641d7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -85,4 +85,4 @@ def self.postgresql? require 'ajax-datatables-rails' # Load test helpers -Dir[File.dirname(__FILE__) + '/support/**/*.rb'].sort.each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } diff --git a/spec/support/datatables/complex_datatable.rb b/spec/support/datatables/complex_datatable.rb index ece7ee49..2999c467 100644 --- a/spec/support/datatables/complex_datatable.rb +++ b/spec/support/datatables/complex_datatable.rb @@ -14,7 +14,7 @@ def view_columns } end - def data + def data # rubocop:disable Metrics/MethodLength records.map do |record| { username: record.username, @@ -29,7 +29,7 @@ def data end end - def get_raw_records + def get_raw_records # rubocop:disable Naming/AccessorMethodName User.all end end diff --git a/spec/support/datatables/datatable_cond_string.rb b/spec/support/datatables/datatable_cond_string.rb index 42fb4acf..2cc78c17 100644 --- a/spec/support/datatables/datatable_cond_string.rb +++ b/spec/support/datatables/datatable_cond_string.rb @@ -38,6 +38,6 @@ def view_columns class DatatableWithFormater < ComplexDatatable def view_columns - super.deep_merge(last_name: { formatter: ->(o) { o.upcase } }) + super.deep_merge(last_name: { formatter: lambda(&:upcase) }) end end diff --git a/spec/support/datatables/datatable_custom_column.rb b/spec/support/datatables/datatable_custom_column.rb index 4740adea..2d8db393 100644 --- a/spec/support/datatables/datatable_custom_column.rb +++ b/spec/support/datatables/datatable_custom_column.rb @@ -5,7 +5,7 @@ def view_columns super.deep_merge(full_name: { cond: filter_full_name }) end - def get_raw_records + def get_raw_records # rubocop:disable Naming/AccessorMethodName User.select("*, CONCAT(first_name, ' ', last_name) as full_name") end diff --git a/spec/support/datatables/grouped_datatable_array.rb b/spec/support/datatables/grouped_datatable_array.rb index e4547adf..e23e0126 100644 --- a/spec/support/datatables/grouped_datatable_array.rb +++ b/spec/support/datatables/grouped_datatable_array.rb @@ -2,7 +2,7 @@ class GroupedDatatable < ComplexDatatable - def get_raw_records + def get_raw_records # rubocop:disable Naming/AccessorMethodName User.all.group(:id) end end diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index dff2e791..0323ab51 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Metrics/MethodLength +# rubocop:disable Metrics/MethodLength, Layout/HashAlignment def sample_params ActionController::Parameters.new( { @@ -58,13 +58,16 @@ def sample_params 'order' => { '0' => { 'column' => '0', 'dir' => 'asc' }, }, - 'start' => '0', 'length' => '10', 'search' => { + 'start' => '0', + 'length' => '10', + 'search' => { 'value' => '', 'regex' => 'false' }, - '_' => '1423364387185' + '_' => '1423364387185', } ) end +# rubocop:enable Metrics/MethodLength, Layout/HashAlignment def sample_params_json hash_params = sample_params.to_unsafe_h @@ -72,7 +75,6 @@ def sample_params_json hash_params['order'] = hash_params['order'].values ActionController::Parameters.new(hash_params) end -# rubocop:enable Metrics/MethodLength def nulls_last_sql(datatable) case datatable.db_adapter diff --git a/spec/support/models/user.rb b/spec/support/models/user.rb index 887efd98..34d527e2 100644 --- a/spec/support/models/user.rb +++ b/spec/support/models/user.rb @@ -8,8 +8,8 @@ def full_name end def email_hash - return nil if email.nil? + return nil if email.nil? - Digest::SHA256.hexdigest email + Digest::SHA256.hexdigest email end end From 53f86075ee95a5e5aefce8a7432dd2e771afcfdd Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 23 Sep 2024 21:25:57 +0200 Subject: [PATCH 270/290] Update appraisal gem --- Gemfile | 2 +- gemfiles/rails_7.0.8.gemfile | 2 +- gemfiles/rails_7.1.0.gemfile | 2 +- gemfiles/rails_7.2.0.gemfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index f6dbad75..45eb77bf 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gemspec -gem 'appraisal', git: 'https://github.com/n-rodriguez/appraisal.git', branch: 'wip/combustion' +gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' # gem 'activerecord-oracle_enhanced-adapter' gem 'combustion' diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index 1f491efa..5e4c38b9 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "combustion" gem "database_cleaner" gem "factory_bot" diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index 97ecb805..77552bf8 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "combustion" gem "database_cleaner" gem "factory_bot" diff --git a/gemfiles/rails_7.2.0.gemfile b/gemfiles/rails_7.2.0.gemfile index ee0697dc..2ed9ec3b 100644 --- a/gemfiles/rails_7.2.0.gemfile +++ b/gemfiles/rails_7.2.0.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "appraisal", git: "https://github.com/n-rodriguez/appraisal.git", branch: "wip/combustion" +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "combustion" gem "database_cleaner" gem "factory_bot" From a21694e34e11810b8b46ad01a6f4144f13f7d117 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 24 Sep 2024 00:30:37 +0200 Subject: [PATCH 271/290] Bump to paambaati/codeclimate-action@v9 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab63d87d..c112a187 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -139,7 +139,7 @@ jobs: DB_ADAPTER: ${{ matrix.adapter }} - name: RSpec & publish code coverage - uses: paambaati/codeclimate-action@v8.0.0 + uses: paambaati/codeclimate-action@v9.0.0 env: DB_ADAPTER: ${{ matrix.adapter }} CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} From 9e9205c296c2b14952edd91c9a8f18201aa1aaa7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 24 Sep 2024 17:12:33 +0200 Subject: [PATCH 272/290] Improve Appraisal config --- .github/workflows/ci.yml | 2 +- Appraisals | 192 +++++++++++++----- Gemfile | 6 +- gemfiles/rails_7.0.8_with_mysql2.gemfile | 36 ++++ .../rails_7.0.8_with_oracle_enhanced.gemfile | 37 ++++ ...mfile => rails_7.0.8_with_postgis.gemfile} | 24 +-- gemfiles/rails_7.0.8_with_postgresql.gemfile | 36 ++++ gemfiles/rails_7.0.8_with_sqlite3.gemfile | 36 ++++ gemfiles/rails_7.0.8_with_trilogy.gemfile | 36 ++++ gemfiles/rails_7.1.0.gemfile | 52 ----- gemfiles/rails_7.1.0_with_mysql2.gemfile | 26 +++ .../rails_7.1.0_with_oracle_enhanced.gemfile | 27 +++ gemfiles/rails_7.1.0_with_postgis.gemfile | 27 +++ gemfiles/rails_7.1.0_with_postgresql.gemfile | 26 +++ gemfiles/rails_7.1.0_with_sqlite3.gemfile | 26 +++ gemfiles/rails_7.1.0_with_trilogy.gemfile | 26 +++ gemfiles/rails_7.2.0.gemfile | 47 ----- gemfiles/rails_7.2.0_with_mysql2.gemfile | 26 +++ .../rails_7.2.0_with_oracle_enhanced.gemfile | 27 +++ gemfiles/rails_7.2.0_with_postgis.gemfile | 27 +++ gemfiles/rails_7.2.0_with_postgresql.gemfile | 26 +++ gemfiles/rails_7.2.0_with_sqlite3.gemfile | 26 +++ gemfiles/rails_7.2.0_with_trilogy.gemfile | 26 +++ 23 files changed, 645 insertions(+), 175 deletions(-) create mode 100644 gemfiles/rails_7.0.8_with_mysql2.gemfile create mode 100644 gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile rename gemfiles/{rails_7.0.8.gemfile => rails_7.0.8_with_postgis.gemfile} (58%) create mode 100644 gemfiles/rails_7.0.8_with_postgresql.gemfile create mode 100644 gemfiles/rails_7.0.8_with_sqlite3.gemfile create mode 100644 gemfiles/rails_7.0.8_with_trilogy.gemfile delete mode 100644 gemfiles/rails_7.1.0.gemfile create mode 100644 gemfiles/rails_7.1.0_with_mysql2.gemfile create mode 100644 gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile create mode 100644 gemfiles/rails_7.1.0_with_postgis.gemfile create mode 100644 gemfiles/rails_7.1.0_with_postgresql.gemfile create mode 100644 gemfiles/rails_7.1.0_with_sqlite3.gemfile create mode 100644 gemfiles/rails_7.1.0_with_trilogy.gemfile delete mode 100644 gemfiles/rails_7.2.0.gemfile create mode 100644 gemfiles/rails_7.2.0_with_mysql2.gemfile create mode 100644 gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile create mode 100644 gemfiles/rails_7.2.0_with_postgis.gemfile create mode 100644 gemfiles/rails_7.2.0_with_postgresql.gemfile create mode 100644 gemfiles/rails_7.2.0_with_sqlite3.gemfile create mode 100644 gemfiles/rails_7.2.0_with_trilogy.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c112a187..58d43f39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.rails }}.gemfile + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.rails }}_with_${{ matrix.adapter }}.gemfile ORACLE_COOKIE: sqldev ORACLE_FILE: oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip ORACLE_HOME: /u01/app/oracle/product/11.2.0/xe diff --git a/Appraisals b/Appraisals index 53eb9ac3..41b0c378 100644 --- a/Appraisals +++ b/Appraisals @@ -1,28 +1,48 @@ # frozen_string_literal: true -appraise 'rails_7.0.8' do # rubocop:disable Metrics/BlockLength - gem 'rails', '7.0.8' +############### +# RAILS 7.0.8 # +############### - install_if '-> { ENV["DB_ADAPTER"] == "sqlite3" }' do - gem 'sqlite3', '~> 1.5.0' - end +appraise 'rails_7.0.8_with_postgresql' do + gem 'rails', '7.0.8' + gem 'pg' - install_if '-> { ENV["DB_ADAPTER"] == "mysql2" }' do - gem 'mysql2' + # Fix: + # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 + # Add logger to your Gemfile or gemspec. + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do + gem 'base64' + gem 'bigdecimal' + gem 'benchmark' + gem 'drb' + gem 'logger' + gem 'mutex_m' + gem 'ostruct' end +end - install_if '-> { ENV["DB_ADAPTER"] == "trilogy" }' do - gem 'activerecord-trilogy-adapter' - end +appraise 'rails_7.0.8_with_sqlite3' do + gem 'rails', '7.0.8' + gem 'sqlite3', '~> 1.5.0' - install_if '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' do - gem 'ruby-oci8' - gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' + # Fix: + # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 + # Add logger to your Gemfile or gemspec. + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do + gem 'base64' + gem 'bigdecimal' + gem 'benchmark' + gem 'drb' + gem 'logger' + gem 'mutex_m' + gem 'ostruct' end +end - install_if '-> { ENV["DB_ADAPTER"] == "postgis" }' do - gem 'activerecord-postgis-adapter' - end +appraise 'rails_7.0.8_with_mysql2' do + gem 'rails', '7.0.8' + gem 'mysql2' # Fix: # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 @@ -38,60 +58,130 @@ appraise 'rails_7.0.8' do # rubocop:disable Metrics/BlockLength end end -appraise 'rails_7.1.0' do - gem 'rails', '7.1.0' - - install_if '-> { ENV["DB_ADAPTER"] == "sqlite3" }' do - gem 'sqlite3', '~> 1.5.0' - end +appraise 'rails_7.0.8_with_trilogy' do + gem 'rails', '7.0.8' + gem 'activerecord-trilogy-adapter' - install_if '-> { ENV["DB_ADAPTER"] == "mysql2" }' do - gem 'mysql2' + # Fix: + # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 + # Add logger to your Gemfile or gemspec. + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do + gem 'base64' + gem 'bigdecimal' + gem 'benchmark' + gem 'drb' + gem 'logger' + gem 'mutex_m' + gem 'ostruct' end +end - install_if '-> { ENV["DB_ADAPTER"] == "trilogy" }' do - gem 'activerecord-trilogy-adapter' - end +appraise 'rails_7.0.8_with_oracle_enhanced' do + gem 'rails', '7.0.8' + gem 'ruby-oci8' + gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' - install_if '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' do - gem 'ruby-oci8' - gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + # Fix: + # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 + # Add logger to your Gemfile or gemspec. + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do + gem 'base64' + gem 'bigdecimal' + gem 'benchmark' + gem 'drb' + gem 'logger' + gem 'mutex_m' + gem 'ostruct' end +end - install_if '-> { ENV["DB_ADAPTER"] == "postgis" }' do - gem 'activerecord-postgis-adapter' - end +appraise 'rails_7.0.8_with_postgis' do + gem 'rails', '7.0.8' + gem 'pg' + gem 'activerecord-postgis-adapter' # Fix: # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") }' do + install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do + gem 'base64' + gem 'bigdecimal' + gem 'benchmark' + gem 'drb' gem 'logger' + gem 'mutex_m' gem 'ostruct' end end -appraise 'rails_7.2.0' do +############### +# RAILS 7.1.0 # +############### + +appraise 'rails_7.1.0_with_postgresql' do + gem 'rails', '7.1.0' + gem 'pg' +end + +appraise 'rails_7.1.0_with_sqlite3' do + gem 'rails', '7.1.0' + gem 'sqlite3', '~> 1.5.0' +end + +appraise 'rails_7.1.0_with_mysql2' do + gem 'rails', '7.1.0' + gem 'mysql2' +end + +appraise 'rails_7.1.0_with_trilogy' do + gem 'rails', '7.1.0' + gem 'activerecord-trilogy-adapter' +end + +appraise 'rails_7.1.0_with_oracle_enhanced' do + gem 'rails', '7.1.0' + gem 'ruby-oci8' + gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' +end + +appraise 'rails_7.1.0_with_postgis' do + gem 'rails', '7.1.0' + gem 'pg' + gem 'activerecord-postgis-adapter' +end + +############### +# RAILS 7.2.0 # +############### + +appraise 'rails_7.2.0_with_postgresql' do gem 'rails', '7.2.0' + gem 'pg' +end - install_if '-> { ENV["DB_ADAPTER"] == "sqlite3" }' do - gem 'sqlite3', '~> 1.5.0' - end +appraise 'rails_7.2.0_with_sqlite3' do + gem 'rails', '7.2.0' + gem 'sqlite3', '~> 1.5.0' +end - install_if '-> { ENV["DB_ADAPTER"] == "mysql2" }' do - gem 'mysql2' - end +appraise 'rails_7.2.0_with_mysql2' do + gem 'rails', '7.2.0' + gem 'mysql2' +end - install_if '-> { ENV["DB_ADAPTER"] == "trilogy" }' do - gem 'activerecord-trilogy-adapter' - end +appraise 'rails_7.2.0_with_trilogy' do + gem 'rails', '7.2.0' + gem 'activerecord-trilogy-adapter' +end - install_if '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' do - gem 'ruby-oci8' - gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' - end +appraise 'rails_7.2.0_with_oracle_enhanced' do + gem 'rails', '7.2.0' + gem 'ruby-oci8' + gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' +end - install_if '-> { ENV["DB_ADAPTER"] == "postgis" }' do - gem 'activerecord-postgis-adapter', git: 'https://github.com/rgeo/activerecord-postgis-adapter.git' - end +appraise 'rails_7.2.0_with_postgis' do + gem 'rails', '7.2.0' + gem 'pg' + gem 'activerecord-postgis-adapter', git: 'https://github.com/rgeo/activerecord-postgis-adapter.git' end diff --git a/Gemfile b/Gemfile index 45eb77bf..f9de92e8 100644 --- a/Gemfile +++ b/Gemfile @@ -6,14 +6,12 @@ gemspec gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' -# gem 'activerecord-oracle_enhanced-adapter' gem 'combustion' gem 'database_cleaner' gem 'factory_bot' gem 'faker' gem 'generator_spec' gem 'guard-rspec' -gem 'pg' gem 'pry' gem 'puma' gem 'rake' @@ -25,3 +23,7 @@ gem 'rubocop-performance' gem 'rubocop-rake' gem 'rubocop-rspec' gem 'simplecov' + +# Fallback to pg if DB_ADAPTER is not set (like in dev/local environment) +# so we can still call bin/rspec +gem 'pg' if $PROGRAM_NAME == 'bin/rspec' && ENV['DB_ADAPTER'].nil? diff --git a/gemfiles/rails_7.0.8_with_mysql2.gemfile b/gemfiles/rails_7.0.8_with_mysql2.gemfile new file mode 100644 index 00000000..90d98684 --- /dev/null +++ b/gemfiles/rails_7.0.8_with_mysql2.gemfile @@ -0,0 +1,36 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.0.8" +gem "mysql2" + +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "benchmark" + gem "drb" + gem "logger" + gem "mutex_m" + gem "ostruct" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile b/gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile new file mode 100644 index 00000000..5abe3055 --- /dev/null +++ b/gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile @@ -0,0 +1,37 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.0.8" +gem "ruby-oci8" +gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" + +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "benchmark" + gem "drb" + gem "logger" + gem "mutex_m" + gem "ostruct" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8_with_postgis.gemfile similarity index 58% rename from gemfiles/rails_7.0.8.gemfile rename to gemfiles/rails_7.0.8_with_postgis.gemfile index 5e4c38b9..557dd80f 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8_with_postgis.gemfile @@ -9,7 +9,6 @@ gem "factory_bot" gem "faker" gem "generator_spec" gem "guard-rspec" -gem "pg" gem "pry" gem "puma" gem "rake" @@ -22,27 +21,8 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "rails", "7.0.8" - -install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.5.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do - gem "mysql2" -end - -install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do - gem "activerecord-trilogy-adapter" -end - -install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "ruby-oci8" - gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "postgis" } do - gem "activerecord-postgis-adapter" -end +gem "pg" +gem "activerecord-postgis-adapter" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do gem "base64" diff --git a/gemfiles/rails_7.0.8_with_postgresql.gemfile b/gemfiles/rails_7.0.8_with_postgresql.gemfile new file mode 100644 index 00000000..c0b6fe69 --- /dev/null +++ b/gemfiles/rails_7.0.8_with_postgresql.gemfile @@ -0,0 +1,36 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.0.8" +gem "pg" + +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "benchmark" + gem "drb" + gem "logger" + gem "mutex_m" + gem "ostruct" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.8_with_sqlite3.gemfile b/gemfiles/rails_7.0.8_with_sqlite3.gemfile new file mode 100644 index 00000000..1ac98dde --- /dev/null +++ b/gemfiles/rails_7.0.8_with_sqlite3.gemfile @@ -0,0 +1,36 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.0.8" +gem "sqlite3", "~> 1.5.0" + +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "benchmark" + gem "drb" + gem "logger" + gem "mutex_m" + gem "ostruct" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.8_with_trilogy.gemfile b/gemfiles/rails_7.0.8_with_trilogy.gemfile new file mode 100644 index 00000000..eb10fc56 --- /dev/null +++ b/gemfiles/rails_7.0.8_with_trilogy.gemfile @@ -0,0 +1,36 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.0.8" +gem "activerecord-trilogy-adapter" + +install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do + gem "base64" + gem "bigdecimal" + gem "benchmark" + gem "drb" + gem "logger" + gem "mutex_m" + gem "ostruct" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile deleted file mode 100644 index 77552bf8..00000000 --- a/gemfiles/rails_7.1.0.gemfile +++ /dev/null @@ -1,52 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "guard-rspec" -gem "pg" -gem "pry" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" -gem "simplecov" -gem "rails", "7.1.0" - -install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.5.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do - gem "mysql2" -end - -install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do - gem "activerecord-trilogy-adapter" -end - -install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "ruby-oci8" - gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" -end - -install_if -> { ENV["DB_ADAPTER"] == "postgis" } do - gem "activerecord-postgis-adapter" -end - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") } do - gem "logger" - gem "ostruct" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_mysql2.gemfile b/gemfiles/rails_7.1.0_with_mysql2.gemfile new file mode 100644 index 00000000..00798abb --- /dev/null +++ b/gemfiles/rails_7.1.0_with_mysql2.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.1.0" +gem "mysql2" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile new file mode 100644 index 00000000..4b06936c --- /dev/null +++ b/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.1.0" +gem "ruby-oci8" +gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_postgis.gemfile b/gemfiles/rails_7.1.0_with_postgis.gemfile new file mode 100644 index 00000000..9f48bf30 --- /dev/null +++ b/gemfiles/rails_7.1.0_with_postgis.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.1.0" +gem "pg" +gem "activerecord-postgis-adapter" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_postgresql.gemfile b/gemfiles/rails_7.1.0_with_postgresql.gemfile new file mode 100644 index 00000000..338df424 --- /dev/null +++ b/gemfiles/rails_7.1.0_with_postgresql.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.1.0" +gem "pg" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_sqlite3.gemfile b/gemfiles/rails_7.1.0_with_sqlite3.gemfile new file mode 100644 index 00000000..ecceebf9 --- /dev/null +++ b/gemfiles/rails_7.1.0_with_sqlite3.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.1.0" +gem "sqlite3", "~> 1.5.0" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_trilogy.gemfile b/gemfiles/rails_7.1.0_with_trilogy.gemfile new file mode 100644 index 00000000..9ac220c8 --- /dev/null +++ b/gemfiles/rails_7.1.0_with_trilogy.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.1.0" +gem "activerecord-trilogy-adapter" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.0.gemfile b/gemfiles/rails_7.2.0.gemfile deleted file mode 100644 index 2ed9ec3b..00000000 --- a/gemfiles/rails_7.2.0.gemfile +++ /dev/null @@ -1,47 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "guard-rspec" -gem "pg" -gem "pry" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" -gem "simplecov" -gem "rails", "7.2.0" - -install_if -> { ENV["DB_ADAPTER"] == "sqlite3" } do - gem "sqlite3", "~> 1.5.0" -end - -install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do - gem "mysql2" -end - -install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do - gem "activerecord-trilogy-adapter" -end - -install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do - gem "ruby-oci8" - gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" -end - -install_if -> { ENV["DB_ADAPTER"] == "postgis" } do - gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_mysql2.gemfile b/gemfiles/rails_7.2.0_with_mysql2.gemfile new file mode 100644 index 00000000..9deebff8 --- /dev/null +++ b/gemfiles/rails_7.2.0_with_mysql2.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" +gem "mysql2" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile new file mode 100644 index 00000000..17cf98ad --- /dev/null +++ b/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" +gem "ruby-oci8" +gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_postgis.gemfile b/gemfiles/rails_7.2.0_with_postgis.gemfile new file mode 100644 index 00000000..ae616964 --- /dev/null +++ b/gemfiles/rails_7.2.0_with_postgis.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" +gem "pg" +gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_postgresql.gemfile b/gemfiles/rails_7.2.0_with_postgresql.gemfile new file mode 100644 index 00000000..f8fb186e --- /dev/null +++ b/gemfiles/rails_7.2.0_with_postgresql.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" +gem "pg" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_sqlite3.gemfile b/gemfiles/rails_7.2.0_with_sqlite3.gemfile new file mode 100644 index 00000000..3ba3ec0a --- /dev/null +++ b/gemfiles/rails_7.2.0_with_sqlite3.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" +gem "sqlite3", "~> 1.5.0" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_trilogy.gemfile b/gemfiles/rails_7.2.0_with_trilogy.gemfile new file mode 100644 index 00000000..3a148a90 --- /dev/null +++ b/gemfiles/rails_7.2.0_with_trilogy.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "guard-rspec" +gem "pry" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "rubocop" +gem "rubocop-factory_bot" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "rails", "7.2.0" +gem "activerecord-trilogy-adapter" + +gemspec path: "../" From ed2d71ec78632f43dbcf4903dc109886dec32783 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 24 Sep 2024 17:47:42 +0200 Subject: [PATCH 273/290] Add comments to explain why trilogy adapter is disabled in CI --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58d43f39..21ea4474 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,10 @@ jobs: - mysql2 - oracle_enhanced - postgis + # Disabled for now: + # Rails 7.0: trilogy_auth_recv: caching_sha2_password requires either TCP with TLS or a unix socket: TRILOGY_UNSUPPORTED + # Rails 7.1: unknown keyword: :uses_transaction + # Rails 7.2: NotImplementedError # - trilogy exclude: # Rails 7.2 needs Ruby > 3.1 From cf90db435f7016d9bc1d12df3b8be743aff9b355 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 28 Sep 2024 17:53:25 +0200 Subject: [PATCH 274/290] Improve Appraisal config --- Appraisals | 12 ++++++++++++ Gemfile | 5 ++--- gemfiles/rails_7.0.8_with_postgis.gemfile | 2 +- gemfiles/rails_7.0.8_with_postgresql.gemfile | 2 +- gemfiles/rails_7.1.0_with_postgis.gemfile | 2 +- gemfiles/rails_7.1.0_with_postgresql.gemfile | 2 +- gemfiles/rails_7.2.0_with_postgis.gemfile | 2 +- gemfiles/rails_7.2.0_with_postgresql.gemfile | 2 +- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Appraisals b/Appraisals index 41b0c378..ab74f6e8 100644 --- a/Appraisals +++ b/Appraisals @@ -25,6 +25,7 @@ end appraise 'rails_7.0.8_with_sqlite3' do gem 'rails', '7.0.8' gem 'sqlite3', '~> 1.5.0' + remove_gem 'pg' # Fix: # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 @@ -43,6 +44,7 @@ end appraise 'rails_7.0.8_with_mysql2' do gem 'rails', '7.0.8' gem 'mysql2' + remove_gem 'pg' # Fix: # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 @@ -61,6 +63,7 @@ end appraise 'rails_7.0.8_with_trilogy' do gem 'rails', '7.0.8' gem 'activerecord-trilogy-adapter' + remove_gem 'pg' # Fix: # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 @@ -80,6 +83,7 @@ appraise 'rails_7.0.8_with_oracle_enhanced' do gem 'rails', '7.0.8' gem 'ruby-oci8' gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' + remove_gem 'pg' # Fix: # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 @@ -126,22 +130,26 @@ end appraise 'rails_7.1.0_with_sqlite3' do gem 'rails', '7.1.0' gem 'sqlite3', '~> 1.5.0' + remove_gem 'pg' end appraise 'rails_7.1.0_with_mysql2' do gem 'rails', '7.1.0' gem 'mysql2' + remove_gem 'pg' end appraise 'rails_7.1.0_with_trilogy' do gem 'rails', '7.1.0' gem 'activerecord-trilogy-adapter' + remove_gem 'pg' end appraise 'rails_7.1.0_with_oracle_enhanced' do gem 'rails', '7.1.0' gem 'ruby-oci8' gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + remove_gem 'pg' end appraise 'rails_7.1.0_with_postgis' do @@ -162,22 +170,26 @@ end appraise 'rails_7.2.0_with_sqlite3' do gem 'rails', '7.2.0' gem 'sqlite3', '~> 1.5.0' + remove_gem 'pg' end appraise 'rails_7.2.0_with_mysql2' do gem 'rails', '7.2.0' gem 'mysql2' + remove_gem 'pg' end appraise 'rails_7.2.0_with_trilogy' do gem 'rails', '7.2.0' gem 'activerecord-trilogy-adapter' + remove_gem 'pg' end appraise 'rails_7.2.0_with_oracle_enhanced' do gem 'rails', '7.2.0' gem 'ruby-oci8' gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + remove_gem 'pg' end appraise 'rails_7.2.0_with_postgis' do diff --git a/Gemfile b/Gemfile index f9de92e8..e37e11d1 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,5 @@ gem 'rubocop-rake' gem 'rubocop-rspec' gem 'simplecov' -# Fallback to pg if DB_ADAPTER is not set (like in dev/local environment) -# so we can still call bin/rspec -gem 'pg' if $PROGRAM_NAME == 'bin/rspec' && ENV['DB_ADAPTER'].nil? +# Fallback to pg in dev/local environment +gem 'pg' diff --git a/gemfiles/rails_7.0.8_with_postgis.gemfile b/gemfiles/rails_7.0.8_with_postgis.gemfile index 557dd80f..0f907b20 100644 --- a/gemfiles/rails_7.0.8_with_postgis.gemfile +++ b/gemfiles/rails_7.0.8_with_postgis.gemfile @@ -20,8 +20,8 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.0.8" gem "pg" +gem "rails", "7.0.8" gem "activerecord-postgis-adapter" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do diff --git a/gemfiles/rails_7.0.8_with_postgresql.gemfile b/gemfiles/rails_7.0.8_with_postgresql.gemfile index c0b6fe69..b2202905 100644 --- a/gemfiles/rails_7.0.8_with_postgresql.gemfile +++ b/gemfiles/rails_7.0.8_with_postgresql.gemfile @@ -20,8 +20,8 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.0.8" gem "pg" +gem "rails", "7.0.8" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do gem "base64" diff --git a/gemfiles/rails_7.1.0_with_postgis.gemfile b/gemfiles/rails_7.1.0_with_postgis.gemfile index 9f48bf30..c7a8276c 100644 --- a/gemfiles/rails_7.1.0_with_postgis.gemfile +++ b/gemfiles/rails_7.1.0_with_postgis.gemfile @@ -20,8 +20,8 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.1.0" gem "pg" +gem "rails", "7.1.0" gem "activerecord-postgis-adapter" gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_postgresql.gemfile b/gemfiles/rails_7.1.0_with_postgresql.gemfile index 338df424..02ad0018 100644 --- a/gemfiles/rails_7.1.0_with_postgresql.gemfile +++ b/gemfiles/rails_7.1.0_with_postgresql.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.1.0" gem "pg" +gem "rails", "7.1.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_postgis.gemfile b/gemfiles/rails_7.2.0_with_postgis.gemfile index ae616964..81dbb10e 100644 --- a/gemfiles/rails_7.2.0_with_postgis.gemfile +++ b/gemfiles/rails_7.2.0_with_postgis.gemfile @@ -20,8 +20,8 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.2.0" gem "pg" +gem "rails", "7.2.0" gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_postgresql.gemfile b/gemfiles/rails_7.2.0_with_postgresql.gemfile index f8fb186e..1c9c96f8 100644 --- a/gemfiles/rails_7.2.0_with_postgresql.gemfile +++ b/gemfiles/rails_7.2.0_with_postgresql.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.2.0" gem "pg" +gem "rails", "7.2.0" gemspec path: "../" From 3f53a49ff0a9a050712caeadb8645f236a5b38a8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 28 Sep 2024 17:59:18 +0200 Subject: [PATCH 275/290] oracle-enhanced v7.1.x is out \o/ --- Appraisals | 4 +--- gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile | 3 +-- gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Appraisals b/Appraisals index ab74f6e8..95602572 100644 --- a/Appraisals +++ b/Appraisals @@ -147,8 +147,7 @@ end appraise 'rails_7.1.0_with_oracle_enhanced' do gem 'rails', '7.1.0' - gem 'ruby-oci8' - gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + gem 'activerecord-oracle_enhanced-adapter', '~> 7.1.0' remove_gem 'pg' end @@ -187,7 +186,6 @@ end appraise 'rails_7.2.0_with_oracle_enhanced' do gem 'rails', '7.2.0' - gem 'ruby-oci8' gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' remove_gem 'pg' end diff --git a/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile index 4b06936c..2ce152c6 100644 --- a/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile @@ -21,7 +21,6 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "rails", "7.1.0" -gem "ruby-oci8" -gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" +gem "activerecord-oracle_enhanced-adapter", "~> 7.1.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile index 17cf98ad..ec1368b3 100644 --- a/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile @@ -21,7 +21,6 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "rails", "7.2.0" -gem "ruby-oci8" gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" gemspec path: "../" From e94fc295f9af0b87b683fcdc276e41dcf2430def Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 28 Sep 2024 18:01:07 +0200 Subject: [PATCH 276/290] Re-enable CI for oracle_enhanced with Rails 7.1 --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21ea4474..7892ab59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,8 +109,6 @@ jobs: # `create_apiwrap' - rails: rails_7.2.0 adapter: oracle_enhanced - - rails: rails_7.1.0 - adapter: oracle_enhanced steps: - name: Checkout From 3dd685b79bc4fde13875894ac04c2bd8b9e90ac7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 30 Sep 2024 02:33:10 +0200 Subject: [PATCH 277/290] Coding style --- .rubocop.yml | 1 - lib/ajax-datatables-rails.rb | 19 +++++++++++-------- lib/generators/rails/datatable_generator.rb | 2 +- .../{datatable.rb => datatable.rb.erb} | 0 4 files changed, 12 insertions(+), 10 deletions(-) rename lib/generators/rails/templates/{datatable.rb => datatable.rb.erb} (100%) diff --git a/.rubocop.yml b/.rubocop.yml index f97f2160..912f20f5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,6 @@ AllCops: - bin/* - gemfiles/* - spec/dummy/**/* - - lib/generators/**/*.rb ######### # STYLE # diff --git a/lib/ajax-datatables-rails.rb b/lib/ajax-datatables-rails.rb index 05d6fff1..cb9f515f 100644 --- a/lib/ajax-datatables-rails.rb +++ b/lib/ajax-datatables-rails.rb @@ -1,14 +1,17 @@ # frozen_string_literal: true +# require external dependencies require 'zeitwerk' -loader = Zeitwerk::Loader.for_gem -generators = "#{__dir__}/generators" -loader.ignore(generators) -loader.inflector.inflect( - 'orm' => 'ORM', - 'ajax-datatables-rails' => 'AjaxDatatablesRails' -) -loader.setup + +# load zeitwerk +Zeitwerk::Loader.for_gem.tap do |loader| + loader.ignore("#{__dir__}/generators") + loader.inflector.inflect( + 'orm' => 'ORM', + 'ajax-datatables-rails' => 'AjaxDatatablesRails' + ) + loader.setup +end module AjaxDatatablesRails end diff --git a/lib/generators/rails/datatable_generator.rb b/lib/generators/rails/datatable_generator.rb index 5ef5afdb..8e582bcd 100644 --- a/lib/generators/rails/datatable_generator.rb +++ b/lib/generators/rails/datatable_generator.rb @@ -10,7 +10,7 @@ class DatatableGenerator < ::Rails::Generators::Base argument :name, type: :string def generate_datatable - template 'datatable.rb', File.join('app', 'datatables', "#{datatable_path}.rb") + template 'datatable.rb.erb', File.join('app', 'datatables', "#{datatable_path}.rb") end def datatable_name diff --git a/lib/generators/rails/templates/datatable.rb b/lib/generators/rails/templates/datatable.rb.erb similarity index 100% rename from lib/generators/rails/templates/datatable.rb rename to lib/generators/rails/templates/datatable.rb.erb From 885c581085fed3310e245a6488ea407b9e4b6167 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 12 Oct 2024 17:47:21 +0200 Subject: [PATCH 278/290] Make gem smaller --- ajax-datatables-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 1c2ddb16..6bf0f390 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0.0' - s.files = `git ls-files`.split("\n") + s.files = Dir['README.md', 'CHANGELOG.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/*.erb'] s.add_dependency 'rails', '>= 7.0' s.add_dependency 'zeitwerk' From ab1b7d3e7ed04e3737dc59fee61a8fa676927e5a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 8 Nov 2024 00:44:53 +0100 Subject: [PATCH 279/290] Improve Appraisal config --- .github/workflows/ci.yml | 10 +-- Appraisals | 74 +++++++++---------- ....gemfile => rails_7.0_with_mysql2.gemfile} | 2 +- ...=> rails_7.0_with_oracle_enhanced.gemfile} | 2 +- ...gemfile => rails_7.0_with_postgis.gemfile} | 2 +- ...file => rails_7.0_with_postgresql.gemfile} | 2 +- ...gemfile => rails_7.0_with_sqlite3.gemfile} | 2 +- ...gemfile => rails_7.0_with_trilogy.gemfile} | 2 +- ....gemfile => rails_7.1_with_mysql2.gemfile} | 2 +- ...=> rails_7.1_with_oracle_enhanced.gemfile} | 2 +- ...gemfile => rails_7.1_with_postgis.gemfile} | 2 +- ...file => rails_7.1_with_postgresql.gemfile} | 2 +- ...gemfile => rails_7.1_with_sqlite3.gemfile} | 2 +- ...gemfile => rails_7.1_with_trilogy.gemfile} | 2 +- ....gemfile => rails_7.2_with_mysql2.gemfile} | 2 +- ...=> rails_7.2_with_oracle_enhanced.gemfile} | 2 +- ...gemfile => rails_7.2_with_postgis.gemfile} | 2 +- ...file => rails_7.2_with_postgresql.gemfile} | 2 +- ...gemfile => rails_7.2_with_sqlite3.gemfile} | 2 +- ...gemfile => rails_7.2_with_trilogy.gemfile} | 2 +- 20 files changed, 60 insertions(+), 60 deletions(-) rename gemfiles/{rails_7.0.8_with_mysql2.gemfile => rails_7.0_with_mysql2.gemfile} (96%) rename gemfiles/{rails_7.0.8_with_oracle_enhanced.gemfile => rails_7.0_with_oracle_enhanced.gemfile} (96%) rename gemfiles/{rails_7.0.8_with_postgis.gemfile => rails_7.0_with_postgis.gemfile} (96%) rename gemfiles/{rails_7.0.8_with_postgresql.gemfile => rails_7.0_with_postgresql.gemfile} (96%) rename gemfiles/{rails_7.0.8_with_sqlite3.gemfile => rails_7.0_with_sqlite3.gemfile} (96%) rename gemfiles/{rails_7.0.8_with_trilogy.gemfile => rails_7.0_with_trilogy.gemfile} (96%) rename gemfiles/{rails_7.1.0_with_mysql2.gemfile => rails_7.1_with_mysql2.gemfile} (95%) rename gemfiles/{rails_7.1.0_with_oracle_enhanced.gemfile => rails_7.1_with_oracle_enhanced.gemfile} (95%) rename gemfiles/{rails_7.1.0_with_postgis.gemfile => rails_7.1_with_postgis.gemfile} (95%) rename gemfiles/{rails_7.2.0_with_postgresql.gemfile => rails_7.1_with_postgresql.gemfile} (95%) rename gemfiles/{rails_7.1.0_with_sqlite3.gemfile => rails_7.1_with_sqlite3.gemfile} (95%) rename gemfiles/{rails_7.2.0_with_trilogy.gemfile => rails_7.1_with_trilogy.gemfile} (95%) rename gemfiles/{rails_7.2.0_with_mysql2.gemfile => rails_7.2_with_mysql2.gemfile} (95%) rename gemfiles/{rails_7.2.0_with_oracle_enhanced.gemfile => rails_7.2_with_oracle_enhanced.gemfile} (95%) rename gemfiles/{rails_7.2.0_with_postgis.gemfile => rails_7.2_with_postgis.gemfile} (95%) rename gemfiles/{rails_7.1.0_with_postgresql.gemfile => rails_7.2_with_postgresql.gemfile} (95%) rename gemfiles/{rails_7.2.0_with_sqlite3.gemfile => rails_7.2_with_sqlite3.gemfile} (95%) rename gemfiles/{rails_7.1.0_with_trilogy.gemfile => rails_7.2_with_trilogy.gemfile} (95%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7892ab59..f82f61e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,9 +77,9 @@ jobs: - '3.0' - 'head' rails: - - rails_7.2.0 - - rails_7.1.0 - - rails_7.0.8 + - rails_7.2 + - rails_7.1 + - rails_7.0 adapter: - sqlite3 - postgresql @@ -93,7 +93,7 @@ jobs: # - trilogy exclude: # Rails 7.2 needs Ruby > 3.1 - - rails: rails_7.2.0 + - rails: rails_7.2 ruby: '3.0' # Disabled for now because of build error: @@ -107,7 +107,7 @@ jobs: # from # /home/runner/work/ajax-datatables-rails/ajax-datatables-rails/vendor/bundle/ruby/3.0.0/gems/ruby-oci8-2.2.14/ext/oci8/apiwrap.rb:64:in # `create_apiwrap' - - rails: rails_7.2.0 + - rails: rails_7.2 adapter: oracle_enhanced steps: diff --git a/Appraisals b/Appraisals index 95602572..6eeece2f 100644 --- a/Appraisals +++ b/Appraisals @@ -1,11 +1,11 @@ # frozen_string_literal: true ############### -# RAILS 7.0.8 # +# RAILS 7.0 # ############### -appraise 'rails_7.0.8_with_postgresql' do - gem 'rails', '7.0.8' +appraise 'rails_7.0_with_postgresql' do + gem 'rails', '~> 7.0.0' gem 'pg' # Fix: @@ -22,8 +22,8 @@ appraise 'rails_7.0.8_with_postgresql' do end end -appraise 'rails_7.0.8_with_sqlite3' do - gem 'rails', '7.0.8' +appraise 'rails_7.0_with_sqlite3' do + gem 'rails', '~> 7.0.0' gem 'sqlite3', '~> 1.5.0' remove_gem 'pg' @@ -41,8 +41,8 @@ appraise 'rails_7.0.8_with_sqlite3' do end end -appraise 'rails_7.0.8_with_mysql2' do - gem 'rails', '7.0.8' +appraise 'rails_7.0_with_mysql2' do + gem 'rails', '~> 7.0.0' gem 'mysql2' remove_gem 'pg' @@ -60,8 +60,8 @@ appraise 'rails_7.0.8_with_mysql2' do end end -appraise 'rails_7.0.8_with_trilogy' do - gem 'rails', '7.0.8' +appraise 'rails_7.0_with_trilogy' do + gem 'rails', '~> 7.0.0' gem 'activerecord-trilogy-adapter' remove_gem 'pg' @@ -79,8 +79,8 @@ appraise 'rails_7.0.8_with_trilogy' do end end -appraise 'rails_7.0.8_with_oracle_enhanced' do - gem 'rails', '7.0.8' +appraise 'rails_7.0_with_oracle_enhanced' do + gem 'rails', '~> 7.0.0' gem 'ruby-oci8' gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' remove_gem 'pg' @@ -99,8 +99,8 @@ appraise 'rails_7.0.8_with_oracle_enhanced' do end end -appraise 'rails_7.0.8_with_postgis' do - gem 'rails', '7.0.8' +appraise 'rails_7.0_with_postgis' do + gem 'rails', '~> 7.0.0' gem 'pg' gem 'activerecord-postgis-adapter' @@ -122,37 +122,37 @@ end # RAILS 7.1.0 # ############### -appraise 'rails_7.1.0_with_postgresql' do - gem 'rails', '7.1.0' +appraise 'rails_7.1_with_postgresql' do + gem 'rails', '~> 7.1.0' gem 'pg' end -appraise 'rails_7.1.0_with_sqlite3' do - gem 'rails', '7.1.0' +appraise 'rails_7.1_with_sqlite3' do + gem 'rails', '~> 7.1.0' gem 'sqlite3', '~> 1.5.0' remove_gem 'pg' end -appraise 'rails_7.1.0_with_mysql2' do - gem 'rails', '7.1.0' +appraise 'rails_7.1_with_mysql2' do + gem 'rails', '~> 7.1.0' gem 'mysql2' remove_gem 'pg' end -appraise 'rails_7.1.0_with_trilogy' do - gem 'rails', '7.1.0' +appraise 'rails_7.1_with_trilogy' do + gem 'rails', '~> 7.1.0' gem 'activerecord-trilogy-adapter' remove_gem 'pg' end -appraise 'rails_7.1.0_with_oracle_enhanced' do - gem 'rails', '7.1.0' +appraise 'rails_7.1_with_oracle_enhanced' do + gem 'rails', '~> 7.1.0' gem 'activerecord-oracle_enhanced-adapter', '~> 7.1.0' remove_gem 'pg' end -appraise 'rails_7.1.0_with_postgis' do - gem 'rails', '7.1.0' +appraise 'rails_7.1_with_postgis' do + gem 'rails', '~> 7.1.0' gem 'pg' gem 'activerecord-postgis-adapter' end @@ -161,37 +161,37 @@ end # RAILS 7.2.0 # ############### -appraise 'rails_7.2.0_with_postgresql' do - gem 'rails', '7.2.0' +appraise 'rails_7.2_with_postgresql' do + gem 'rails', '~> 7.2.0' gem 'pg' end -appraise 'rails_7.2.0_with_sqlite3' do - gem 'rails', '7.2.0' +appraise 'rails_7.2_with_sqlite3' do + gem 'rails', '~> 7.2.0' gem 'sqlite3', '~> 1.5.0' remove_gem 'pg' end -appraise 'rails_7.2.0_with_mysql2' do - gem 'rails', '7.2.0' +appraise 'rails_7.2_with_mysql2' do + gem 'rails', '~> 7.2.0' gem 'mysql2' remove_gem 'pg' end -appraise 'rails_7.2.0_with_trilogy' do - gem 'rails', '7.2.0' +appraise 'rails_7.2_with_trilogy' do + gem 'rails', '~> 7.2.0' gem 'activerecord-trilogy-adapter' remove_gem 'pg' end -appraise 'rails_7.2.0_with_oracle_enhanced' do - gem 'rails', '7.2.0' +appraise 'rails_7.2_with_oracle_enhanced' do + gem 'rails', '~> 7.2.0' gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' remove_gem 'pg' end -appraise 'rails_7.2.0_with_postgis' do - gem 'rails', '7.2.0' +appraise 'rails_7.2_with_postgis' do + gem 'rails', '~> 7.2.0' gem 'pg' gem 'activerecord-postgis-adapter', git: 'https://github.com/rgeo/activerecord-postgis-adapter.git' end diff --git a/gemfiles/rails_7.0.8_with_mysql2.gemfile b/gemfiles/rails_7.0_with_mysql2.gemfile similarity index 96% rename from gemfiles/rails_7.0.8_with_mysql2.gemfile rename to gemfiles/rails_7.0_with_mysql2.gemfile index 90d98684..d3000d8f 100644 --- a/gemfiles/rails_7.0.8_with_mysql2.gemfile +++ b/gemfiles/rails_7.0_with_mysql2.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.0.8" +gem "rails", "~> 7.0.0" gem "mysql2" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do diff --git a/gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile b/gemfiles/rails_7.0_with_oracle_enhanced.gemfile similarity index 96% rename from gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile rename to gemfiles/rails_7.0_with_oracle_enhanced.gemfile index 5abe3055..215fc370 100644 --- a/gemfiles/rails_7.0.8_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.0_with_oracle_enhanced.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.0.8" +gem "rails", "~> 7.0.0" gem "ruby-oci8" gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" diff --git a/gemfiles/rails_7.0.8_with_postgis.gemfile b/gemfiles/rails_7.0_with_postgis.gemfile similarity index 96% rename from gemfiles/rails_7.0.8_with_postgis.gemfile rename to gemfiles/rails_7.0_with_postgis.gemfile index 0f907b20..ace2ccc0 100644 --- a/gemfiles/rails_7.0.8_with_postgis.gemfile +++ b/gemfiles/rails_7.0_with_postgis.gemfile @@ -21,7 +21,7 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "pg" -gem "rails", "7.0.8" +gem "rails", "~> 7.0.0" gem "activerecord-postgis-adapter" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do diff --git a/gemfiles/rails_7.0.8_with_postgresql.gemfile b/gemfiles/rails_7.0_with_postgresql.gemfile similarity index 96% rename from gemfiles/rails_7.0.8_with_postgresql.gemfile rename to gemfiles/rails_7.0_with_postgresql.gemfile index b2202905..a6ec4659 100644 --- a/gemfiles/rails_7.0.8_with_postgresql.gemfile +++ b/gemfiles/rails_7.0_with_postgresql.gemfile @@ -21,7 +21,7 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "pg" -gem "rails", "7.0.8" +gem "rails", "~> 7.0.0" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do gem "base64" diff --git a/gemfiles/rails_7.0.8_with_sqlite3.gemfile b/gemfiles/rails_7.0_with_sqlite3.gemfile similarity index 96% rename from gemfiles/rails_7.0.8_with_sqlite3.gemfile rename to gemfiles/rails_7.0_with_sqlite3.gemfile index 1ac98dde..fe0c4ada 100644 --- a/gemfiles/rails_7.0.8_with_sqlite3.gemfile +++ b/gemfiles/rails_7.0_with_sqlite3.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.0.8" +gem "rails", "~> 7.0.0" gem "sqlite3", "~> 1.5.0" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do diff --git a/gemfiles/rails_7.0.8_with_trilogy.gemfile b/gemfiles/rails_7.0_with_trilogy.gemfile similarity index 96% rename from gemfiles/rails_7.0.8_with_trilogy.gemfile rename to gemfiles/rails_7.0_with_trilogy.gemfile index eb10fc56..fb6fe0eb 100644 --- a/gemfiles/rails_7.0.8_with_trilogy.gemfile +++ b/gemfiles/rails_7.0_with_trilogy.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.0.8" +gem "rails", "~> 7.0.0" gem "activerecord-trilogy-adapter" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do diff --git a/gemfiles/rails_7.1.0_with_mysql2.gemfile b/gemfiles/rails_7.1_with_mysql2.gemfile similarity index 95% rename from gemfiles/rails_7.1.0_with_mysql2.gemfile rename to gemfiles/rails_7.1_with_mysql2.gemfile index 00798abb..370e17e4 100644 --- a/gemfiles/rails_7.1.0_with_mysql2.gemfile +++ b/gemfiles/rails_7.1_with_mysql2.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.1.0" +gem "rails", "~> 7.1.0" gem "mysql2" gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.1_with_oracle_enhanced.gemfile similarity index 95% rename from gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile rename to gemfiles/rails_7.1_with_oracle_enhanced.gemfile index 2ce152c6..4899d072 100644 --- a/gemfiles/rails_7.1.0_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.1_with_oracle_enhanced.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.1.0" +gem "rails", "~> 7.1.0" gem "activerecord-oracle_enhanced-adapter", "~> 7.1.0" gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_postgis.gemfile b/gemfiles/rails_7.1_with_postgis.gemfile similarity index 95% rename from gemfiles/rails_7.1.0_with_postgis.gemfile rename to gemfiles/rails_7.1_with_postgis.gemfile index c7a8276c..63bfc47d 100644 --- a/gemfiles/rails_7.1.0_with_postgis.gemfile +++ b/gemfiles/rails_7.1_with_postgis.gemfile @@ -21,7 +21,7 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "pg" -gem "rails", "7.1.0" +gem "rails", "~> 7.1.0" gem "activerecord-postgis-adapter" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_postgresql.gemfile b/gemfiles/rails_7.1_with_postgresql.gemfile similarity index 95% rename from gemfiles/rails_7.2.0_with_postgresql.gemfile rename to gemfiles/rails_7.1_with_postgresql.gemfile index 1c9c96f8..0e7c95f1 100644 --- a/gemfiles/rails_7.2.0_with_postgresql.gemfile +++ b/gemfiles/rails_7.1_with_postgresql.gemfile @@ -21,6 +21,6 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "pg" -gem "rails", "7.2.0" +gem "rails", "~> 7.1.0" gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_sqlite3.gemfile b/gemfiles/rails_7.1_with_sqlite3.gemfile similarity index 95% rename from gemfiles/rails_7.1.0_with_sqlite3.gemfile rename to gemfiles/rails_7.1_with_sqlite3.gemfile index ecceebf9..949d3aa3 100644 --- a/gemfiles/rails_7.1.0_with_sqlite3.gemfile +++ b/gemfiles/rails_7.1_with_sqlite3.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.1.0" +gem "rails", "~> 7.1.0" gem "sqlite3", "~> 1.5.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_trilogy.gemfile b/gemfiles/rails_7.1_with_trilogy.gemfile similarity index 95% rename from gemfiles/rails_7.2.0_with_trilogy.gemfile rename to gemfiles/rails_7.1_with_trilogy.gemfile index 3a148a90..4b2832eb 100644 --- a/gemfiles/rails_7.2.0_with_trilogy.gemfile +++ b/gemfiles/rails_7.1_with_trilogy.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.2.0" +gem "rails", "~> 7.1.0" gem "activerecord-trilogy-adapter" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_mysql2.gemfile b/gemfiles/rails_7.2_with_mysql2.gemfile similarity index 95% rename from gemfiles/rails_7.2.0_with_mysql2.gemfile rename to gemfiles/rails_7.2_with_mysql2.gemfile index 9deebff8..f86bff3d 100644 --- a/gemfiles/rails_7.2.0_with_mysql2.gemfile +++ b/gemfiles/rails_7.2_with_mysql2.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.2.0" +gem "rails", "~> 7.2.0" gem "mysql2" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.2_with_oracle_enhanced.gemfile similarity index 95% rename from gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile rename to gemfiles/rails_7.2_with_oracle_enhanced.gemfile index ec1368b3..88d00c49 100644 --- a/gemfiles/rails_7.2.0_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.2_with_oracle_enhanced.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.2.0" +gem "rails", "~> 7.2.0" gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_postgis.gemfile b/gemfiles/rails_7.2_with_postgis.gemfile similarity index 95% rename from gemfiles/rails_7.2.0_with_postgis.gemfile rename to gemfiles/rails_7.2_with_postgis.gemfile index 81dbb10e..3868fa91 100644 --- a/gemfiles/rails_7.2.0_with_postgis.gemfile +++ b/gemfiles/rails_7.2_with_postgis.gemfile @@ -21,7 +21,7 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "pg" -gem "rails", "7.2.0" +gem "rails", "~> 7.2.0" gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_postgresql.gemfile b/gemfiles/rails_7.2_with_postgresql.gemfile similarity index 95% rename from gemfiles/rails_7.1.0_with_postgresql.gemfile rename to gemfiles/rails_7.2_with_postgresql.gemfile index 02ad0018..69e9ac7b 100644 --- a/gemfiles/rails_7.1.0_with_postgresql.gemfile +++ b/gemfiles/rails_7.2_with_postgresql.gemfile @@ -21,6 +21,6 @@ gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" gem "pg" -gem "rails", "7.1.0" +gem "rails", "~> 7.2.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2.0_with_sqlite3.gemfile b/gemfiles/rails_7.2_with_sqlite3.gemfile similarity index 95% rename from gemfiles/rails_7.2.0_with_sqlite3.gemfile rename to gemfiles/rails_7.2_with_sqlite3.gemfile index 3ba3ec0a..4642fb54 100644 --- a/gemfiles/rails_7.2.0_with_sqlite3.gemfile +++ b/gemfiles/rails_7.2_with_sqlite3.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.2.0" +gem "rails", "~> 7.2.0" gem "sqlite3", "~> 1.5.0" gemspec path: "../" diff --git a/gemfiles/rails_7.1.0_with_trilogy.gemfile b/gemfiles/rails_7.2_with_trilogy.gemfile similarity index 95% rename from gemfiles/rails_7.1.0_with_trilogy.gemfile rename to gemfiles/rails_7.2_with_trilogy.gemfile index 9ac220c8..0e8bbcc7 100644 --- a/gemfiles/rails_7.1.0_with_trilogy.gemfile +++ b/gemfiles/rails_7.2_with_trilogy.gemfile @@ -20,7 +20,7 @@ gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" gem "simplecov" -gem "rails", "7.1.0" +gem "rails", "~> 7.2.0" gem "activerecord-trilogy-adapter" gemspec path: "../" From 53e732598be9061eaad99ad34d089b2f215b7438 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 12 Nov 2024 00:21:15 +0100 Subject: [PATCH 280/290] Enable RSpec warnings --- .rspec | 1 + 1 file changed, 1 insertion(+) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..372b5acf --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--warnings From b94235bb9541102d4936d51061ac1bf2aa1b75a1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 15 Dec 2024 01:40:22 +0100 Subject: [PATCH 281/290] Improve Gemfile --- Gemfile | 17 +++++++++-------- Rakefile | 10 ---------- gemfiles/rails_7.0_with_mysql2.gemfile | 13 ++++++------- gemfiles/rails_7.0_with_oracle_enhanced.gemfile | 13 ++++++------- gemfiles/rails_7.0_with_postgis.gemfile | 13 ++++++------- gemfiles/rails_7.0_with_postgresql.gemfile | 13 ++++++------- gemfiles/rails_7.0_with_sqlite3.gemfile | 13 ++++++------- gemfiles/rails_7.0_with_trilogy.gemfile | 13 ++++++------- gemfiles/rails_7.1_with_mysql2.gemfile | 13 ++++++------- gemfiles/rails_7.1_with_oracle_enhanced.gemfile | 13 ++++++------- gemfiles/rails_7.1_with_postgis.gemfile | 13 ++++++------- gemfiles/rails_7.1_with_postgresql.gemfile | 13 ++++++------- gemfiles/rails_7.1_with_sqlite3.gemfile | 13 ++++++------- gemfiles/rails_7.1_with_trilogy.gemfile | 13 ++++++------- gemfiles/rails_7.2_with_mysql2.gemfile | 13 ++++++------- gemfiles/rails_7.2_with_oracle_enhanced.gemfile | 13 ++++++------- gemfiles/rails_7.2_with_postgis.gemfile | 13 ++++++------- gemfiles/rails_7.2_with_postgresql.gemfile | 13 ++++++------- gemfiles/rails_7.2_with_sqlite3.gemfile | 13 ++++++------- gemfiles/rails_7.2_with_trilogy.gemfile | 13 ++++++------- 20 files changed, 117 insertions(+), 144 deletions(-) diff --git a/Gemfile b/Gemfile index e37e11d1..47a46474 100644 --- a/Gemfile +++ b/Gemfile @@ -4,25 +4,26 @@ source 'https://rubygems.org' gemspec +# Dev libs gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' - gem 'combustion' gem 'database_cleaner' gem 'factory_bot' gem 'faker' gem 'generator_spec' -gem 'guard-rspec' -gem 'pry' gem 'puma' gem 'rake' gem 'rspec' gem 'rspec-retry' -gem 'rubocop' -gem 'rubocop-factory_bot' -gem 'rubocop-performance' -gem 'rubocop-rake' -gem 'rubocop-rspec' gem 'simplecov' # Fallback to pg in dev/local environment gem 'pg' + +# Dev tools / linter +gem 'guard-rspec', require: false +gem 'rubocop', require: false +gem 'rubocop-factory_bot', require: false +gem 'rubocop-performance', require: false +gem 'rubocop-rake', require: false +gem 'rubocop-rspec', require: false diff --git a/Rakefile b/Rakefile index 5de361c0..ad26ae7d 100644 --- a/Rakefile +++ b/Rakefile @@ -5,13 +5,3 @@ require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task default: :spec - -desc 'Open a Ruby irb console with the gem loaded' -task :console do - require 'pry' - require 'rails' - require 'ajax-datatables-rails' - puts 'Loaded AjaxDatatablesRails' - ARGV.clear - Pry.start -end diff --git a/gemfiles/rails_7.0_with_mysql2.gemfile b/gemfiles/rails_7.0_with_mysql2.gemfile index d3000d8f..792ae856 100644 --- a/gemfiles/rails_7.0_with_mysql2.gemfile +++ b/gemfiles/rails_7.0_with_mysql2.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.0.0" gem "mysql2" diff --git a/gemfiles/rails_7.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.0_with_oracle_enhanced.gemfile index 215fc370..b5e1c608 100644 --- a/gemfiles/rails_7.0_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.0_with_oracle_enhanced.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.0.0" gem "ruby-oci8" gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" diff --git a/gemfiles/rails_7.0_with_postgis.gemfile b/gemfiles/rails_7.0_with_postgis.gemfile index ace2ccc0..38d6553f 100644 --- a/gemfiles/rails_7.0_with_postgis.gemfile +++ b/gemfiles/rails_7.0_with_postgis.gemfile @@ -8,19 +8,18 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.0.0" gem "activerecord-postgis-adapter" diff --git a/gemfiles/rails_7.0_with_postgresql.gemfile b/gemfiles/rails_7.0_with_postgresql.gemfile index a6ec4659..35a89b6c 100644 --- a/gemfiles/rails_7.0_with_postgresql.gemfile +++ b/gemfiles/rails_7.0_with_postgresql.gemfile @@ -8,19 +8,18 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.0.0" install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do diff --git a/gemfiles/rails_7.0_with_sqlite3.gemfile b/gemfiles/rails_7.0_with_sqlite3.gemfile index fe0c4ada..832b0487 100644 --- a/gemfiles/rails_7.0_with_sqlite3.gemfile +++ b/gemfiles/rails_7.0_with_sqlite3.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.0.0" gem "sqlite3", "~> 1.5.0" diff --git a/gemfiles/rails_7.0_with_trilogy.gemfile b/gemfiles/rails_7.0_with_trilogy.gemfile index fb6fe0eb..65364f2e 100644 --- a/gemfiles/rails_7.0_with_trilogy.gemfile +++ b/gemfiles/rails_7.0_with_trilogy.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.0.0" gem "activerecord-trilogy-adapter" diff --git a/gemfiles/rails_7.1_with_mysql2.gemfile b/gemfiles/rails_7.1_with_mysql2.gemfile index 370e17e4..8be9ba3b 100644 --- a/gemfiles/rails_7.1_with_mysql2.gemfile +++ b/gemfiles/rails_7.1_with_mysql2.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" gem "mysql2" diff --git a/gemfiles/rails_7.1_with_oracle_enhanced.gemfile b/gemfiles/rails_7.1_with_oracle_enhanced.gemfile index 4899d072..01410313 100644 --- a/gemfiles/rails_7.1_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.1_with_oracle_enhanced.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" gem "activerecord-oracle_enhanced-adapter", "~> 7.1.0" diff --git a/gemfiles/rails_7.1_with_postgis.gemfile b/gemfiles/rails_7.1_with_postgis.gemfile index 63bfc47d..ffaad7df 100644 --- a/gemfiles/rails_7.1_with_postgis.gemfile +++ b/gemfiles/rails_7.1_with_postgis.gemfile @@ -8,19 +8,18 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" gem "activerecord-postgis-adapter" diff --git a/gemfiles/rails_7.1_with_postgresql.gemfile b/gemfiles/rails_7.1_with_postgresql.gemfile index 0e7c95f1..042ce7ac 100644 --- a/gemfiles/rails_7.1_with_postgresql.gemfile +++ b/gemfiles/rails_7.1_with_postgresql.gemfile @@ -8,19 +8,18 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" gemspec path: "../" diff --git a/gemfiles/rails_7.1_with_sqlite3.gemfile b/gemfiles/rails_7.1_with_sqlite3.gemfile index 949d3aa3..d23c1582 100644 --- a/gemfiles/rails_7.1_with_sqlite3.gemfile +++ b/gemfiles/rails_7.1_with_sqlite3.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" gem "sqlite3", "~> 1.5.0" diff --git a/gemfiles/rails_7.1_with_trilogy.gemfile b/gemfiles/rails_7.1_with_trilogy.gemfile index 4b2832eb..2500f361 100644 --- a/gemfiles/rails_7.1_with_trilogy.gemfile +++ b/gemfiles/rails_7.1_with_trilogy.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" gem "activerecord-trilogy-adapter" diff --git a/gemfiles/rails_7.2_with_mysql2.gemfile b/gemfiles/rails_7.2_with_mysql2.gemfile index f86bff3d..3d8cc0ed 100644 --- a/gemfiles/rails_7.2_with_mysql2.gemfile +++ b/gemfiles/rails_7.2_with_mysql2.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.2.0" gem "mysql2" diff --git a/gemfiles/rails_7.2_with_oracle_enhanced.gemfile b/gemfiles/rails_7.2_with_oracle_enhanced.gemfile index 88d00c49..17280e0e 100644 --- a/gemfiles/rails_7.2_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_7.2_with_oracle_enhanced.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.2.0" gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" diff --git a/gemfiles/rails_7.2_with_postgis.gemfile b/gemfiles/rails_7.2_with_postgis.gemfile index 3868fa91..7f0a4e17 100644 --- a/gemfiles/rails_7.2_with_postgis.gemfile +++ b/gemfiles/rails_7.2_with_postgis.gemfile @@ -8,19 +8,18 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.2.0" gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" diff --git a/gemfiles/rails_7.2_with_postgresql.gemfile b/gemfiles/rails_7.2_with_postgresql.gemfile index 69e9ac7b..ee0c0c1a 100644 --- a/gemfiles/rails_7.2_with_postgresql.gemfile +++ b/gemfiles/rails_7.2_with_postgresql.gemfile @@ -8,19 +8,18 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.2.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2_with_sqlite3.gemfile b/gemfiles/rails_7.2_with_sqlite3.gemfile index 4642fb54..8ce650f8 100644 --- a/gemfiles/rails_7.2_with_sqlite3.gemfile +++ b/gemfiles/rails_7.2_with_sqlite3.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.2.0" gem "sqlite3", "~> 1.5.0" diff --git a/gemfiles/rails_7.2_with_trilogy.gemfile b/gemfiles/rails_7.2_with_trilogy.gemfile index 0e8bbcc7..fcdf669e 100644 --- a/gemfiles/rails_7.2_with_trilogy.gemfile +++ b/gemfiles/rails_7.2_with_trilogy.gemfile @@ -8,18 +8,17 @@ gem "database_cleaner" gem "factory_bot" gem "faker" gem "generator_spec" -gem "guard-rspec" -gem "pry" gem "puma" gem "rake" gem "rspec" gem "rspec-retry" -gem "rubocop" -gem "rubocop-factory_bot" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "rails", "~> 7.2.0" gem "activerecord-trilogy-adapter" From cea41cfdc1b51e2a346f765fea9607f49b879b74 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 15 Dec 2024 01:43:28 +0100 Subject: [PATCH 282/290] Add support for Rails 8.0 --- .github/workflows/ci.yml | 10 ++++- Appraisals | 39 +++++++++++++++++++ gemfiles/rails_8.0_with_mysql2.gemfile | 25 ++++++++++++ .../rails_8.0_with_oracle_enhanced.gemfile | 25 ++++++++++++ gemfiles/rails_8.0_with_postgis.gemfile | 26 +++++++++++++ gemfiles/rails_8.0_with_postgresql.gemfile | 25 ++++++++++++ gemfiles/rails_8.0_with_sqlite3.gemfile | 25 ++++++++++++ gemfiles/rails_8.0_with_trilogy.gemfile | 25 ++++++++++++ 8 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 gemfiles/rails_8.0_with_mysql2.gemfile create mode 100644 gemfiles/rails_8.0_with_oracle_enhanced.gemfile create mode 100644 gemfiles/rails_8.0_with_postgis.gemfile create mode 100644 gemfiles/rails_8.0_with_postgresql.gemfile create mode 100644 gemfiles/rails_8.0_with_sqlite3.gemfile create mode 100644 gemfiles/rails_8.0_with_trilogy.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f82f61e3..19c0e240 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,7 @@ jobs: - '3.0' - 'head' rails: + - rails_8.0 - rails_7.2 - rails_7.1 - rails_7.0 @@ -93,9 +94,16 @@ jobs: # - trilogy exclude: # Rails 7.2 needs Ruby > 3.1 - - rails: rails_7.2 + - rails: 'rails_7.2' + ruby: '3.0' + + # Rails 8.0 needs Ruby > 3.2 + - rails: 'rails_8.0' ruby: '3.0' + - rails: 'rails_8.0' + ruby: '3.1' + # Disabled for now because of build error: # /opt/hostedtoolcache/Ruby/3.0.7/x64/lib/ruby/3.0.0/psych.rb:457:in # `parse_stream': undefined method `parse' for # 8.0.0' + gem 'pg' +end + +appraise 'rails_8.0_with_sqlite3' do + gem 'rails', '~> 8.0.0' + gem 'sqlite3' + remove_gem 'pg' +end + +appraise 'rails_8.0_with_mysql2' do + gem 'rails', '~> 8.0.0' + gem 'mysql2' + remove_gem 'pg' +end + +appraise 'rails_8.0_with_trilogy' do + gem 'rails', '~> 8.0.0' + gem 'activerecord-trilogy-adapter' + remove_gem 'pg' +end + +appraise 'rails_8.0_with_oracle_enhanced' do + gem 'rails', '~> 8.0.0' + gem 'activerecord-oracle_enhanced-adapter', git: 'https://github.com/rsim/oracle-enhanced.git' + remove_gem 'pg' +end + +appraise 'rails_8.0_with_postgis' do + gem 'rails', '~> 8.0.0' + gem 'pg' + gem 'activerecord-postgis-adapter', git: 'https://github.com/rgeo/activerecord-postgis-adapter.git' +end diff --git a/gemfiles/rails_8.0_with_mysql2.gemfile b/gemfiles/rails_8.0_with_mysql2.gemfile new file mode 100644 index 00000000..023c71d8 --- /dev/null +++ b/gemfiles/rails_8.0_with_mysql2.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false +gem "rails", "~> 8.0.0" +gem "mysql2" + +gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_oracle_enhanced.gemfile b/gemfiles/rails_8.0_with_oracle_enhanced.gemfile new file mode 100644 index 00000000..563ac16c --- /dev/null +++ b/gemfiles/rails_8.0_with_oracle_enhanced.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false +gem "rails", "~> 8.0.0" +gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" + +gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_postgis.gemfile b/gemfiles/rails_8.0_with_postgis.gemfile new file mode 100644 index 00000000..c2498b58 --- /dev/null +++ b/gemfiles/rails_8.0_with_postgis.gemfile @@ -0,0 +1,26 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "simplecov" +gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false +gem "rails", "~> 8.0.0" +gem "activerecord-postgis-adapter", git: "https://github.com/rgeo/activerecord-postgis-adapter.git" + +gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_postgresql.gemfile b/gemfiles/rails_8.0_with_postgresql.gemfile new file mode 100644 index 00000000..164f2e09 --- /dev/null +++ b/gemfiles/rails_8.0_with_postgresql.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "simplecov" +gem "pg" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false +gem "rails", "~> 8.0.0" + +gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_sqlite3.gemfile b/gemfiles/rails_8.0_with_sqlite3.gemfile new file mode 100644 index 00000000..62bfdd83 --- /dev/null +++ b/gemfiles/rails_8.0_with_sqlite3.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false +gem "rails", "~> 8.0.0" +gem "sqlite3" + +gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_trilogy.gemfile b/gemfiles/rails_8.0_with_trilogy.gemfile new file mode 100644 index 00000000..f80123d1 --- /dev/null +++ b/gemfiles/rails_8.0_with_trilogy.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "combustion" +gem "database_cleaner" +gem "factory_bot" +gem "faker" +gem "generator_spec" +gem "puma" +gem "rake" +gem "rspec" +gem "rspec-retry" +gem "simplecov" +gem "guard-rspec", require: false +gem "rubocop", require: false +gem "rubocop-factory_bot", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false +gem "rails", "~> 8.0.0" +gem "activerecord-trilogy-adapter" + +gemspec path: "../" From 9d91a5c549f39d6935b30336c6a9c310ab2fd73b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 15 Dec 2024 01:58:38 +0100 Subject: [PATCH 283/290] Run Rubocop with Ruby 3.0 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19c0e240..30deca63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' + ruby-version: '3.0' - name: Bundler run: bundle install From dc123b56d8a1fc94fb78096676a2a6a92f8a5116 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 15 Dec 2024 01:59:58 +0100 Subject: [PATCH 284/290] Test with Ruby 3.4 (rc1) --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30deca63..ca6d8402 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,7 @@ jobs: fail-fast: false matrix: ruby: + - '3.4' - '3.3' - '3.2' - '3.1' From 3c74e8ac22204973b82c7056a43ade3a6099e926 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 15 Dec 2024 02:01:14 +0100 Subject: [PATCH 285/290] Update bundler binstubs --- bin/_guard-core | 8 +++----- bin/appraisal | 8 +++----- bin/bundle | 29 ++++++++++++----------------- bin/guard | 8 +++----- bin/rackup | 4 ++-- bin/rake | 8 +++----- bin/rspec | 8 +++----- bin/rubocop | 8 +++----- 8 files changed, 32 insertions(+), 49 deletions(-) diff --git a/bin/_guard-core b/bin/_guard-core index cd565c3a..9105b28b 100755 --- a/bin/_guard-core +++ b/bin/_guard-core @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/appraisal b/bin/appraisal index 0e7ba65d..5038ce52 100755 --- a/bin/appraisal +++ b/bin/appraisal @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/bundle b/bin/bundle index a71368e3..50da5fdf 100755 --- a/bin/bundle +++ b/bin/bundle @@ -27,7 +27,7 @@ m = Module.new do bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| - if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ @@ -41,13 +41,13 @@ m = Module.new do gemfile = ENV["BUNDLE_GEMFILE"] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../../Gemfile", __FILE__) + File.expand_path("../Gemfile", __dir__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -60,24 +60,19 @@ m = Module.new do Regexp.last_match(1) end - def bundler_version - @bundler_version ||= - env_var_version || cli_arg_version || - lockfile_version - end - def bundler_requirement - return "#{Gem::Requirement.default}.a" unless bundler_version - - bundler_gem_version = Gem::Version.new(bundler_version) - - requirement = bundler_gem_version.approximate_recommendation + @bundler_requirement ||= + env_var_version || + cli_arg_version || + bundler_requirement_for(lockfile_version) + end - return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version - requirement += ".a" if bundler_gem_version.prerelease? + bundler_gem_version = Gem::Version.new(version) - requirement + bundler_gem_version.approximate_recommendation end def load_bundler! diff --git a/bin/guard b/bin/guard index bcb966f4..ff444e0c 100755 --- a/bin/guard +++ b/bin/guard @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/rackup b/bin/rackup index 7023745e..6408c791 100755 --- a/bin/rackup +++ b/bin/rackup @@ -13,7 +13,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. @@ -24,4 +24,4 @@ end require "rubygems" require "bundler/setup" -load Gem.bin_path("rack", "rackup") +load Gem.bin_path("rackup", "rackup") diff --git a/bin/rake b/bin/rake index 9275675e..4eb7d7bf 100755 --- a/bin/rake +++ b/bin/rake @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/rspec b/bin/rspec index a6c78521..cb53ebe5 100755 --- a/bin/rspec +++ b/bin/rspec @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. diff --git a/bin/rubocop b/bin/rubocop index d0c48829..369a05be 100755 --- a/bin/rubocop +++ b/bin/rubocop @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. From 641628761b4fdb31b37723e750899abf753922f4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 28 Jan 2025 23:36:34 +0100 Subject: [PATCH 286/290] Trigger CI jobs manually --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca6d8402..f6e9901b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ on: - '**' schedule: - cron: '0 4 1 * *' + # Run workflow manually + workflow_dispatch: jobs: rubocop: From 16aacc693b6e542b09a24fc4ca77c8b6c072fa81 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 29 Jan 2025 01:42:04 +0100 Subject: [PATCH 287/290] Update CHANGELOG --- CHANGELOG.md | 17 +++++++++++++++-- README.md | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca0e88a4..9d03e7bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,28 @@ # CHANGELOG +## 1.6.0 (2025-??-??) + +* Remove dead code * Implementing `searchable: false` tests +* Improve objects shape +* Fix Rubocop offenses +* Make gem smaller +* Drop support of Rails 6.0 +* Drop support of Rails 6.1 +* Drop support of Ruby 2.7 +* Add support for Rails 7.2 +* Add support for Rails 8.0 +* Add support for Ruby 3.4 ## 1.5.0 (2024-04-08) -* Drop support of Rails 5.2 * Add support for grouped results (merge: [#419](https://github.com/jbox-web/ajax-datatables-rails/pull/419)) * Fix server-side out of order ajax responses (merge: [#418](https://github.com/jbox-web/ajax-datatables-rails/pull/418)) * Add support for postgis adapter (merge: [#417](https://github.com/jbox-web/ajax-datatables-rails/pull/417)) * Add support for trilogy adapter (merge: [#423](https://github.com/jbox-web/ajax-datatables-rails/pull/423)) +* Drop support of Rails 5.2 * Add support for Rails 7.1 +* Add support for Ruby 3.2 * Add support for Ruby 3.3 This is the last version to support Rails 6.0.x and Ruby 2.7.x. @@ -21,7 +34,7 @@ This is the last version to support Rails 6.0.x and Ruby 2.7.x. * Drop support of Ruby 2.5 * Drop support of Ruby 2.6 * Add support of Ruby 3.1 -* Add support of Rails 7 +* Add support of Rails 7.0 * Fix: prevent establishing ActiveRecord connection on startup ## 1.3.1 (2021-02-09) diff --git a/README.md b/README.md index 0cef164d..85b89318 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ It's tested against : -* Rails: 7.0.4 / 7.1.0 / 7.2.0 -* Ruby: 3.0 / 3.1 / 3.2 / 3.3 +* Rails: 7.0 / 7.1 / 7.2 / 8.0 +* Ruby: 3.0 / 3.1 / 3.2 / 3.3 / 3.4 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle From 6f6d2f0b46a068cfe4051c53d0b7fc688c8d715b Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 29 Jan 2025 01:46:09 +0100 Subject: [PATCH 288/290] Drop support for Rails 7.0 --- .github/workflows/ci.yml | 1 - Appraisals | 118 ------------------ CHANGELOG.md | 1 + README.md | 2 +- ajax-datatables-rails.gemspec | 2 +- gemfiles/rails_7.0_with_mysql2.gemfile | 35 ------ .../rails_7.0_with_oracle_enhanced.gemfile | 36 ------ gemfiles/rails_7.0_with_postgis.gemfile | 36 ------ gemfiles/rails_7.0_with_postgresql.gemfile | 35 ------ gemfiles/rails_7.0_with_sqlite3.gemfile | 35 ------ gemfiles/rails_7.0_with_trilogy.gemfile | 35 ------ 11 files changed, 3 insertions(+), 333 deletions(-) delete mode 100644 gemfiles/rails_7.0_with_mysql2.gemfile delete mode 100644 gemfiles/rails_7.0_with_oracle_enhanced.gemfile delete mode 100644 gemfiles/rails_7.0_with_postgis.gemfile delete mode 100644 gemfiles/rails_7.0_with_postgresql.gemfile delete mode 100644 gemfiles/rails_7.0_with_sqlite3.gemfile delete mode 100644 gemfiles/rails_7.0_with_trilogy.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6e9901b..cabe9823 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,6 @@ jobs: - rails_8.0 - rails_7.2 - rails_7.1 - - rails_7.0 adapter: - sqlite3 - postgresql diff --git a/Appraisals b/Appraisals index f53cd173..dc6bea81 100644 --- a/Appraisals +++ b/Appraisals @@ -1,123 +1,5 @@ # frozen_string_literal: true -############### -# RAILS 7.0 # -############### - -appraise 'rails_7.0_with_postgresql' do - gem 'rails', '~> 7.0.0' - gem 'pg' - - # Fix: - # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 - # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do - gem 'base64' - gem 'bigdecimal' - gem 'benchmark' - gem 'drb' - gem 'logger' - gem 'mutex_m' - gem 'ostruct' - end -end - -appraise 'rails_7.0_with_sqlite3' do - gem 'rails', '~> 7.0.0' - gem 'sqlite3', '~> 1.5.0' - remove_gem 'pg' - - # Fix: - # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 - # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do - gem 'base64' - gem 'bigdecimal' - gem 'benchmark' - gem 'drb' - gem 'logger' - gem 'mutex_m' - gem 'ostruct' - end -end - -appraise 'rails_7.0_with_mysql2' do - gem 'rails', '~> 7.0.0' - gem 'mysql2' - remove_gem 'pg' - - # Fix: - # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 - # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do - gem 'base64' - gem 'bigdecimal' - gem 'benchmark' - gem 'drb' - gem 'logger' - gem 'mutex_m' - gem 'ostruct' - end -end - -appraise 'rails_7.0_with_trilogy' do - gem 'rails', '~> 7.0.0' - gem 'activerecord-trilogy-adapter' - remove_gem 'pg' - - # Fix: - # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 - # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do - gem 'base64' - gem 'bigdecimal' - gem 'benchmark' - gem 'drb' - gem 'logger' - gem 'mutex_m' - gem 'ostruct' - end -end - -appraise 'rails_7.0_with_oracle_enhanced' do - gem 'rails', '~> 7.0.0' - gem 'ruby-oci8' - gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' - remove_gem 'pg' - - # Fix: - # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 - # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do - gem 'base64' - gem 'bigdecimal' - gem 'benchmark' - gem 'drb' - gem 'logger' - gem 'mutex_m' - gem 'ostruct' - end -end - -appraise 'rails_7.0_with_postgis' do - gem 'rails', '~> 7.0.0' - gem 'pg' - gem 'activerecord-postgis-adapter' - - # Fix: - # warning: logger was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0 - # Add logger to your Gemfile or gemspec. - install_if '-> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") }' do - gem 'base64' - gem 'bigdecimal' - gem 'benchmark' - gem 'drb' - gem 'logger' - gem 'mutex_m' - gem 'ostruct' - end -end - ############### # RAILS 7.1.0 # ############### diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d03e7bd..7718eccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Make gem smaller * Drop support of Rails 6.0 * Drop support of Rails 6.1 +* Drop support of Rails 7.0 * Drop support of Ruby 2.7 * Add support for Rails 7.2 * Add support for Rails 8.0 diff --git a/README.md b/README.md index 85b89318..33c67a1f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It's tested against : -* Rails: 7.0 / 7.1 / 7.2 / 8.0 +* Rails: 7.1 / 7.2 / 8.0 * Ruby: 3.0 / 3.1 / 3.2 / 3.3 / 3.4 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 6bf0f390..42bf915e 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -24,6 +24,6 @@ Gem::Specification.new do |s| s.files = Dir['README.md', 'CHANGELOG.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/*.erb'] - s.add_dependency 'rails', '>= 7.0' + s.add_dependency 'rails', '>= 7.1' s.add_dependency 'zeitwerk' end diff --git a/gemfiles/rails_7.0_with_mysql2.gemfile b/gemfiles/rails_7.0_with_mysql2.gemfile deleted file mode 100644 index 792ae856..00000000 --- a/gemfiles/rails_7.0_with_mysql2.gemfile +++ /dev/null @@ -1,35 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "simplecov" -gem "guard-rspec", require: false -gem "rubocop", require: false -gem "rubocop-factory_bot", require: false -gem "rubocop-performance", require: false -gem "rubocop-rake", require: false -gem "rubocop-rspec", require: false -gem "rails", "~> 7.0.0" -gem "mysql2" - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "benchmark" - gem "drb" - gem "logger" - gem "mutex_m" - gem "ostruct" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0_with_oracle_enhanced.gemfile b/gemfiles/rails_7.0_with_oracle_enhanced.gemfile deleted file mode 100644 index b5e1c608..00000000 --- a/gemfiles/rails_7.0_with_oracle_enhanced.gemfile +++ /dev/null @@ -1,36 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "simplecov" -gem "guard-rspec", require: false -gem "rubocop", require: false -gem "rubocop-factory_bot", require: false -gem "rubocop-performance", require: false -gem "rubocop-rake", require: false -gem "rubocop-rspec", require: false -gem "rails", "~> 7.0.0" -gem "ruby-oci8" -gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "benchmark" - gem "drb" - gem "logger" - gem "mutex_m" - gem "ostruct" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0_with_postgis.gemfile b/gemfiles/rails_7.0_with_postgis.gemfile deleted file mode 100644 index 38d6553f..00000000 --- a/gemfiles/rails_7.0_with_postgis.gemfile +++ /dev/null @@ -1,36 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "simplecov" -gem "pg" -gem "guard-rspec", require: false -gem "rubocop", require: false -gem "rubocop-factory_bot", require: false -gem "rubocop-performance", require: false -gem "rubocop-rake", require: false -gem "rubocop-rspec", require: false -gem "rails", "~> 7.0.0" -gem "activerecord-postgis-adapter" - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "benchmark" - gem "drb" - gem "logger" - gem "mutex_m" - gem "ostruct" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0_with_postgresql.gemfile b/gemfiles/rails_7.0_with_postgresql.gemfile deleted file mode 100644 index 35a89b6c..00000000 --- a/gemfiles/rails_7.0_with_postgresql.gemfile +++ /dev/null @@ -1,35 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "simplecov" -gem "pg" -gem "guard-rspec", require: false -gem "rubocop", require: false -gem "rubocop-factory_bot", require: false -gem "rubocop-performance", require: false -gem "rubocop-rake", require: false -gem "rubocop-rspec", require: false -gem "rails", "~> 7.0.0" - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "benchmark" - gem "drb" - gem "logger" - gem "mutex_m" - gem "ostruct" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0_with_sqlite3.gemfile b/gemfiles/rails_7.0_with_sqlite3.gemfile deleted file mode 100644 index 832b0487..00000000 --- a/gemfiles/rails_7.0_with_sqlite3.gemfile +++ /dev/null @@ -1,35 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "simplecov" -gem "guard-rspec", require: false -gem "rubocop", require: false -gem "rubocop-factory_bot", require: false -gem "rubocop-performance", require: false -gem "rubocop-rake", require: false -gem "rubocop-rspec", require: false -gem "rails", "~> 7.0.0" -gem "sqlite3", "~> 1.5.0" - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "benchmark" - gem "drb" - gem "logger" - gem "mutex_m" - gem "ostruct" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0_with_trilogy.gemfile b/gemfiles/rails_7.0_with_trilogy.gemfile deleted file mode 100644 index 65364f2e..00000000 --- a/gemfiles/rails_7.0_with_trilogy.gemfile +++ /dev/null @@ -1,35 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" -gem "combustion" -gem "database_cleaner" -gem "factory_bot" -gem "faker" -gem "generator_spec" -gem "puma" -gem "rake" -gem "rspec" -gem "rspec-retry" -gem "simplecov" -gem "guard-rspec", require: false -gem "rubocop", require: false -gem "rubocop-factory_bot", require: false -gem "rubocop-performance", require: false -gem "rubocop-rake", require: false -gem "rubocop-rspec", require: false -gem "rails", "~> 7.0.0" -gem "activerecord-trilogy-adapter" - -install_if -> { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") } do - gem "base64" - gem "bigdecimal" - gem "benchmark" - gem "drb" - gem "logger" - gem "mutex_m" - gem "ostruct" -end - -gemspec path: "../" From 3f3d2f488f7c98d8e179fa0699994977515efc8f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 29 Jan 2025 01:50:56 +0100 Subject: [PATCH 289/290] Drop support of Ruby 3.0 --- .github/workflows/ci.yml | 14 +++----------- .rubocop.yml | 2 +- CHANGELOG.md | 1 + README.md | 2 +- ajax-datatables-rails.gemspec | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cabe9823..1b22f5e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.0' + ruby-version: '3.1' - name: Bundler run: bundle install @@ -77,7 +77,6 @@ jobs: - '3.3' - '3.2' - '3.1' - - '3.0' - 'head' rails: - rails_8.0 @@ -95,14 +94,7 @@ jobs: # Rails 7.2: NotImplementedError # - trilogy exclude: - # Rails 7.2 needs Ruby > 3.1 - - rails: 'rails_7.2' - ruby: '3.0' - # Rails 8.0 needs Ruby > 3.2 - - rails: 'rails_8.0' - ruby: '3.0' - - rails: 'rails_8.0' ruby: '3.1' @@ -117,8 +109,8 @@ jobs: # from # /home/runner/work/ajax-datatables-rails/ajax-datatables-rails/vendor/bundle/ruby/3.0.0/gems/ruby-oci8-2.2.14/ext/oci8/apiwrap.rb:64:in # `create_apiwrap' - - rails: rails_7.2 - adapter: oracle_enhanced + - rails: 'rails_7.2' + adapter: 'oracle_enhanced' steps: - name: Checkout diff --git a/.rubocop.yml b/.rubocop.yml index 912f20f5..3f8009ae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,7 @@ require: AllCops: NewCops: enable - TargetRubyVersion: 3.0 + TargetRubyVersion: 3.1 Exclude: - bin/* - gemfiles/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 7718eccd..10407924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Drop support of Rails 6.1 * Drop support of Rails 7.0 * Drop support of Ruby 2.7 +* Drop support of Ruby 3.0 * Add support for Rails 7.2 * Add support for Rails 8.0 * Add support for Ruby 3.4 diff --git a/README.md b/README.md index 33c67a1f..62fd2b29 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It's tested against : * Rails: 7.1 / 7.2 / 8.0 -* Ruby: 3.0 / 3.1 / 3.2 / 3.3 / 3.4 +* Ruby: 3.1 / 3.2 / 3.3 / 3.4 * Databases: MySQL 8 / SQLite3 / Postgresql 16 / Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) * Adapters: sqlite / mysql2 / trilogy / postgres / postgis / oracle diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 42bf915e..69e22ea8 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| 'rubygems_mfa_required' => 'true', } - s.required_ruby_version = '>= 3.0.0' + s.required_ruby_version = '>= 3.1.0' s.files = Dir['README.md', 'CHANGELOG.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/*.erb'] From dd2dad5426f93cdda51017f4fc880d0181df5cbe Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 29 Jan 2025 01:51:16 +0100 Subject: [PATCH 290/290] Fix Rubocop offenses --- spec/spec_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eb3641d7..86ed53d9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -73,11 +73,11 @@ def self.oracle? end def self.mysql? - ENV['DB_ADAPTER'] == 'mysql2' || ENV['DB_ADAPTER'] == 'trilogy' + %w[mysql2 trilogy].include?(ENV.fetch('DB_ADAPTER', nil)) end def self.postgresql? - ENV['DB_ADAPTER'] == 'postgresql' || ENV['DB_ADAPTER'] == 'postgis' + %w[postgresql postgis].include?(ENV.fetch('DB_ADAPTER', nil)) end end