From acf0a1755c255f5db831cf5f95f7ec43f5fedb86 Mon Sep 17 00:00:00 2001 From: Mehmet Emin INAC Date: Thu, 3 Aug 2017 12:08:57 +0200 Subject: [PATCH 001/364] Rename `additional_datas` method as `additional_data`. Data is already plural and singular form of it is +datum+ therefore naming a method as `additional_datas` is wrong. This commit renames the method without breaking change but with deprecating the old one. --- README.md | 6 +++--- lib/ajax-datatables-rails/base.rb | 21 +++++++++++++++++++-- spec/ajax-datatables-rails/base_spec.rb | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 08068fcf..363ea368 100644 --- a/README.md +++ b/README.md @@ -353,12 +353,12 @@ end ``` -#### Additional datas +#### Additional data -You can inject other key/value pairs in the rendered JSON by defining the `#additional_datas` method : +You can inject other key/value pairs in the rendered JSON by defining the `#additional_data` method : ```ruby -def additional_datas +def additional_data { foo: 'bar' } diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 6869ab53..6c874140 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -33,7 +33,7 @@ def data fail(NotImplementedError, data_error_text) end - def additional_datas + def additional_data {} end @@ -42,7 +42,7 @@ def as_json(*) recordsTotal: records_total_count, recordsFiltered: records_filtered_count, data: sanitize(data) - }.merge(additional_datas) + }.merge(get_additional_data) end def records @@ -72,6 +72,23 @@ 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 <<-eos + `additional_datas` has been deprecated and + will be removed in next major version update! + Please use `additional_data` instead. + eos + + additional_datas + else + additional_data + end + end + def sanitize(data) data.map do |record| if record.is_a?(Array) diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 39e5a738..5e6c2e15 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -98,10 +98,10 @@ expect(data[:data].size).to eq 5 end - context 'with additional_datas' do + context 'with additional_data' do it 'should return a hash' do create_list(:user, 5) - expect(datatable).to receive(:additional_datas){ { 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 From c5fd2dae77e405d825f229d48dacc5d7ed20f308 Mon Sep 17 00:00:00 2001 From: Michael J Date: Sun, 27 Aug 2017 22:45:15 -0700 Subject: [PATCH 002/364] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08068fcf..e2e37c03 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ end __Some comments for the above code:__ 1. In the `get_raw_records` method we have quite a complex query having one to -many and may to many associations using the joins ActiveRecord method. +many and many to many associations using the joins ActiveRecord method. The joins will generate INNER JOIN relations in the SQL query. In this case, we do not include all event in the report if we have events which is not associated with any model record from the relation. From 428a0a86f049bbcb1dee8cacd2862b02b4aa17a8 Mon Sep 17 00:00:00 2001 From: Johannes Leers Date: Fri, 3 Nov 2017 10:33:26 +0100 Subject: [PATCH 003/364] Added timezone support for daterange --- lib/ajax-datatables-rails/datatable/column_date_filter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column_date_filter.rb b/lib/ajax-datatables-rails/datatable/column_date_filter.rb index df2b659e..f0e54775 100644 --- a/lib/ajax-datatables-rails/datatable/column_date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column_date_filter.rb @@ -21,8 +21,8 @@ def range_end # Do a range search def date_range_search return nil if empty_range_search? - new_start = range_start.blank? ? DateTime.parse('01/01/1970') : DateTime.parse(range_start) - new_end = range_end.blank? ? DateTime.current : DateTime.parse("#{range_end} 23:59:59") + new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") table[field].between(OpenStruct.new(begin: new_start, end: new_end)) end From 65aa589b238999f23c0f3ba1de1f71f067ec04a6 Mon Sep 17 00:00:00 2001 From: Johannes Leers Date: Fri, 3 Nov 2017 11:19:42 +0100 Subject: [PATCH 004/364] Added timezone support for daterange --- .../datatable/column_date_filter.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column_date_filter.rb b/lib/ajax-datatables-rails/datatable/column_date_filter.rb index f0e54775..78a31fe3 100644 --- a/lib/ajax-datatables-rails/datatable/column_date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column_date_filter.rb @@ -21,8 +21,14 @@ def range_end # Do a range search def date_range_search return nil if empty_range_search? - new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) - new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") + + if Time.zone + new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") + else + new_start = range_start.blank? ? DateTime.parse('01/01/1970') : DateTime.parse(range_start) + new_end = range_end.blank? ? DateTime.current : DateTime.parse("#{range_end} 23:59:59") + end table[field].between(OpenStruct.new(begin: new_start, end: new_end)) end From f346a7df496e906501e9c6f47c1b42692a621917 Mon Sep 17 00:00:00 2001 From: Makoto Furuya <> Date: Fri, 3 Nov 2017 15:43:38 -0700 Subject: [PATCH 005/364] Updating README to add examples for view helpers --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e2e37c03..2288328f 100644 --- a/README.md +++ b/README.md @@ -545,7 +545,7 @@ a file inside the `config/initializers` directory. #### Using view helpers Sometimes you'll need to use view helper methods like `link_to`, `h`, `mailto`, -`edit_resource_path` in the returned JSON representation returned by the `data` +`edit_resource_path`, `check_box_tag` in the returned JSON representation returned by the `data` method. To have these methods available to be used, this is the way to go: @@ -558,15 +558,21 @@ class MyCustomDatatable < AjaxDatatablesRails::Base def_delegator :@view, :mail_to # or define them in one pass - def_delegators :@view, :link_to, :h, :mailto, :edit_resource_path, :other_method + def_delegators :@view, :link_to, :h, :mailto, :edit_resource_path, :check_box_tag, :other_method + + # Define columns as described above for `id`, `first_name`, `email`, and others + def view_columns + ... + end # now, you'll have these methods available to be used anywhere # example: mapping the 2d jsonified array returned. def data records.map do |record| { + id: check_box_tag('users[]', record.id), first_name: link_to(record.fname, edit_resource_path(record)), - email: mail_to(record.email), + email: mail_to(record.email) # other attributes } end @@ -574,6 +580,24 @@ class MyCustomDatatable < AjaxDatatablesRails::Base 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. + +```ruby +... + def data + records.map do |record| + { + id: record.decorate.id, + first_name: record.decorate.first_name, + email: record.decorate.email + # other attributes + } + end + end +... +``` + #### Options From 1526ae4b42db906ce2a334409d3bc69026f0d5ff Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 9 Nov 2017 16:54:34 +0100 Subject: [PATCH 006/364] Update travis-oracle version --- spec/install_oracle.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/install_oracle.sh b/spec/install_oracle.sh index ce02313c..cec3ac49 100755 --- a/spec/install_oracle.sh +++ b/spec/install_oracle.sh @@ -1,8 +1,8 @@ #!/bin/bash -wget 'https://github.com/cbandy/travis-oracle/archive/v2.0.2.tar.gz' +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.2.tar.gz +tar xz --strip-components 1 -C ~/.travis/oracle -f v2.0.3.tar.gz ~/.travis/oracle/download.sh ~/.travis/oracle/install.sh From 24408f0c5f22ef358f55ececd1f2ec1b43365679 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 9 Nov 2017 16:57:16 +0100 Subject: [PATCH 007/364] Test with latest Ruby versions --- .travis.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 05056a71..fb1ea8ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: ruby sudo: required cache: bundler rvm: - - 2.2.7 - - 2.3.4 + - 2.2.8 + - 2.3.5 gemfile: - gemfiles/rails_4.0.13.gemfile - gemfiles/rails_4.1.15.gemfile @@ -13,31 +13,31 @@ gemfile: - gemfiles/rails_5.1.2.gemfile matrix: include: - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_4.2.9.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_5.0.4.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_5.1.2.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_4.2.9.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_5.0.4.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_5.1.2.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_4.2.9.gemfile env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_5.0.4.gemfile env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.1 + - rvm: 2.4.2 gemfile: gemfiles/rails_5.1.2.gemfile env: DB_ADAPTER=oracle_enhanced after_success: From 789eff86e17bddb60664ec93c1162730935b6c6a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 9 Nov 2017 17:16:55 +0100 Subject: [PATCH 008/364] Test with latest Rails versions --- .travis.yml | 26 +++++++++---------- Appraisals | 8 +++--- ...ls_4.1.15.gemfile => rails_4.1.16.gemfile} | 2 +- ...ils_4.2.9.gemfile => rails_4.2.10.gemfile} | 2 +- ...ails_5.0.4.gemfile => rails_5.0.6.gemfile} | 2 +- ...ails_5.1.2.gemfile => rails_5.1.4.gemfile} | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) rename gemfiles/{rails_4.1.15.gemfile => rails_4.1.16.gemfile} (93%) rename gemfiles/{rails_4.2.9.gemfile => rails_4.2.10.gemfile} (92%) rename gemfiles/{rails_5.0.4.gemfile => rails_5.0.6.gemfile} (92%) rename gemfiles/{rails_5.1.2.gemfile => rails_5.1.4.gemfile} (92%) diff --git a/.travis.yml b/.travis.yml index fb1ea8ee..57eb540b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,38 +7,38 @@ rvm: - 2.3.5 gemfile: - gemfiles/rails_4.0.13.gemfile - - gemfiles/rails_4.1.15.gemfile - - gemfiles/rails_4.2.9.gemfile - - gemfiles/rails_5.0.4.gemfile - - gemfiles/rails_5.1.2.gemfile + - gemfiles/rails_4.1.16.gemfile + - gemfiles/rails_4.2.10.gemfile + - gemfiles/rails_5.0.6.gemfile + - gemfiles/rails_5.1.4.gemfile matrix: include: - rvm: 2.4.2 - gemfile: gemfiles/rails_4.2.9.gemfile + gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.2 - gemfile: gemfiles/rails_5.0.4.gemfile + gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.2 - gemfile: gemfiles/rails_5.1.2.gemfile + gemfile: gemfiles/rails_5.1.4.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.2 - gemfile: gemfiles/rails_4.2.9.gemfile + gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.2 - gemfile: gemfiles/rails_5.0.4.gemfile + gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.2 - gemfile: gemfiles/rails_5.1.2.gemfile + gemfile: gemfiles/rails_5.1.4.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.2 - gemfile: gemfiles/rails_4.2.9.gemfile + gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=oracle_enhanced - rvm: 2.4.2 - gemfile: gemfiles/rails_5.0.4.gemfile + gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=oracle_enhanced - rvm: 2.4.2 - gemfile: gemfiles/rails_5.1.2.gemfile + gemfile: gemfiles/rails_5.1.4.gemfile env: DB_ADAPTER=oracle_enhanced after_success: - bundle exec codeclimate-test-reporter diff --git a/Appraisals b/Appraisals index 56e6e7c7..98d63776 100644 --- a/Appraisals +++ b/Appraisals @@ -3,18 +3,18 @@ RAILS_VERSIONS = { 'mysql2' => '~> 0.3.18', 'activerecord-oracle_enhanced-adapter' => '~> 1.5.0' }, - '4.1.15' => { + '4.1.16' => { 'mysql2' => '~> 0.3.18', 'activerecord-oracle_enhanced-adapter' => '~> 1.5.0' }, - '4.2.9' => { + '4.2.10' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0' }, - '5.0.4' => { + '5.0.6' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', 'ruby-oci8' => '' }, - '5.1.2' => { + '5.1.4' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'ruby-oci8' => '' } diff --git a/gemfiles/rails_4.1.15.gemfile b/gemfiles/rails_4.1.16.gemfile similarity index 93% rename from gemfiles/rails_4.1.15.gemfile rename to gemfiles/rails_4.1.16.gemfile index 0b8a98ef..8af0b017 100644 --- a/gemfiles/rails_4.1.15.gemfile +++ b/gemfiles/rails_4.1.16.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "4.1.15" +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" diff --git a/gemfiles/rails_4.2.9.gemfile b/gemfiles/rails_4.2.10.gemfile similarity index 92% rename from gemfiles/rails_4.2.9.gemfile rename to gemfiles/rails_4.2.10.gemfile index 261f43d3..3fb5d20d 100644 --- a/gemfiles/rails_4.2.9.gemfile +++ b/gemfiles/rails_4.2.10.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "4.2.9" +gem "rails", "4.2.10" gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/gemfiles/rails_5.0.4.gemfile b/gemfiles/rails_5.0.6.gemfile similarity index 92% rename from gemfiles/rails_5.0.4.gemfile rename to gemfiles/rails_5.0.6.gemfile index 4822c1ee..86904ba2 100644 --- a/gemfiles/rails_5.0.4.gemfile +++ b/gemfiles/rails_5.0.6.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "5.0.4" +gem "rails", "5.0.6" gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/gemfiles/rails_5.1.2.gemfile b/gemfiles/rails_5.1.4.gemfile similarity index 92% rename from gemfiles/rails_5.1.2.gemfile rename to gemfiles/rails_5.1.4.gemfile index 3892ab26..f66c5aa3 100644 --- a/gemfiles/rails_5.1.2.gemfile +++ b/gemfiles/rails_5.1.4.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "5.1.2" +gem "rails", "5.1.4" gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" From 14f5a6ff5b2c8d52ea7beaf5e58177603558db12 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 10 Nov 2017 14:42:03 +0100 Subject: [PATCH 009/364] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2288328f..4ccc2e3b 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ > This gem is targeted at Datatables version 1.10.x. > > It's tested against : -> * Rails 4.0.13 / 4.1.15 / 4.2.9 / 5.0.4 / 5.1.2 -> * Ruby 2.2.7 / 2.3.4 / 2.4.1 +> * Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.6 / 5.1.4 +> * Ruby 2.2.8 / 2.3.5 / 2.4.2 > * Postgresql > * MySQL > * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) @@ -561,7 +561,7 @@ class MyCustomDatatable < AjaxDatatablesRails::Base def_delegators :@view, :link_to, :h, :mailto, :edit_resource_path, :check_box_tag, :other_method # Define columns as described above for `id`, `first_name`, `email`, and others - def view_columns + def view_columns ... end @@ -580,7 +580,7 @@ class MyCustomDatatable < AjaxDatatablesRails::Base end ``` -If you want to keep things tidy in the data mapping method, you could use +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. ```ruby From 3e2ba931963c77cd270fe8f2b41504445483baf5 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 14 Nov 2017 11:17:47 +0100 Subject: [PATCH 010/364] Switch to FactoryBot --- ajax-datatables-rails.gemspec | 2 +- spec/factories/user.rb | 2 +- spec/spec_helper.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 36052a61..392ff7a4 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'pry' s.add_development_dependency 'simplecov' s.add_development_dependency 'database_cleaner' - s.add_development_dependency 'factory_girl' + s.add_development_dependency 'factory_bot' s.add_development_dependency 'faker' s.add_development_dependency 'appraisal' diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 186adfc2..5cd5bf6a 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :user do |f| f.username { Faker::Internet.user_name } f.email { Faker::Internet.email } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22cb1cfa..e006e6cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ require 'simplecov' require 'rspec' require 'database_cleaner' -require 'factory_girl' +require 'factory_bot' require 'faker' require 'pry' require 'rails' @@ -15,10 +15,10 @@ # Configure RSpec RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods + config.include FactoryBot::Syntax::Methods config.before(:suite) do - FactoryGirl.find_definitions + FactoryBot.find_definitions end config.after(:each) do From 5fe09e9c52353e7247fa160e0df3a4f9475256b1 Mon Sep 17 00:00:00 2001 From: Nick Muerdter Date: Wed, 22 Nov 2017 16:57:55 -0700 Subject: [PATCH 011/364] Fix database offset queries to use the actual "start" parameter value. If the start value wasn't an exact multiple of the limit, then previously the database query would not acknowledge intermediate offset values. So, for example, if a request with start=20&limit=100 was made, ajax-datatables-rails would perform a "LIMIT 100 OFFSET 0" query, instead of "LIMIT 100 OFFSET 20" (which is what is intended). --- lib/ajax-datatables-rails/datatable/datatable.rb | 2 +- spec/ajax-datatables-rails/base_spec.rb | 4 ++-- spec/ajax-datatables-rails/datatable/datatable_spec.rb | 2 +- .../orm/active_record_paginate_records_spec.rb | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index cdda7e1e..50e76c70 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -56,7 +56,7 @@ def paginate? end def offset - (page - 1) * per_page + options.fetch(:start, 0).to_i end def page diff --git a/spec/ajax-datatables-rails/base_spec.rb b/spec/ajax-datatables-rails/base_spec.rb index 39e5a738..81f59117 100644 --- a/spec/ajax-datatables-rails/base_spec.rb +++ b/spec/ajax-datatables-rails/base_spec.rb @@ -155,10 +155,10 @@ expect(datatable.datatable.send(:offset)).to eq(0) end - it 'matches the value on view params[:start] minus 1' do + it 'matches the value on view params[:start]' do paginated_view = double('view', params: { start: '11' }) datatable = described_class.new(paginated_view) - expect(datatable.datatable.send(:offset)).to eq(10) + expect(datatable.datatable.send(:offset)).to eq(11) end end diff --git a/spec/ajax-datatables-rails/datatable/datatable_spec.rb b/spec/ajax-datatables-rails/datatable/datatable_spec.rb index b7c1d3d2..de530e5d 100644 --- a/spec/ajax-datatables-rails/datatable/datatable_spec.rb +++ b/spec/ajax-datatables-rails/datatable/datatable_spec.rb @@ -73,7 +73,7 @@ end it 'offset' do - expect(datatable.offset).to eq(45) + expect(datatable.offset).to eq(50) end it 'page' do 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 d9ddaa3b..f3dbffb4 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 @@ -38,16 +38,16 @@ if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] if Rails.version.in? %w[4.0.13 4.1.15 4.2.9] expect(datatable.paginate_records(records).to_sql).to include( - 'rownum <= 50' + 'rownum <= 51' ) else expect(datatable.paginate_records(records).to_sql).to include( - 'rownum <= (25 + 25)' + 'rownum <= (26 + 25)' ) end else expect(datatable.paginate_records(records).to_sql).to include( - 'LIMIT 25 OFFSET 25' + 'LIMIT 25 OFFSET 26' ) end end From 55c3918284a0a630d1a627794555985bae6928e3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 14 Feb 2018 00:28:06 +0100 Subject: [PATCH 012/364] Fix tests with Postgres --- 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 392ff7a4..939db8be 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rails', '>= 4.0' s.add_development_dependency 'rake' - s.add_development_dependency 'pg' + 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' From f253646d615e80250043fc97f34fd50f3b430b86 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 19:26:20 +0100 Subject: [PATCH 013/364] Enforce internal API consistency --- 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 6c874140..970d64a9 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -108,11 +108,11 @@ def retrieve_records end def records_total_count - get_raw_records.count(:all) + fetch_records.count(:all) end def records_filtered_count - filter_records(get_raw_records).count(:all) + filter_records(fetch_records).count(:all) end # Private helper methods From ad58aec20767f57c47afe4e4089788cc9ced20ca Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 19:30:37 +0100 Subject: [PATCH 014/364] Test with Rails 5.1.5 --- .travis.yml | 8 ++++---- Appraisals | 2 +- gemfiles/{rails_5.1.4.gemfile => rails_5.1.5.gemfile} | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename gemfiles/{rails_5.1.4.gemfile => rails_5.1.5.gemfile} (92%) diff --git a/.travis.yml b/.travis.yml index 57eb540b..98ae4e20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ gemfile: - gemfiles/rails_4.1.16.gemfile - gemfiles/rails_4.2.10.gemfile - gemfiles/rails_5.0.6.gemfile - - gemfiles/rails_5.1.4.gemfile + - gemfiles/rails_5.1.5.gemfile matrix: include: - rvm: 2.4.2 @@ -20,7 +20,7 @@ matrix: gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.2 - gemfile: gemfiles/rails_5.1.4.gemfile + gemfile: gemfiles/rails_5.1.5.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.2 gemfile: gemfiles/rails_4.2.10.gemfile @@ -29,7 +29,7 @@ matrix: gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.2 - gemfile: gemfiles/rails_5.1.4.gemfile + gemfile: gemfiles/rails_5.1.5.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.2 gemfile: gemfiles/rails_4.2.10.gemfile @@ -38,7 +38,7 @@ matrix: gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=oracle_enhanced - rvm: 2.4.2 - gemfile: gemfiles/rails_5.1.4.gemfile + gemfile: gemfiles/rails_5.1.5.gemfile env: DB_ADAPTER=oracle_enhanced after_success: - bundle exec codeclimate-test-reporter diff --git a/Appraisals b/Appraisals index 98d63776..14a8e0f3 100644 --- a/Appraisals +++ b/Appraisals @@ -14,7 +14,7 @@ RAILS_VERSIONS = { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', 'ruby-oci8' => '' }, - '5.1.4' => { + '5.1.5' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'ruby-oci8' => '' } diff --git a/gemfiles/rails_5.1.4.gemfile b/gemfiles/rails_5.1.5.gemfile similarity index 92% rename from gemfiles/rails_5.1.4.gemfile rename to gemfiles/rails_5.1.5.gemfile index f66c5aa3..57e7ca9e 100644 --- a/gemfiles/rails_5.1.4.gemfile +++ b/gemfiles/rails_5.1.5.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "5.1.4" +gem "rails", "5.1.5" gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" From 9f96760cb87fdd3a918be4b170d067b171754efb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 20:31:59 +0100 Subject: [PATCH 015/364] Fix tests with Oracle --- .../orm/active_record_filter_records_spec.rb | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 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 bcf66d67..1c2445e1 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 @@ -341,11 +341,22 @@ create(:user, last_name: 'MARY') end - 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' + if AjaxDatatablesRails.config.db_adapter == :oracleenhanced + 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 From be59d0647f6973e4f4713d1aacfa0f64f0f6a525 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 20:49:48 +0100 Subject: [PATCH 016/364] Test with latest Ruby versions --- .travis.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 98ae4e20..ac1ad58c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: ruby sudo: required cache: bundler rvm: - - 2.2.8 - - 2.3.5 + - 2.2.9 + - 2.3.6 gemfile: - gemfiles/rails_4.0.13.gemfile - gemfiles/rails_4.1.16.gemfile @@ -13,31 +13,31 @@ gemfile: - gemfiles/rails_5.1.5.gemfile matrix: include: - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_5.1.5.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_5.1.5.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_5.0.6.gemfile env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.2 + - rvm: 2.4.3 gemfile: gemfiles/rails_5.1.5.gemfile env: DB_ADAPTER=oracle_enhanced after_success: From 2716663faf6e5a3ed1a5896c8c2036ffa3a64a62 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 22:18:58 +0100 Subject: [PATCH 017/364] Fix tests with Oracle --- .../orm/active_record_paginate_records_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d9ddaa3b..ea71fb5b 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 @@ it 'paginates records properly' do if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced] - if Rails.version.in? %w[4.0.13 4.1.15 4.2.9] + if Rails.version.in? %w[4.0.13 4.1.16 4.2.10] expect(datatable.paginate_records(records).to_sql).to include( 'rownum <= 10' ) @@ -36,7 +36,7 @@ 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.15 4.2.9] + if Rails.version.in? %w[4.0.13 4.1.16 4.2.10] expect(datatable.paginate_records(records).to_sql).to include( 'rownum <= 50' ) From eb470022b6d06ab5a7cbe7eee640f805677ccbaf Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 22:54:45 +0100 Subject: [PATCH 018/364] Update README [ci skip] --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f924d7c2..24a4821f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ > This gem is targeted at Datatables version 1.10.x. > > It's tested against : -> * Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.6 / 5.1.4 +> * Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.6 / 5.1.5 > * Ruby 2.2.8 / 2.3.5 / 2.4.2 > * Postgresql > * MySQL @@ -243,10 +243,7 @@ This is where your query goes. ```ruby def get_raw_records # suppose we need all User records - # Rails 4+ User.all - # Rails 3.x - # User.scoped end ``` @@ -570,7 +567,7 @@ class MyCustomDatatable < AjaxDatatablesRails::Base def data records.map do |record| { - id: check_box_tag('users[]', record.id), + id: check_box_tag('users[]', record.id), first_name: link_to(record.fname, edit_resource_path(record)), email: mail_to(record.email) # other attributes From 9040bd9d7305af7a38f79a6e74bbe2231fc837c3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 17 Feb 2018 23:43:11 +0100 Subject: [PATCH 019/364] Update README [ci skip] --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24a4821f..35b959b7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ## Description -Datatables is a nifty jquery plugin that adds the ability to paginate, sort, +[Datatables](https://datatables.net/) is a nifty jquery plugin that adds the ability to paginate, sort, and search your html tables. When dealing with large tables (more than a couple hundred rows) however, we run into performance issues. These can be fixed by using server-side pagination, but this breaks some @@ -33,6 +33,10 @@ this [Railscast](http://railscasts.com/episodes/340-datatables). I needed to implement a similar solution in a couple projects I was working on, so I extracted a solution into a gem. +The final goal of this gem is to **generate a JSON** content that will be given to JQuery Datatable. +All the datatable customizations (header, tr, td, css classes, width, height, etc, etc) **must** take place in the [javascript definition](#wire-up-the-javascript) of the datatable. +JQuery Datatable is a very powerful tool with a lot of customizations available. Take the time to [read the doc](https://datatables.net/reference/option/). + ## ORM support Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for From 24f6d3ac1289ad8dd55a12683648b307974c4b2e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 00:08:39 +0100 Subject: [PATCH 020/364] Update generator [ci skip] --- lib/generators/rails/templates/datatable.rb | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/generators/rails/templates/datatable.rb b/lib/generators/rails/templates/datatable.rb index 12c9963b..dfa1ead6 100644 --- a/lib/generators/rails/templates/datatable.rb +++ b/lib/generators/rails/templates/datatable.rb @@ -19,23 +19,9 @@ def data end end - private - def get_raw_records # insert query here + # User.all end - # ==== These methods represent the basic operations to perform on records - # and feel free to override them - - # def filter_records(records) - # end - - # def sort_records(records) - # end - - # def paginate_records(records) - # end - - # ==== Insert 'presenter'-like methods below if necessary end From 82fb2c6338c86a9af07d9883a125c2d021725819 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 01:48:13 +0100 Subject: [PATCH 021/364] Improve coding style --- .rubocop.yml | 1154 +---------------- Appraisals | 10 +- Gemfile | 2 + Rakefile | 3 +- ajax-datatables-rails.gemspec | 10 +- lib/ajax-datatables-rails.rb | 14 +- lib/ajax-datatables-rails/base.rb | 34 +- lib/ajax-datatables-rails/config.rb | 2 + lib/ajax-datatables-rails/datatable/column.rb | 15 +- .../datatable/column_date_filter.rb | 18 +- .../datatable/datatable.rb | 4 +- .../datatable/simple_order.rb | 2 + .../datatable/simple_search.rb | 2 + .../orm/active_record.rb | 6 +- lib/ajax-datatables-rails/version.rb | 4 +- lib/ajax_datatables_rails.rb | 13 + lib/generators/datatable/config_generator.rb | 2 + .../templates/ajax_datatables_rails_config.rb | 2 + lib/generators/rails/datatable_generator.rb | 9 +- 19 files changed, 116 insertions(+), 1190 deletions(-) create mode 100644 lib/ajax_datatables_rails.rb diff --git a/.rubocop.yml b/.rubocop.yml index 631862d4..09d6d6f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,1157 +1,51 @@ AllCops: - DisabledByDefault: true + TargetRubyVersion: 2.4 + Exclude: + - spec/**/*.rb + - lib/ajax-datatables-rails.rb + - lib/generators/rails/templates/*.rb -#################### Lint ################################ - -Lint/AmbiguousOperator: - Description: >- - Checks for ambiguous operators in the first argument of a - method invocation without parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-as-args' - Enabled: true - -Lint/AmbiguousRegexpLiteral: - Description: >- - Checks for ambiguous regexp literals in the first argument of - a method invocation without parenthesis. - Enabled: true - -Lint/AssignmentInCondition: - Description: "Don't use assignment in conditions." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition' - Enabled: true - -Lint/BlockAlignment: - Description: 'Align block ends correctly.' - Enabled: true - -Lint/CircularArgumentReference: - Description: "Don't refer to the keyword argument in the default value." - Enabled: true - -Lint/ConditionPosition: - Description: >- - Checks for condition placed in a confusing position relative to - the keyword. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#same-line-condition' - Enabled: true - -Lint/Debugger: - Description: 'Check for debugger calls.' - Enabled: true - -Lint/DefEndAlignment: - Description: 'Align ends corresponding to defs correctly.' - Enabled: true - -Lint/DeprecatedClassMethods: - Description: 'Check for deprecated class method calls.' - Enabled: true - -Lint/DuplicateMethods: - Description: 'Check for duplicate methods calls.' - Enabled: true - -Lint/EachWithObjectArgument: - Description: 'Check for immutable argument given to each_with_object.' - Enabled: true - -Lint/ElseLayout: - Description: 'Check for odd code arrangement in an else block.' - Enabled: true - -Lint/EmptyEnsure: - Description: 'Checks for empty ensure block.' - Enabled: true - -Lint/EmptyInterpolation: - Description: 'Checks for empty string interpolation.' - Enabled: true - -Lint/EndAlignment: - Description: 'Align ends correctly.' - Enabled: true - -Lint/EndInMethod: - Description: 'END blocks should not be placed inside method definitions.' - Enabled: true - -Lint/EnsureReturn: - Description: 'Do not use return in an ensure block.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-return-ensure' - Enabled: true - -Lint/Eval: - Description: 'The use of eval represents a serious security risk.' - Enabled: true - -Lint/FormatParameterMismatch: - Description: 'The number of parameters to format/sprint must match the fields.' - Enabled: true - -Lint/HandleExceptions: - Description: "Don't suppress exception." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions' - Enabled: true - -Lint/InvalidCharacterLiteral: - Description: >- - Checks for invalid character literals with a non-escaped - whitespace character. - Enabled: true - -Lint/LiteralInCondition: - Description: 'Checks of literals used in conditions.' - Enabled: true - -Lint/LiteralInInterpolation: - Description: 'Checks for literals used in interpolation.' - Enabled: true - -Lint/Loop: - Description: >- - Use Kernel#loop with break rather than begin/end/until or - begin/end/while for post-loop tests. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#loop-with-break' - Enabled: true - -Lint/NestedMethodDefinition: - Description: 'Do not use nested method definitions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-methods' - Enabled: true - -Lint/NonLocalExitFromIterator: - Description: 'Do not use return in iterator to cause non-local exit.' - Enabled: true - -Lint/ParenthesesAsGroupedExpression: - Description: >- - Checks for method calls with a space before the opening - parenthesis. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: true - -Lint/RequireParentheses: - Description: >- - Use parentheses in the method call to avoid confusion - about precedence. - Enabled: true - -Lint/RescueException: - Description: 'Avoid rescuing the Exception class.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-blind-rescues' - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Description: >- - Do not use the same name as outer local variable - for block arguments or block local variables. - Enabled: true - -Lint/StringConversionInInterpolation: - Description: 'Checks for Object#to_s usage in string interpolation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-to-s' - Enabled: true - -Lint/UnderscorePrefixedVariableName: - Description: 'Do not use prefix `_` for a variable that is used.' - Enabled: true - -Lint/UnneededDisable: - Description: >- - Checks for rubocop:disable comments that can be removed. - Note: this cop is not disabled when disabling all cops. - It must be explicitly disabled. - Enabled: true - -Lint/UnusedBlockArgument: - Description: 'Checks for unused block arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' - Enabled: true - -Lint/UnusedMethodArgument: - Description: 'Checks for unused method arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' - Enabled: true - -Lint/UnreachableCode: - Description: 'Unreachable code.' - Enabled: true - -Lint/UselessAccessModifier: - Description: 'Checks for useless access modifiers.' - Enabled: true - -Lint/UselessAssignment: - Description: 'Checks for useless assignment to a local variable.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' - Enabled: true - -Lint/UselessComparison: - Description: 'Checks for comparison of something with itself.' - Enabled: true - -Lint/UselessElseWithoutRescue: - Description: 'Checks for useless `else` in `begin..end` without `rescue`.' - Enabled: true - -Lint/UselessSetterCall: - Description: 'Checks for useless setter call to a local variable.' - Enabled: true - -Lint/Void: - Description: 'Possible use of operator/literal/variable in void context.' - Enabled: true - -###################### Metrics #################################### - -Metrics/AbcSize: - Description: >- - A calculated magnitude based on number of assignments, - branches, and conditions. - Reference: 'http://c2.com/cgi/wiki?AbcMetric' - Enabled: false - Max: 20 - -Metrics/BlockNesting: - Description: 'Avoid excessive block nesting' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count' - Enabled: true - Max: 4 - -Metrics/ClassLength: - Description: 'Avoid classes longer than 250 lines of code.' - Enabled: true - Max: 250 - -Metrics/CyclomaticComplexity: - Description: >- - A complexity metric that is strongly correlated to the number - of test cases needed to validate a method. - Enabled: true - Max: 7 - -Metrics/LineLength: - Description: 'Limit lines to 80 characters.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' - Enabled: false - -Metrics/MethodLength: - Description: 'Avoid methods longer than 30 lines of code.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods' - Enabled: true - Max: 30 - -Metrics/ModuleLength: - Description: 'Avoid modules longer than 250 lines of code.' - Enabled: true - Max: 250 - -Metrics/ParameterLists: - Description: 'Avoid parameter lists longer than three or four parameters.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params' - Enabled: true - -Metrics/PerceivedComplexity: - Description: >- - A complexity metric geared towards measuring complexity for a - human reader. - Enabled: false - -##################### Performance ############################# - -Performance/Count: - Description: >- - Use `count` instead of `select...size`, `reject...size`, - `select...count`, `reject...count`, `select...length`, - and `reject...length`. - Enabled: true - -Performance/Detect: - Description: >- - Use `detect` instead of `select.first`, `find_all.first`, - `select.last`, and `find_all.last`. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code' - Enabled: true - -Performance/FlatMap: - Description: >- - Use `Enumerable#flat_map` - instead of `Enumerable#map...Array#flatten(1)` - or `Enumberable#collect..Array#flatten(1)` - Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code' - Enabled: true - EnabledForFlattenWithoutParams: false - # If enabled, this cop will warn about usages of - # `flatten` being called without any parameters. - # This can be dangerous since `flat_map` will only flatten 1 level, and - # `flatten` without any parameters can flatten multiple levels. - -Performance/ReverseEach: - Description: 'Use `reverse_each` instead of `reverse.each`.' - Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code' - Enabled: true - -Performance/Sample: - Description: >- - Use `sample` instead of `shuffle.first`, - `shuffle.last`, and `shuffle[Fixnum]`. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code' - Enabled: true - -Performance/Size: - Description: >- - Use `size` instead of `count` for counting - the number of elements in `Array` and `Hash`. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#arraycount-vs-arraysize-code' - Enabled: true - -Performance/StringReplacement: - Description: >- - Use `tr` instead of `gsub` when you are replacing the same - number of characters. Use `delete` instead of `gsub` when - you are deleting characters. - Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code' - Enabled: true - -##################### Rails ################################## - -Rails/ActionFilter: - Description: 'Enforces consistent use of action filter methods.' - Enabled: false - -Rails/Date: - Description: >- - Checks the correct usage of date aware methods, - such as Date.today, Date.current etc. - Enabled: false - -Rails/Delegate: - Description: 'Prefer delegate method for delegations.' - Enabled: false - -Rails/FindBy: - Description: 'Prefer find_by over where.first.' - Enabled: false - -Rails/FindEach: - Description: 'Prefer all.find_each over all.find.' - Enabled: false - -Rails/HasAndBelongsToMany: - Description: 'Prefer has_many :through to has_and_belongs_to_many.' - Enabled: false - -Rails/Output: - Description: 'Checks for calls to puts, print, etc.' - Enabled: false - -Rails/ReadWriteAttribute: - Description: >- - Checks for read_attribute(:attr) and - write_attribute(:attr, val). - Enabled: false - -Rails/ScopeArgs: - Description: 'Checks the arguments of ActiveRecord scopes.' - Enabled: false - -Rails/TimeZone: - Description: 'Checks the correct usage of time zone aware methods.' - StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time' - Reference: 'http://danilenko.org/2012/7/6/rails_timezones' - Enabled: false - -Rails/Validation: - Description: 'Use validates :attribute, hash of validations.' - Enabled: false - -################## Style ################################# - -Style/AccessModifierIndentation: - Description: Check indentation of private/protected visibility modifiers. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected' - Enabled: false - -Style/AccessorMethodName: - Description: Check the naming of accessor methods for get_/set_. - Enabled: false - -Style/Alias: - Description: 'Use alias_method instead of alias.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method' - Enabled: false - -Style/AlignArray: - Description: >- - Align the elements of an array literal if they span more than - one line. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays' - Enabled: false - -Style/AlignHash: - Description: >- - Align the elements of a hash literal if they span more than - one line. - Enabled: false - -Style/AlignParameters: - Description: >- - Align the parameters of a method call if they span more - than one line. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent' - Enabled: false - -Style/AndOr: - Description: 'Use &&/|| instead of and/or.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-and-or-or' - Enabled: false - -Style/ArrayJoin: - Description: 'Use Array#join instead of Array#*.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#array-join' - Enabled: false - -Style/AsciiComments: - Description: 'Use only ascii symbols in comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments' - Enabled: false - -Style/AsciiIdentifiers: - Description: 'Use only ascii symbols in identifiers.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers' - Enabled: false - -Style/Attr: - Description: 'Checks for uses of Module#attr.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr' - Enabled: false - -Style/BeginBlock: - Description: 'Avoid the use of BEGIN blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks' - Enabled: false - -Style/BarePercentLiterals: - Description: 'Checks if usage of %() or %Q() matches configuration.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q-shorthand' - Enabled: false - -Style/BlockComments: - Description: 'Do not use block comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments' - Enabled: false - -Style/BlockEndNewline: - Description: 'Put end statement of multiline block on its own line.' - Enabled: false - -Style/BlockDelimiters: - Description: >- - Avoid using {...} for multi-line blocks (multiline chaining is - always ugly). - Prefer {...} over do...end for single-line blocks. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' - Enabled: false - -Style/BracesAroundHashParameters: - Description: 'Enforce braces style around hash parameters.' - Enabled: false - -Style/CaseEquality: - Description: 'Avoid explicit use of the case equality operator(===).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality' - Enabled: false - -Style/CaseIndentation: - Description: 'Indentation of when in a case/when/[else/]end.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-when-to-case' - Enabled: false - -Style/CharacterLiteral: - Description: 'Checks for uses of character literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-character-literals' - Enabled: false - -Style/ClassAndModuleCamelCase: - Description: 'Use CamelCase for classes and modules.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#camelcase-classes' - Enabled: false - -Style/ClassAndModuleChildren: - Description: 'Checks style of children classes and modules.' - Enabled: false - -Style/ClassCheck: - Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.' - Enabled: false - -Style/ClassMethods: - Description: 'Use self when defining module/class methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-class-methods' - Enabled: false - -Style/ClassVars: - Description: 'Avoid the use of class variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-class-vars' - Enabled: false - -Style/ClosingParenthesisIndentation: - Description: 'Checks the indentation of hanging closing parentheses.' - Enabled: false - -Style/ColonMethodCall: - Description: 'Do not use :: for method call.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons' - Enabled: false - -Style/CommandLiteral: - Description: 'Use `` or %x around command literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-x' - Enabled: false - -Style/CommentAnnotation: - Description: 'Checks formatting of annotation comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#annotate-keywords' - Enabled: false - -Style/CommentIndentation: - Description: 'Indentation of comments.' - Enabled: false - -Style/ConstantName: - Description: 'Constants should use SCREAMING_SNAKE_CASE.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#screaming-snake-case' - Enabled: false - -Style/DefWithParentheses: - Description: 'Use def with parentheses when there are arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false - -Style/PreferredHashMethods: - Description: 'Checks for use of deprecated Hash methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key' - Enabled: false - -Style/Documentation: - Description: 'Document classes and non-namespace modules.' - Enabled: false - -Style/DotPosition: - Description: 'Checks the position of the dot in multi-line method calls.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains' - Enabled: false - -Style/DoubleNegation: - Description: 'Checks for uses of double negation (!!).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang' - Enabled: false - -Style/EachWithObject: - Description: 'Prefer `each_with_object` over `inject` or `reduce`.' - Enabled: false - -Style/ElseAlignment: - Description: 'Align elses and elsifs correctly.' - Enabled: false - -Style/EmptyElse: - Description: 'Avoid empty else-clauses.' - Enabled: false - -Style/EmptyLineBetweenDefs: - Description: 'Use empty lines between defs.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods' - Enabled: false - -Style/EmptyLines: - Description: "Don't use several empty lines in a row." - Enabled: false - -Style/EmptyLinesAroundAccessModifier: - Description: "Keep blank lines around access modifiers." - Enabled: false - -Style/EmptyLinesAroundBlockBody: - Description: "Keeps track of empty lines around block bodies." - Enabled: false - -Style/EmptyLinesAroundClassBody: - Description: "Keeps track of empty lines around class bodies." - Enabled: false - -Style/EmptyLinesAroundModuleBody: - Description: "Keeps track of empty lines around module bodies." - Enabled: false - -Style/EmptyLinesAroundMethodBody: - Description: "Keeps track of empty lines around method bodies." - Enabled: false - -Style/EmptyLiteral: - Description: 'Prefer literals to Array.new/Hash.new/String.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#literal-array-hash' - Enabled: false - -Style/EndBlock: - Description: 'Avoid the use of END blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-END-blocks' - Enabled: false - -Style/EndOfLine: - Description: 'Use Unix-style line endings.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf' +Documentation: Enabled: false -Style/EvenOdd: - Description: 'Favor the use of Fixnum#even? && Fixnum#odd?' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' +Gemspec/OrderedDependencies: Enabled: false -Style/ExtraSpacing: - Description: 'Do not use unnecessary spacing.' +Layout/EmptyLines: Enabled: false -Style/FileName: - Description: 'Use snake_case for source file names.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files' +Layout/EmptyLinesAroundClassBody: Enabled: false -Style/InitialIndentation: - Description: >- - Checks the indentation of the first non-blank non-comment line in a file. +Layout/EmptyLinesAroundBlockBody: Enabled: false -Style/FirstParameterIndentation: - Description: 'Checks the indentation of the first parameter in a method call.' +Layout/EmptyLinesAroundModuleBody: Enabled: false -Style/FlipFlop: - Description: 'Checks for flip flops' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops' +Layout/EmptyLineBetweenDefs: Enabled: false -Style/For: - Description: 'Checks use of for or each in multiline loops.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-for-loops' - Enabled: false - -Style/FormatString: - Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf' - Enabled: false - -Style/GlobalVars: - Description: 'Do not introduce global variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars' - Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html' - Enabled: false - -Style/GuardClause: - Description: 'Check for conditionals that can be replaced with guard clauses' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false - -Style/HashSyntax: - Description: >- - Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax - { :a => 1, :b => 2 }. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals' - Enabled: false - -Style/IfUnlessModifier: - Description: >- - Favor modifier if/unless usage when you have a - single-line body. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' - Enabled: false - -Style/IfWithSemicolon: - Description: 'Do not use if x; .... Use the ternary operator instead.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs' - Enabled: false - -Style/IndentationConsistency: - Description: 'Keep indentation straight.' - Enabled: false - -Style/IndentationWidth: - Description: 'Use 2 spaces for indentation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false - -Style/IndentArray: - Description: >- - Checks the indentation of the first element in an array - literal. - Enabled: false - -Style/IndentHash: - Description: 'Checks the indentation of the first key in a hash literal.' - Enabled: false - -Style/InfiniteLoop: - Description: 'Use Kernel#loop for infinite loops.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#infinite-loop' - Enabled: false - -Style/Lambda: - Description: 'Use the new lambda literal syntax for single-line blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#lambda-multi-line' - Enabled: false - -Style/LambdaCall: - Description: 'Use lambda.call(...) instead of lambda.(...).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc-call' - Enabled: false - -Style/LeadingCommentSpace: - Description: 'Comments should start with a space.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' - Enabled: false - -Style/LineEndConcatenation: - Description: >- - Use \ instead of + or << to concatenate two string literals at - line end. - Enabled: false - -Style/MethodCallParentheses: - Description: 'Do not use parentheses for method calls with no arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens' - Enabled: false - -Style/MethodDefParentheses: - Description: >- - Checks if the method definitions have or don't have - parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false - -Style/MethodName: - Description: 'Use the configured style when naming methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false - -Style/ModuleFunction: - Description: 'Checks for usage of `extend self` in modules.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function' - Enabled: false - -Style/MultilineBlockChain: - Description: 'Avoid multi-line chains of blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' - Enabled: false - -Style/MultilineBlockLayout: - Description: 'Ensures newlines after multiline block do statements.' - Enabled: false - -Style/MultilineIfThen: - Description: 'Do not use then for multi-line if/unless.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then' - Enabled: false - -Style/MultilineOperationIndentation: - Description: >- - Checks indentation of binary operations that span more than - one line. - Enabled: false - -Style/MultilineTernaryOperator: - Description: >- - Avoid multi-line ?: (the ternary operator); - use if/unless instead. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary' - Enabled: false - -Style/NegatedIf: - Description: >- - Favor unless over if for negative conditions - (or control flow or). - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives' - Enabled: false - -Style/NegatedWhile: - Description: 'Favor until over while for negative conditions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#until-for-negatives' - Enabled: false - -Style/NestedTernaryOperator: - Description: 'Use one expression per branch in a ternary operator.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-ternary' - Enabled: false - -Style/Next: - Description: 'Use `next` to skip iteration instead of a condition at the end.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false - -Style/NilComparison: - Description: 'Prefer x.nil? to x == nil.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false - -Style/NonNilCheck: - Description: 'Checks for redundant nil checks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks' - Enabled: false - -Style/Not: - Description: 'Use ! instead of not.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bang-not-not' - Enabled: false - -Style/NumericLiterals: - Description: >- - Add underscores to large numeric literals to improve their - readability. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics' - Enabled: false - -Style/OneLineConditional: - Description: >- - Favor the ternary operator(?:) over - if/then/else/end constructs. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator' - Enabled: false - -Style/OpMethod: - Description: 'When defining binary operators, name the argument other.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg' - Enabled: false - -Style/OptionalArguments: - Description: >- - Checks for optional arguments that do not appear at the end - of the argument list - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#optional-arguments' - Enabled: false - -Style/ParallelAssignment: - Description: >- - Check for simple usages of parallel assignment. - It will only warn when the number of variables - matches on both sides of the assignment. - This also provides performance benefits - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment' - Enabled: false - -Style/ParenthesesAroundCondition: - Description: >- - Don't use parentheses around the condition of an - if/unless/while. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-parens-if' - Enabled: false - -Style/PercentLiteralDelimiters: - Description: 'Use `%`-literal delimiters consistently' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-literal-braces' - Enabled: false - -Style/PercentQLiterals: - Description: 'Checks if uses of %Q/%q match the configured preference.' - Enabled: false - -Style/PerlBackrefs: - Description: 'Avoid Perl-style regex back references.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers' - Enabled: false - -Style/PredicateName: - Description: 'Check the names of predicate methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark' - Enabled: false - -Style/Proc: - Description: 'Use proc instead of Proc.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc' - Enabled: false - -Style/RaiseArgs: - Description: 'Checks the arguments passed to raise/fail.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#exception-class-messages' - Enabled: false - -Style/RedundantBegin: - Description: "Don't use begin blocks when they are not needed." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit' - Enabled: false - -Style/RedundantException: - Description: "Checks for an obsolete RuntimeException argument in raise/fail." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror' - Enabled: false - -Style/RedundantReturn: - Description: "Don't use return where it's not required." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-return' - Enabled: false - -Style/RedundantSelf: - Description: "Don't use self where it's not needed." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-self-unless-required' - Enabled: false - -Style/RegexpLiteral: - Description: 'Use / or %r around regular expressions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r' - Enabled: false - -Style/RescueEnsureAlignment: - Description: 'Align rescues and ensures correctly.' - Enabled: false - -Style/RescueModifier: - Description: 'Avoid using rescue in its modifier form.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers' - Enabled: false - -Style/SelfAssignment: - Description: >- - Checks for places where self-assignment shorthand should have - been used. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment' - Enabled: false - -Style/Semicolon: - Description: "Don't use semicolons to terminate expressions." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon' - Enabled: false - -Style/SignalException: - Description: 'Checks for proper usage of fail and raise.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method' - Enabled: false - -Style/SingleLineBlockParams: - Description: 'Enforces the names of some block params.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#reduce-blocks' - Enabled: false - -Style/SingleLineMethods: - Description: 'Avoid single-line methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-single-line-methods' - Enabled: false - -Style/SpaceBeforeFirstArg: - Description: >- - Checks that exactly one space is used between a method name - and the first argument for method calls without parentheses. - Enabled: true - -Style/SpaceAfterColon: - Description: 'Use spaces after colons.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceAfterComma: - Description: 'Use spaces after commas.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceAroundKeyword: - Description: 'Use spaces around keywords.' - Enabled: false - -Style/SpaceAfterMethodName: - Description: >- - Do not put a space between a method name and the opening - parenthesis in a method definition. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: false - -Style/SpaceAfterNot: - Description: Tracks redundant space after the ! operator. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-bang' - Enabled: false - -Style/SpaceAfterSemicolon: - Description: 'Use spaces after semicolons.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceBeforeBlockBraces: - Description: >- - Checks that the left block brace has or doesn't have space - before it. - Enabled: false - -Style/SpaceBeforeComma: - Description: 'No spaces before commas.' - Enabled: false - -Style/SpaceBeforeComment: - Description: >- - Checks for missing space between code and a comment on the - same line. - Enabled: false - -Style/SpaceBeforeSemicolon: - Description: 'No spaces before semicolons.' - Enabled: false - -Style/SpaceInsideBlockBraces: - Description: >- - Checks that block braces have or don't have surrounding space. - For blocks taking parameters, checks that the left brace has - or doesn't have trailing space. - Enabled: false - -Style/SpaceAroundBlockParameters: - Description: 'Checks the spacing inside and after block parameters pipes.' - Enabled: false - -Style/SpaceAroundEqualsInParameterDefault: - Description: >- - Checks that the equals signs in parameter default assignments - have or don't have surrounding space depending on - configuration. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-around-equals' - Enabled: false - -Style/SpaceAroundOperators: - Description: 'Use a single space around operators.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceInsideBrackets: - Description: 'No spaces after [ or before ].' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceInsideHashLiteralBraces: - Description: "Use spaces inside hash literal braces - or don't." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceInsideParens: - Description: 'No spaces after ( or before ).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceInsideRangeLiteral: - Description: 'No spaces inside range literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals' - Enabled: false - -Style/SpaceInsideStringInterpolation: - Description: 'Checks for padding/surrounding spaces inside string interpolation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#string-interpolation' - Enabled: false - -Style/SpecialGlobalVars: - Description: 'Avoid Perl-style global variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms' - Enabled: false - -Style/StringLiterals: - Description: 'Checks if uses of quotes match the configured preference.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals' - Enabled: false - -Style/StringLiteralsInInterpolation: - Description: >- - Checks if uses of quotes inside expressions in interpolated - strings match the configured preference. - Enabled: false - -Style/StructInheritance: - Description: 'Checks for inheritance from Struct.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new' - Enabled: false - -Style/SymbolLiteral: - Description: 'Use plain symbols instead of string symbols when possible.' - Enabled: false - -Style/SymbolProc: - Description: 'Use symbols as procs instead of blocks when possible.' - Enabled: false - -Style/Tab: - Description: 'No hard tabs.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false - -Style/TrailingBlankLines: - Description: 'Checks trailing blank lines and final newline.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof' - Enabled: false - -Style/TrailingCommaInArguments: - Description: 'Checks for trailing comma in parameter lists.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma' - Enabled: false - -Style/TrailingCommaInLiteral: - Description: 'Checks for trailing comma in literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' - Enabled: false - -Style/TrailingWhitespace: - Description: 'Avoid trailing whitespace.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace' - Enabled: false - -Style/TrivialAccessors: - Description: 'Prefer attr_* methods to trivial readers/writers.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr_family' - Enabled: false - -Style/UnlessElse: - Description: >- - Do not use unless with else. Rewrite these with the positive - case first. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-else-with-unless' - Enabled: false - -Style/UnneededCapitalW: - Description: 'Checks for %W when interpolation is not needed.' - Enabled: false - -Style/UnneededPercentQ: - Description: 'Checks for %q/%Q when single quotes or double quotes would do.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q' +Metrics/LineLength: Enabled: false -Style/TrailingUnderscoreVariable: - Description: >- - Checks for the usage of unneeded trailing underscores at the - end of parallel variable assignment. +Metrics/AbcSize: Enabled: false -Style/VariableInterpolation: - Description: >- - Don't interpolate global, instance and class variables - directly in strings. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#curlies-interpolate' - Enabled: false +Metrics/MethodLength: + Max: 12 -Style/VariableName: - Description: 'Use the configured style when naming variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false +Metrics/BlockLength: + Max: 30 -Style/WhenThen: - Description: 'Use when x then ... for one-line cases.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#one-line-cases' - Enabled: false +Metrics/ModuleLength: + Max: 130 -Style/WhileUntilDo: - Description: 'Checks for redundant do after while or until.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-while-do' - Enabled: false +Metrics/ClassLength: + Max: 130 -Style/WhileUntilModifier: - Description: >- - Favor modifier while/until usage when you have a - single-line body. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier' +Naming/AccessorMethodName: Enabled: false -Style/WordArray: - Description: 'Use %w or %W for arrays of words.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w' +Style/NumericPredicate: Enabled: false diff --git a/Appraisals b/Appraisals index 14a8e0f3..f43a3f78 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RAILS_VERSIONS = { '4.0.13' => { 'mysql2' => '~> 0.3.18', @@ -18,16 +20,16 @@ RAILS_VERSIONS = { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'ruby-oci8' => '' } -} +}.freeze RAILS_VERSIONS.each do |version, gems| appraise "rails_#{version}" do gem 'rails', version - gems.each do |name, version| - if version.empty? + gems.each do |name, gem_version| + if gem_version.empty? gem name else - gem name, version + gem name, gem_version end end end diff --git a/Gemfile b/Gemfile index 7ae18d32..4644180e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org/' gemspec diff --git a/Rakefile b/Rakefile index fa3c4583..c0d0eb86 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ -#!/usr/bin/env rake +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/ajax-datatables-rails.gemspec b/ajax-datatables-rails.gemspec index 939db8be..780b46b7 100644 --- a/ajax-datatables-rails.gemspec +++ b/ajax-datatables-rails.gemspec @@ -1,5 +1,7 @@ +# frozen_string_literal: true # coding: utf-8 -$:.push File.expand_path('../lib', __FILE__) + +$LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'ajax-datatables-rails/version' Gem::Specification.new do |s| @@ -9,8 +11,8 @@ Gem::Specification.new do |s| s.authors = ['Joel Quenneville', 'Antonio Antillon'] s.email = ['joel.quenneville@collegeplus.org', 'antillas21@gmail.com'] s.homepage = 'https://github.com/jbox-web/ajax-datatables-rails' - s.summary = %q{A gem that simplifies using datatables and hundreds of records via ajax} - s.description = %q{A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app} + 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.add_dependency 'railties', '>= 4.0' @@ -32,6 +34,6 @@ Gem::Specification.new do |s| 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.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] end diff --git a/lib/ajax-datatables-rails.rb b/lib/ajax-datatables-rails.rb index a4662a42..9675176c 100644 --- a/lib/ajax-datatables-rails.rb +++ b/lib/ajax-datatables-rails.rb @@ -1,11 +1,3 @@ -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_date_filter' unless AjaxDatatablesRails.old_rails? - require 'ajax-datatables-rails/datatable/column' - require 'ajax-datatables-rails/orm/active_record' -end +# frozen_string_literal: true + +require 'ajax_datatables_rails' diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 970d64a9..eef3cbdb 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AjaxDatatablesRails class Base extend Forwardable @@ -5,7 +7,7 @@ class Base attr_reader :view, :options def_delegator :@view, :params - GLOBAL_SEARCH_DELIMITER = ' '.freeze + GLOBAL_SEARCH_DELIMITER = ' ' def initialize(view, options = {}) @view = view @@ -22,15 +24,15 @@ def datatable end def view_columns - fail(NotImplementedError, view_columns_error_text) + raise(NotImplementedError, view_columns_error_text) end def get_raw_records - fail(NotImplementedError, raw_records_error_text) + raise(NotImplementedError, raw_records_error_text) end def data - fail(NotImplementedError, data_error_text) + raise(NotImplementedError, data_error_text) end def additional_data @@ -77,11 +79,11 @@ def search_columns # without breaking change. def get_additional_data if respond_to?(:additional_datas) - puts <<-eos + puts <<-WARNING `additional_datas` has been deprecated and will be removed in next major version update! Please use `additional_data` instead. - eos + WARNING additional_datas else @@ -94,7 +96,7 @@ def sanitize(data) if record.is_a?(Array) record.map { |td| ERB::Util.html_escape(td) } else - record.update(record){ |_, v| ERB::Util.html_escape(v) } + record.update(record) { |_, v| ERB::Util.html_escape(v) } end end end @@ -118,9 +120,9 @@ def records_filtered_count # Private helper methods def load_orm_extension case config.orm - when :mongoid then nil - when :active_record then extend ORM::ActiveRecord - else + when :active_record + extend ORM::ActiveRecord + when :mongoid nil end end @@ -130,30 +132,30 @@ def global_search_delimiter end def raw_records_error_text - return <<-eos + <<-ERROR You should implement this method in your class and specify how records are going to be retrieved from the database. - eos + ERROR end def data_error_text - return <<-eos + <<-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. - eos + ERROR end def view_columns_error_text - return <<-eos + <<-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. - eos + ERROR end end end diff --git a/lib/ajax-datatables-rails/config.rb b/lib/ajax-datatables-rails/config.rb index bd252889..c2b642dd 100644 --- a/lib/ajax-datatables-rails/config.rb +++ b/lib/ajax-datatables-rails/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/configurable' module AjaxDatatablesRails diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 495e875e..ece9ed9e 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -1,17 +1,22 @@ +# frozen_string_literal: true + require 'ostruct' module AjaxDatatablesRails module Datatable class Column attr_reader :datatable, :index, :options + attr_writer :search unless AjaxDatatablesRails.old_rails? prepend ColumnDateFilter end def initialize(datatable, index, options) - @datatable, @index, @options = datatable, index, options - @view_column = datatable.view_columns[options["data"].to_sym] + @datatable = datatable + @index = index + @options = options + @view_column = datatable.view_columns[options['data'].to_sym] end def data @@ -34,10 +39,6 @@ def searched? search.value.present? end - def search=(value) - @search = value - end - def cond @view_column[:cond] || :like end @@ -129,8 +130,6 @@ def non_regex_search casted_column.matches("%#{formated_value}") when :like casted_column.matches("%#{formated_value}%") - else - nil end end diff --git a/lib/ajax-datatables-rails/datatable/column_date_filter.rb b/lib/ajax-datatables-rails/datatable/column_date_filter.rb index 78a31fe3..e2ce8cdd 100644 --- a/lib/ajax-datatables-rails/datatable/column_date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column_date_filter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AjaxDatatablesRails module Datatable module ColumnDateFilter @@ -26,21 +28,21 @@ def date_range_search new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") else - new_start = range_start.blank? ? DateTime.parse('01/01/1970') : DateTime.parse(range_start) - new_end = range_end.blank? ? DateTime.current : DateTime.parse("#{range_end} 23:59:59") + new_start = range_start.blank? ? Time.parse('01/01/1970') : Time.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.parse("#{range_end} 23:59:59") end table[field].between(OpenStruct.new(begin: new_start, end: new_end)) end private - def non_regex_search - if cond == :date_range - date_range_search - else - super - end + def non_regex_search + if cond == :date_range + date_range_search + else + super end + end end end diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index 50e76c70..6f375a54 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module AjaxDatatablesRails module Datatable - TRUE_VALUE = 'true'.freeze + 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 dca4cbfa..7a17d102 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AjaxDatatablesRails module Datatable class SimpleOrder diff --git a/lib/ajax-datatables-rails/datatable/simple_search.rb b/lib/ajax-datatables-rails/datatable/simple_search.rb index cab3fc35..0e70d774 100644 --- a/lib/ajax-datatables-rails/datatable/simple_search.rb +++ b/lib/ajax-datatables-rails/datatable/simple_search.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AjaxDatatablesRails module Datatable class SimpleSearch diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index 9a252732..da82a10b 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AjaxDatatablesRails module ORM module ActiveRecord @@ -15,7 +17,7 @@ def sort_records(records) column = order.column queries << order.query(column.sort_query) if column end - records.order(sort_by.join(", ")) + records.order(sort_by.join(', ')) end def paginate_records(records) @@ -34,7 +36,7 @@ def build_conditions def build_conditions_for_datatable criteria = search_for.inject([]) do |crit, atom| - search = Datatable::SimpleSearch.new({ value: atom, regex: datatable.search.regexp? }) + search = Datatable::SimpleSearch.new(value: atom, regex: datatable.search.regexp?) crit << searchable_columns.map do |simple_column| simple_column.search = search simple_column.search_query diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index d5472c0c..3f795c6d 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AjaxDatatablesRails - VERSION = '0.4.0'.freeze + VERSION = '0.4.0' end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb new file mode 100644 index 00000000..a7215139 --- /dev/null +++ b/lib/ajax_datatables_rails.rb @@ -0,0 +1,13 @@ +# 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_date_filter' unless AjaxDatatablesRails.old_rails? + require 'ajax-datatables-rails/datatable/column' + require 'ajax-datatables-rails/orm/active_record' +end diff --git a/lib/generators/datatable/config_generator.rb b/lib/generators/datatable/config_generator.rb index ea5ff476..2df3f2d8 100644 --- a/lib/generators/datatable/config_generator.rb +++ b/lib/generators/datatable/config_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails/generators' module Datatable diff --git a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb index b4d78750..52fa23cb 100644 --- a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +++ b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb @@ -1,3 +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 diff --git a/lib/generators/rails/datatable_generator.rb b/lib/generators/rails/datatable_generator.rb index 429c76dc..606016a7 100644 --- a/lib/generators/rails/datatable_generator.rb +++ b/lib/generators/rails/datatable_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails/generators' module Rails @@ -8,9 +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', File.join('app', 'datatables', "#{datatable_path}.rb") end def datatable_name @@ -18,10 +18,11 @@ def datatable_name end private + def datatable_path "#{name.underscore}_datatable" end end end -end \ No newline at end of file +end From cc44a081116290d0c302b10b913690e72a8a1405 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 01:56:20 +0100 Subject: [PATCH 022/364] Move ColumnDateFilter module under Column namespace --- lib/ajax-datatables-rails/datatable/column.rb | 9 +-- .../datatable/column/date_filter.rb | 59 +++++++++++++++++++ .../datatable/column_date_filter.rb | 49 --------------- lib/ajax_datatables_rails.rb | 2 +- 4 files changed, 61 insertions(+), 58 deletions(-) create mode 100644 lib/ajax-datatables-rails/datatable/column/date_filter.rb delete mode 100644 lib/ajax-datatables-rails/datatable/column_date_filter.rb diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index ece9ed9e..d50ae32d 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'ostruct' - module AjaxDatatablesRails module Datatable class Column @@ -9,7 +7,7 @@ class Column attr_writer :search unless AjaxDatatablesRails.old_rails? - prepend ColumnDateFilter + prepend DateFilter end def initialize(datatable, index, options) @@ -67,11 +65,6 @@ def use_regex? @view_column.fetch(:use_regex, true) end - # Add delimiter option to handle range search - def delimiter - @view_column[:delimiter] || '-' - end - def table model = source.split('.').first.constantize model.arel_table rescue model diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb new file mode 100644 index 00000000..738fe38f --- /dev/null +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'ostruct' + +module AjaxDatatablesRails + module Datatable + class Column + module DateFilter + + # Add delimiter option to handle range search + def delimiter + @view_column[:delimiter] || '-' + end + + def empty_range_search? + (formated_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] + end + + # A range value is in form '' + # This returns + def range_end + @range_end ||= formated_value.split(delimiter)[1] + end + + # Do a range search + def date_range_search + return nil if empty_range_search? + + if Time.zone + new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") + else + new_start = range_start.blank? ? Time.parse('01/01/1970') : Time.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.parse("#{range_end} 23:59:59") + end + + table[field].between(OpenStruct.new(begin: new_start, end: new_end)) + end + + private + + def non_regex_search + if cond == :date_range + date_range_search + else + super + end + end + + end + end + end +end diff --git a/lib/ajax-datatables-rails/datatable/column_date_filter.rb b/lib/ajax-datatables-rails/datatable/column_date_filter.rb deleted file mode 100644 index e2ce8cdd..00000000 --- a/lib/ajax-datatables-rails/datatable/column_date_filter.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -module AjaxDatatablesRails - module Datatable - module ColumnDateFilter - - def empty_range_search? - (formated_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] - end - - # A range value is in form '' - # This returns - def range_end - @range_end ||= formated_value.split(delimiter)[1] - end - - # Do a range search - def date_range_search - return nil if empty_range_search? - - if Time.zone - new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) - new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") - else - new_start = range_start.blank? ? Time.parse('01/01/1970') : Time.parse(range_start) - new_end = range_end.blank? ? Time.current : Time.parse("#{range_end} 23:59:59") - end - table[field].between(OpenStruct.new(begin: new_start, end: new_end)) - end - - private - - def non_regex_search - if cond == :date_range - date_range_search - else - super - end - end - - end - end -end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb index a7215139..bf6fda14 100644 --- a/lib/ajax_datatables_rails.rb +++ b/lib/ajax_datatables_rails.rb @@ -7,7 +7,7 @@ module AjaxDatatablesRails 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_date_filter' unless AjaxDatatablesRails.old_rails? + require 'ajax-datatables-rails/datatable/column/date_filter' unless AjaxDatatablesRails.old_rails? require 'ajax-datatables-rails/datatable/column' require 'ajax-datatables-rails/orm/active_record' end From 473703268f41ab8625c9872054a4cd70a6431cd4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:10:17 +0100 Subject: [PATCH 023/364] Replace switch statement by a Hash lookup --- lib/ajax-datatables-rails/datatable/column.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index d50ae32d..7c537f9d 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -3,6 +3,16 @@ module AjaxDatatablesRails module Datatable class Column + + DB_ADAPTER_TYPE_CAST = { + mysql: 'CHAR', + mysql2: 'CHAR', + sqlite: 'TEXT', + sqlite3: 'TEXT', + oracle: 'VARCHAR2(4000)', + oracleenhanced: 'VARCHAR2(4000)', + }.freeze + attr_reader :datatable, :index, :options attr_writer :search @@ -127,13 +137,7 @@ def non_regex_search end def typecast - case config.db_adapter - when :oracle, :oracleenhanced then 'VARCHAR2(4000)' - when :mysql, :mysql2 then 'CHAR' - when :sqlite, :sqlite3 then 'TEXT' - else - 'VARCHAR' - end + DB_ADAPTER_TYPE_CAST[config.db_adapter] || 'VARCHAR' end def casted_column From ea5847ec7e58bd5f3716f5989e6e82fbff50692e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:14:32 +0100 Subject: [PATCH 024/364] Extract Column search module --- lib/ajax-datatables-rails/datatable/column.rb | 77 +--------------- .../datatable/column/search.rb | 88 +++++++++++++++++++ lib/ajax_datatables_rails.rb | 1 + 3 files changed, 91 insertions(+), 75 deletions(-) create mode 100644 lib/ajax-datatables-rails/datatable/column/search.rb diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 7c537f9d..88d64908 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -16,6 +16,8 @@ class Column attr_reader :datatable, :index, :options attr_writer :search + include Search + unless AjaxDatatablesRails.old_rails? prepend DateFilter end @@ -31,30 +33,10 @@ def data options[:data].presence || options[:name] end - def searchable? - @view_column.fetch(:searchable, true) - end - def orderable? @view_column.fetch(:orderable, true) end - def search - @search ||= SimpleSearch.new(options[:search]) - end - - def searched? - search.value.present? - end - - def cond - @view_column[:cond] || :like - end - - def filter - @view_column[:cond].call(self, formated_value) - end - def source @view_column[:source] end @@ -70,11 +52,6 @@ def formater @view_column[:formater] end - # Add use_regex option to allow bypassing of regex search - def use_regex? - @view_column.fetch(:use_regex, true) - end - def table model = source.split('.').first.constantize model.arel_table rescue model @@ -84,10 +61,6 @@ def field source.split('.').last.to_sym end - def search_query - search.regexp? ? regex_search : non_regex_search - end - def sort_query custom_field? ? source : "#{table.name}.#{sort_field}" end @@ -106,36 +79,6 @@ def config @config ||= AjaxDatatablesRails.config end - # Using multi-select filters in JQuery Datatable auto-enables regex_search. - # Unfortunately regex_search doesn't work when filtering on primary keys with integer. - # It generates this kind of query : AND ("regions"."id" ~ '2|3') which throws an error : - # operator doesn't exist : integer ~ unknown - # 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)) - else - non_regex_search - end - end - - def non_regex_search - case cond - when Proc - filter - when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in - numeric_search - when :null_value - null_value_search - when :start_with - casted_column.matches("#{formated_value}%") - when :end_with - casted_column.matches("%#{formated_value}") - when :like - casted_column.matches("%#{formated_value}%") - end - end - def typecast DB_ADAPTER_TYPE_CAST[config.db_adapter] || 'VARCHAR' end @@ -144,22 +87,6 @@ def casted_column ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(typecast)]) end - def null_value_search - if formated_value == '!NULL' - table[field].not_eq(nil) - else - table[field].eq(nil) - end - end - - def numeric_search - if custom_field? - ::Arel::Nodes::SqlLiteral.new(field).eq(formated_value) - else - table[field].send(cond, formated_value) - end - end - end end end diff --git a/lib/ajax-datatables-rails/datatable/column/search.rb b/lib/ajax-datatables-rails/datatable/column/search.rb new file mode 100644 index 00000000..e3371134 --- /dev/null +++ b/lib/ajax-datatables-rails/datatable/column/search.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + module Datatable + class Column + module Search + + def searchable? + @view_column.fetch(:searchable, true) + end + + def cond + @view_column[:cond] || :like + end + + def filter + @view_column[:cond].call(self, formated_value) + end + + def search + @search ||= SimpleSearch.new(options[:search]) + end + + def searched? + search.value.present? + end + + def search_query + search.regexp? ? regex_search : non_regex_search + end + + # Add use_regex option to allow bypassing of regex search + def use_regex? + @view_column.fetch(:use_regex, true) + end + + private + + # Using multi-select filters in JQuery Datatable auto-enables regex_search. + # Unfortunately regex_search doesn't work when filtering on primary keys with integer. + # It generates this kind of query : AND ("regions"."id" ~ '2|3') which throws an error : + # operator doesn't exist : integer ~ unknown + # 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)) + else + non_regex_search + end + end + + def non_regex_search + case cond + when Proc + filter + when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in + numeric_search + when :null_value + null_value_search + when :start_with + casted_column.matches("#{formated_value}%") + when :end_with + casted_column.matches("%#{formated_value}") + when :like + casted_column.matches("%#{formated_value}%") + end + end + + def null_value_search + if formated_value == '!NULL' + table[field].not_eq(nil) + else + table[field].eq(nil) + end + end + + def numeric_search + if custom_field? + ::Arel::Nodes::SqlLiteral.new(field).eq(formated_value) + else + table[field].send(cond, formated_value) + end + end + + end + end + end +end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb index bf6fda14..22c54fa7 100644 --- a/lib/ajax_datatables_rails.rb +++ b/lib/ajax_datatables_rails.rb @@ -7,6 +7,7 @@ module AjaxDatatablesRails 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/date_filter' unless AjaxDatatablesRails.old_rails? require 'ajax-datatables-rails/datatable/column' require 'ajax-datatables-rails/orm/active_record' From 35437bd5cd2896b0ce311a50c69fa09c678bcf93 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:16:34 +0100 Subject: [PATCH 025/364] Extract Column order module --- lib/ajax-datatables-rails/datatable/column.rb | 14 +---------- .../datatable/column/order.rb | 24 +++++++++++++++++++ lib/ajax_datatables_rails.rb | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 lib/ajax-datatables-rails/datatable/column/order.rb diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 88d64908..275ba35e 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -17,6 +17,7 @@ class Column attr_writer :search include Search + include Order unless AjaxDatatablesRails.old_rails? prepend DateFilter @@ -33,19 +34,10 @@ def data options[:data].presence || options[:name] end - def orderable? - @view_column.fetch(:orderable, true) - end - def source @view_column[:source] end - # Add sort_field option to allow overriding of sort field - def sort_field - @view_column[:sort_field] || field - end - # Add formater option to allow modification of the value # before passing it to the database def formater @@ -61,10 +53,6 @@ def field source.split('.').last.to_sym end - def sort_query - custom_field? ? source : "#{table.name}.#{sort_field}" - end - def formated_value formater ? formater.call(search.value) : search.value end diff --git a/lib/ajax-datatables-rails/datatable/column/order.rb b/lib/ajax-datatables-rails/datatable/column/order.rb new file mode 100644 index 00000000..39417f75 --- /dev/null +++ b/lib/ajax-datatables-rails/datatable/column/order.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module AjaxDatatablesRails + module Datatable + class Column + module Order + + def orderable? + @view_column.fetch(:orderable, true) + end + + # Add sort_field option to allow overriding of sort field + def sort_field + @view_column[:sort_field] || field + end + + def sort_query + custom_field? ? source : "#{table.name}.#{sort_field}" + end + + end + end + end +end diff --git a/lib/ajax_datatables_rails.rb b/lib/ajax_datatables_rails.rb index 22c54fa7..49bc773d 100644 --- a/lib/ajax_datatables_rails.rb +++ b/lib/ajax_datatables_rails.rb @@ -8,6 +8,7 @@ module AjaxDatatablesRails 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' unless AjaxDatatablesRails.old_rails? require 'ajax-datatables-rails/datatable/column' require 'ajax-datatables-rails/orm/active_record' From 03c8b873c461a94a623e845494a4bf54636d6c14 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:23:07 +0100 Subject: [PATCH 026/364] Extract method --- lib/ajax-datatables-rails/datatable/simple_order.rb | 7 ++++++- spec/ajax-datatables-rails/datatable/simple_order_spec.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 7a17d102..e35bf2a0 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -20,7 +20,7 @@ def column end def direction - DIRECTIONS.find { |dir| dir == @options[:dir].upcase } || 'ASC' + DIRECTIONS.find { |dir| dir == column_direction } || 'ASC' end private @@ -28,6 +28,11 @@ def direction def column_index @options[:column] end + + def column_direction + @options[:dir].upcase + 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 296fd044..6e0a6695 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 @@ describe AjaxDatatablesRails::Datatable::SimpleOrder do - 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(nil, options) } describe 'option methods' do From d03eacd8ec2c714859870f144531d4e6ed9a83cb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:24:12 +0100 Subject: [PATCH 027/364] Coding style --- lib/ajax-datatables-rails/datatable/simple_search.rb | 1 + spec/ajax-datatables-rails/datatable/simple_search_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/datatable/simple_search.rb b/lib/ajax-datatables-rails/datatable/simple_search.rb index 0e70d774..a2ccd233 100644 --- a/lib/ajax-datatables-rails/datatable/simple_search.rb +++ b/lib/ajax-datatables-rails/datatable/simple_search.rb @@ -15,6 +15,7 @@ def value def regexp? @options[:regex] == TRUE_VALUE end + end end end diff --git a/spec/ajax-datatables-rails/datatable/simple_search_spec.rb b/spec/ajax-datatables-rails/datatable/simple_search_spec.rb index b9eb1fbf..784d85cf 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 @@ 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 From 2414aab24249220eaaef4db6fae2482c47202605 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:35:40 +0100 Subject: [PATCH 028/364] Extract methods in Column::DateFilter --- .../datatable/column/date_filter.rb | 27 ++++++++++++------- 1 file changed, 17 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 738fe38f..d12260c4 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -31,16 +31,7 @@ def range_end # Do a range search def date_range_search return nil if empty_range_search? - - if Time.zone - new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) - new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") - else - new_start = range_start.blank? ? Time.parse('01/01/1970') : Time.parse(range_start) - new_end = range_end.blank? ? Time.current : Time.parse("#{range_end} 23:59:59") - end - - table[field].between(OpenStruct.new(begin: new_start, end: new_end)) + table[field].between(OpenStruct.new(begin: range_start_casted, end: range_end_casted)) end private @@ -53,6 +44,22 @@ def non_regex_search end end + def range_start_casted + range_start.blank? ? parse_date('01/01/1970') : parse_date(range_start) + end + + def range_end_casted + range_end.blank? ? Time.current : parse_date("#{range_end} 23:59:59") + end + + def parse_date(date) + if Time.zone + Time.zone.parse(date) + else + Time.parse(date) + end + end + end end end From e742eb6de7424452aed451072cb3c9e2f6b78086 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 02:36:13 +0100 Subject: [PATCH 029/364] Enforce Rubcoop guidelines --- .rubocop.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 09d6d6f2..b94fc819 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Exclude: - spec/**/*.rb - lib/ajax-datatables-rails.rb @@ -29,18 +29,9 @@ Layout/EmptyLineBetweenDefs: Metrics/LineLength: Enabled: false -Metrics/AbcSize: - Enabled: false - -Metrics/MethodLength: - Max: 12 - Metrics/BlockLength: Max: 30 -Metrics/ModuleLength: - Max: 130 - Metrics/ClassLength: Max: 130 From 9a92bbbb89ac7a7da397a3878ef998ad3b891d2c Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:05:42 +0100 Subject: [PATCH 030/364] Extract method, add tests --- lib/ajax-datatables-rails/datatable/column.rb | 19 ++++++---- .../datatable/column_spec.rb | 38 +++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 275ba35e..83313abc 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -10,7 +10,7 @@ class Column sqlite: 'TEXT', sqlite3: 'TEXT', oracle: 'VARCHAR2(4000)', - oracleenhanced: 'VARCHAR2(4000)', + oracleenhanced: 'VARCHAR2(4000)' }.freeze attr_reader :datatable, :index, :options @@ -38,21 +38,24 @@ def source @view_column[:source] end - # Add formater option to allow modification of the value - # before passing it to the database - def formater - @view_column[:formater] + def table + model.respond_to?(:arel_table) ? model.arel_table : model end - def table - model = source.split('.').first.constantize - model.arel_table rescue model + def model + source.split('.').first.constantize end def field source.split('.').last.to_sym end + # Add formater option to allow modification of the value + # before passing it to the database + def formater + @view_column[:formater] + end + def formated_value formater ? formater.call(search.value) : search.value end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index bf1daf53..850a5012 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -29,6 +29,44 @@ expect(column.data).to eq('username') end + describe 'data' do + it 'should return 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 + 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 + expect(column.table).to eq User.arel_table + end + end + context 'with other ORM' do + it 'should return the corresponding model' do + expect(User).to receive(:respond_to?).with(:arel_table).and_return(false) + expect(column.table).to eq User + end + end + end + + describe 'model' do + it 'should return 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 + expect(column.field).to eq :username + end + end + describe '#search' do it 'child class' do expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch) From 3205053462e4e612b1e0f28e4ffad99df7249a9f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:08:00 +0100 Subject: [PATCH 031/364] Rename private method --- lib/ajax-datatables-rails/datatable/column.rb | 4 ++-- .../orm/active_record_filter_records_spec.rb | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 83313abc..0dca7a3d 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -70,12 +70,12 @@ def config @config ||= AjaxDatatablesRails.config end - def typecast + def type_cast DB_ADAPTER_TYPE_CAST[config.db_adapter] || 'VARCHAR' end def casted_column - ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(typecast)]) + ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(type_cast)]) 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 1c2445e1..32ac59b3 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,53 +183,53 @@ end end - describe '#typecast helper method' do + describe '#type_cast helper method' do let(:view) { double('view', params: sample_params) } let(:column) { ComplexDatatable.new(view).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(:typecast)).to eq('VARCHAR') + 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(:typecast)).to eq('VARCHAR') + 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(:typecast)).to eq('VARCHAR') + 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(:typecast)).to eq('VARCHAR2(4000)') + 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(:typecast)).to eq('VARCHAR2(4000)') + 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(:typecast)).to eq('CHAR') + 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(:typecast)).to eq('CHAR') + 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(:typecast)).to eq('TEXT') + 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(:typecast)).to eq('TEXT') + expect(column.send(:type_cast)).to eq('TEXT') end end From 1831893295469616adc005f3db033f4efd0d13c3 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:15:40 +0100 Subject: [PATCH 032/364] Make custom_field? method public --- lib/ajax-datatables-rails/datatable/column.rb | 10 +++++----- .../datatable/column_spec.rb | 16 +++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 0dca7a3d..80626069 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -27,7 +27,7 @@ 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[options[:data].to_sym] end def data @@ -50,6 +50,10 @@ def field source.split('.').last.to_sym end + def custom_field? + !source.include?('.') + end + # Add formater option to allow modification of the value # before passing it to the database def formater @@ -62,10 +66,6 @@ def formated_value private - def custom_field? - !source.include?('.') - end - def config @config ||= AjaxDatatablesRails.config end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 850a5012..c4f44e8b 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -29,19 +29,19 @@ expect(column.data).to eq('username') end - describe 'data' do + describe '#data' do it 'should return the data from params' do expect(column.data).to eq 'username' end end - describe 'source' do + describe '#source' do it 'should return the data source from view_column' do expect(column.source).to eq 'User.username' end end - describe 'table' do + describe '#table' do context 'with ActiveRecord ORM' do it 'should return the corresponding AR table' do expect(column.table).to eq User.arel_table @@ -55,18 +55,24 @@ end end - describe 'model' do + describe '#model' do it 'should return the corresponding AR model' do expect(column.model).to eq User end end - describe 'field' do + describe '#field' do it 'should return 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 + expect(column.custom_field?).to be false + end + end + describe '#search' do it 'child class' do expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch) From d1960d4521ede8462694060be97403101028afd8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:33:41 +0100 Subject: [PATCH 033/364] Remove useless accessor --- lib/ajax-datatables-rails/base.rb | 7 ++----- lib/ajax-datatables-rails/datatable/column.rb | 6 +----- lib/ajax-datatables-rails/datatable/datatable.rb | 1 + 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index eef3cbdb..71cb674a 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -15,10 +15,6 @@ def initialize(view, options = {}) load_orm_extension end - def config - @config ||= AjaxDatatablesRails.config - end - def datatable @datatable ||= Datatable::Datatable.new(self) end @@ -119,7 +115,7 @@ def records_filtered_count # Private helper methods def load_orm_extension - case config.orm + case AjaxDatatablesRails.config.orm when :active_record extend ORM::ActiveRecord when :mongoid @@ -157,5 +153,6 @@ def view_columns_error_text or aliased_join_table.column_name notation. ERROR end + end end diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 80626069..fca931c8 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -66,12 +66,8 @@ def formated_value private - def config - @config ||= AjaxDatatablesRails.config - end - def type_cast - DB_ADAPTER_TYPE_CAST[config.db_adapter] || 'VARCHAR' + DB_ADAPTER_TYPE_CAST[AjaxDatatablesRails.config.db_adapter] || 'VARCHAR' end def casted_column diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index 6f375a54..44d4fc3c 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -76,6 +76,7 @@ def get_param(param) options[param].to_unsafe_h.with_indifferent_access end end + end end end From 5646adbd7ac42912aaf5fd427731d87968667542 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:39:11 +0100 Subject: [PATCH 034/364] Fix tests --- spec/ajax-datatables-rails/datatable/column_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index c4f44e8b..cbe903ab 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -117,9 +117,11 @@ end end - describe '#delimiter' do - it 'should be - by default' do - expect(column.delimiter).to eq('-') + unless AjaxDatatablesRails.old_rails? + describe '#delimiter' do + it 'should be - by default' do + expect(column.delimiter).to eq('-') + end end end end From b5e780687465793837701f5961dae8f6bd429099 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:41:03 +0100 Subject: [PATCH 035/364] Move method --- lib/ajax-datatables-rails/datatable/datatable.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index 44d4fc3c..e8218fbc 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -57,6 +57,10 @@ def paginate? per_page != -1 end + def per_page + options.fetch(:length, 10).to_i + end + def offset options.fetch(:start, 0).to_i end @@ -65,10 +69,6 @@ def page (options[:start].to_i / per_page) + 1 end - def per_page - options.fetch(:length, 10).to_i - end - def get_param(param) if AjaxDatatablesRails.old_rails? options[param] From 0c0d4f2e7f75bf783ead25b8e1c9342174915b0a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:42:20 +0100 Subject: [PATCH 036/364] Reuse existing method --- lib/ajax-datatables-rails/datatable/datatable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/datatable/datatable.rb b/lib/ajax-datatables-rails/datatable/datatable.rb index e8218fbc..c2db1d50 100644 --- a/lib/ajax-datatables-rails/datatable/datatable.rb +++ b/lib/ajax-datatables-rails/datatable/datatable.rb @@ -66,7 +66,7 @@ def offset end def page - (options[:start].to_i / per_page) + 1 + (offset / per_page) + 1 end def get_param(param) From 67ef51deb4314636a436148aae86a5d862bc88f9 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 03:47:35 +0100 Subject: [PATCH 037/364] Memoize some values --- lib/ajax-datatables-rails/datatable/column.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index fca931c8..f1889a3c 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -67,11 +67,11 @@ def formated_value private def type_cast - DB_ADAPTER_TYPE_CAST[AjaxDatatablesRails.config.db_adapter] || 'VARCHAR' + @type_cast ||= (DB_ADAPTER_TYPE_CAST[AjaxDatatablesRails.config.db_adapter] || 'VARCHAR') end def casted_column - ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(type_cast)]) + @casted_column ||= ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(type_cast)]) end end From 20da2eca3377af3b614413b00731bd5505f337a0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 18 Feb 2018 05:20:57 +0100 Subject: [PATCH 038/364] Use a class rather than OpenStruct for DateRange --- .../datatable/column/date_filter.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/date_filter.rb b/lib/ajax-datatables-rails/datatable/column/date_filter.rb index d12260c4..09296f4e 100644 --- a/lib/ajax-datatables-rails/datatable/column/date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column/date_filter.rb @@ -1,12 +1,23 @@ # frozen_string_literal: true -require 'ostruct' - module AjaxDatatablesRails module Datatable class Column module DateFilter + class DateRange + attr_reader :begin, :end + + def initialize(date_start, date_end) + @begin = date_start + @end = date_end + end + + def exclude_end? + false + end + end + # Add delimiter option to handle range search def delimiter @view_column[:delimiter] || '-' @@ -31,7 +42,7 @@ def range_end # Do a range search def date_range_search return nil if empty_range_search? - table[field].between(OpenStruct.new(begin: range_start_casted, end: range_end_casted)) + table[field].between(DateRange.new(range_start_casted, range_end_casted)) end private From ad9e292da24a7dcd306a90cc5903e6991b821664 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 20 Feb 2018 01:38:28 +0100 Subject: [PATCH 039/364] Fix https://github.com/jbox-web/ajax-datatables-rails/issues/245 --- lib/ajax-datatables-rails/orm/active_record.rb | 3 ++- .../orm/active_record_sort_records_spec.rb | 8 ++++++++ spec/support/test_helpers.rb | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index da82a10b..a30e7008 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -15,7 +15,8 @@ def filter_records(records) def sort_records(records) sort_by = datatable.orders.inject([]) do |queries, order| column = order.column - queries << order.query(column.sort_query) if column + queries << order.query(column.sort_query) if column && column.orderable? + queries end records.order(sort_by.join(', ')) 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 ccd19511..5ce77a70 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 @@ -29,6 +29,14 @@ 'ORDER BY users.username ASC, users.email DESC' ) end + + it 'should 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' } + expect(datatable.sort_records(records).to_sql).to_not include( + 'ORDER BY users.username ASC, users.post_id DESC' + ) + end end end diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index 97201b54..ffe760e8 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -60,7 +60,7 @@ def view_columns email: { source: 'User.email' }, first_name: { source: 'User.first_name' }, last_name: { source: 'User.last_name' }, - post_id: { source: 'User.post_id' }, + post_id: { source: 'User.post_id', orderable: false }, created_at: { source: 'User.created_at' }, } end From caaa96fe261d7f17250607d8e276309d86cd6660 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 20 Feb 2018 01:41:51 +0100 Subject: [PATCH 040/364] Improve test --- .../orm/active_record_sort_records_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 5ce77a70..c96ad46f 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 @@ -33,8 +33,13 @@ it 'should 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' } + + expect(datatable.sort_records(records).to_sql).to include( + 'ORDER BY users.username ASC' + ) + expect(datatable.sort_records(records).to_sql).to_not include( - 'ORDER BY users.username ASC, users.post_id DESC' + 'users.post_id DESC' ) end end From d2ed7de95a76908b7aea9448ce053060b0a7b4f4 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 20 Feb 2018 01:49:04 +0100 Subject: [PATCH 041/364] Memoize values that should not change --- lib/ajax-datatables-rails/datatable/column.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index f1889a3c..d1958a66 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -43,11 +43,11 @@ def table end def model - source.split('.').first.constantize + @model ||= source.split('.').first.constantize end def field - source.split('.').last.to_sym + @field ||= source.split('.').last.to_sym end def custom_field? From af0a2b974149d9e7682e0ea5c00e83da647c55f5 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 20 Feb 2018 02:04:32 +0100 Subject: [PATCH 042/364] Update changelog [ci skip] --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91bc78a2..376beac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # CHANGELOG +## 0.4.1 + +* Fix: Restore behavior of #filter method [Comment](https://github.com/jbox-web/ajax-datatables-rails/commit/07795fd26849ff1b3b567f4ce967f722907a45be#comments) +* Fix: Fix erroneous offset/start behavior [PR #264](https://github.com/jbox-web/ajax-datatables-rails/pull/264) +* Fix: "orderable" option has no effect [Issue #245](https://github.com/jbox-web/ajax-datatables-rails/issues/245) +* Change: Rename `additional_datas` method as `additional_data` [PR #251](https://github.com/jbox-web/ajax-datatables-rails/pull/251) +* Change: Added timezone support for daterange [PR #261](https://github.com/jbox-web/ajax-datatables-rails/pull/261) + +**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x + + ## 0.4.0 **Warning:** this version is a **major break** from v0.3. The core has been rewriten to remove dependency on Kaminari (or WillPaginate). From 0d8ad122acc4ed86ac918020e27087cacb9eb7a8 Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Mon, 19 Feb 2018 21:51:59 -0500 Subject: [PATCH 043/364] Add global and per column options to order null values last --- lib/ajax-datatables-rails/config.rb | 1 + .../datatable/column/order.rb | 5 ++++ .../datatable/simple_order.rb | 10 ++++++- .../datatable/column_spec.rb | 6 +++- .../datatable/simple_order_spec.rb | 29 +++++++++++++++++- .../orm/active_record_sort_records_spec.rb | 30 +++++++++++++++++++ spec/spec_helper.rb | 1 + spec/support/datatable_order_nulls_last.rb | 5 ++++ spec/support/test_helpers.rb | 3 ++ 9 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 spec/support/datatable_order_nulls_last.rb diff --git a/lib/ajax-datatables-rails/config.rb b/lib/ajax-datatables-rails/config.rb index c2b642dd..bbcb3c4d 100644 --- a/lib/ajax-datatables-rails/config.rb +++ b/lib/ajax-datatables-rails/config.rb @@ -26,5 +26,6 @@ class Configuration config_accessor(:orm) { :active_record } config_accessor(:db_adapter) { :postgresql } + config_accessor(:nulls_last) { false } end end diff --git a/lib/ajax-datatables-rails/datatable/column/order.rb b/lib/ajax-datatables-rails/datatable/column/order.rb index 39417f75..b793e6ad 100644 --- a/lib/ajax-datatables-rails/datatable/column/order.rb +++ b/lib/ajax-datatables-rails/datatable/column/order.rb @@ -18,6 +18,11 @@ def sort_query custom_field? ? source : "#{table.name}.#{sort_field}" end + # Add option to sort null values last + def nulls_last + @view_column[:nulls_last] || (@options[:nulls_last] == 'true') + 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 e35bf2a0..f10c6cdd 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -12,7 +12,11 @@ def initialize(datatable, options = {}) end def query(sort_column) - "#{sort_column} #{direction}" + if sort_nulls_last? + "CASE WHEN #{sort_column} IS NULL THEN 1 ELSE 0 END, #{sort_column} #{direction}" + else + "#{sort_column} #{direction}" + end end def column @@ -33,6 +37,10 @@ def column_direction @options[:dir].upcase end + def sort_nulls_last? + column.nulls_last == true || AjaxDatatablesRails.config.nulls_last == true + end + end end end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index cbe903ab..56b4c880 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -10,13 +10,17 @@ 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'}, 'nulls_last'=>'true'}} end it 'should be orderable' do expect(column.orderable?).to eq(true) end + it 'should sort nulls last' do + expect(column.nulls_last).to eq(true) + end + it 'should be searchable' do expect(column.searchable?).to eq(true) end diff --git a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb index 6e0a6695..9c851eb0 100644 --- a/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +++ b/spec/ajax-datatables-rails/datatable/simple_order_spec.rb @@ -2,12 +2,39 @@ describe AjaxDatatablesRails::Datatable::SimpleOrder do + let(:view) { double('view', params: sample_params) } + let(:datatable) { ComplexDatatable.new(view).datatable } let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'column' => '1', 'dir' => 'desc'}) } - let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(nil, options) } + let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) } describe 'option methods' do it 'sql query' do expect(simple_order.query('firstname')).to eq('firstname DESC') end 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 } + + it 'sql query' do + expect(simple_order.query('email')).to eq( + 'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC' + ) + end + end + + describe 'using column option' do + let(:sorted_datatable) { DatatableOrderNullsLast.new(view).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' + ) + 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 c96ad46f..128fceb8 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 @@ -4,6 +4,7 @@ let(:view) { double('view', params: sample_params) } let(:datatable) { ComplexDatatable.new(view) } + let(:nulls_last_datatable) { DatatableOrderNullsLast.new(view) } let(:records) { User.all } before(:each) do @@ -44,4 +45,33 @@ end end + 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 + 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' + ) + 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 + # by Users email in descending order + 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' + ) + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e006e6cd..aafab47d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -82,4 +82,5 @@ 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_order_nulls_last.rb' require File.dirname(__FILE__) + '/support/test_models.rb' diff --git a/spec/support/datatable_order_nulls_last.rb b/spec/support/datatable_order_nulls_last.rb new file mode 100644 index 00000000..f4d7f6d3 --- /dev/null +++ b/spec/support/datatable_order_nulls_last.rb @@ -0,0 +1,5 @@ +class DatatableOrderNullsLast < ComplexDatatable + def view_columns + super.deep_merge(email: { nulls_last: true }) + end +end diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index ffe760e8..550b6735 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -83,6 +83,9 @@ def get_raw_records end end +# class ComplexDatatableHash < ComplexDatatable +# end + class ComplexDatatableArray < ComplexDatatable def data records.map do |record| From 3d9dc6e92c2456abaa35a8e04a167754d510e3d2 Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Fri, 23 Mar 2018 11:12:22 -0400 Subject: [PATCH 044/364] Wrap order calls in Arel.sql to avoid Rails 6.0 deprecation warnings. --- lib/ajax-datatables-rails/orm/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index a30e7008..b4f7ad85 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -18,7 +18,7 @@ def sort_records(records) queries << order.query(column.sort_query) if column && column.orderable? queries end - records.order(sort_by.join(', ')) + records.order(Arel.sql(sort_by.join(', '))) end def paginate_records(records) From 574acb5c4993075a4449710efeaeaa4b7004ba32 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 17 Apr 2018 02:34:45 +0200 Subject: [PATCH 045/364] Test with latest versions of Rails --- .travis.yml | 17 +++++++++-------- Appraisals | 8 ++++++-- ...{rails_5.0.6.gemfile => rails_5.0.7.gemfile} | 2 +- ...{rails_5.1.5.gemfile => rails_5.1.6.gemfile} | 2 +- gemfiles/rails_5.2.0.gemfile | 13 +++++++++++++ 5 files changed, 30 insertions(+), 12 deletions(-) rename gemfiles/{rails_5.0.6.gemfile => rails_5.0.7.gemfile} (92%) rename gemfiles/{rails_5.1.5.gemfile => rails_5.1.6.gemfile} (92%) create mode 100644 gemfiles/rails_5.2.0.gemfile diff --git a/.travis.yml b/.travis.yml index ac1ad58c..d25cf8fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,36 +9,37 @@ gemfile: - gemfiles/rails_4.0.13.gemfile - gemfiles/rails_4.1.16.gemfile - gemfiles/rails_4.2.10.gemfile - - gemfiles/rails_5.0.6.gemfile - - gemfiles/rails_5.1.5.gemfile + - gemfiles/rails_5.0.7.gemfile + - gemfiles/rails_5.1.6.gemfile + - gemfiles/rails_5.2.0.gemfile matrix: include: - rvm: 2.4.3 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.3 - gemfile: gemfiles/rails_5.0.6.gemfile + gemfile: gemfiles/rails_5.0.7.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.3 - gemfile: gemfiles/rails_5.1.5.gemfile + gemfile: gemfiles/rails_5.1.6.gemfile env: DB_ADAPTER=postgresql - rvm: 2.4.3 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.3 - gemfile: gemfiles/rails_5.0.6.gemfile + gemfile: gemfiles/rails_5.0.7.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.3 - gemfile: gemfiles/rails_5.1.5.gemfile + gemfile: gemfiles/rails_5.1.6.gemfile env: DB_ADAPTER=mysql2 - rvm: 2.4.3 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=oracle_enhanced - rvm: 2.4.3 - gemfile: gemfiles/rails_5.0.6.gemfile + gemfile: gemfiles/rails_5.0.7.gemfile env: DB_ADAPTER=oracle_enhanced - rvm: 2.4.3 - gemfile: gemfiles/rails_5.1.5.gemfile + gemfile: gemfiles/rails_5.1.6.gemfile env: DB_ADAPTER=oracle_enhanced after_success: - bundle exec codeclimate-test-reporter diff --git a/Appraisals b/Appraisals index f43a3f78..de10f668 100644 --- a/Appraisals +++ b/Appraisals @@ -12,13 +12,17 @@ RAILS_VERSIONS = { '4.2.10' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.6.0' }, - '5.0.6' => { + '5.0.7' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.7.0', 'ruby-oci8' => '' }, - '5.1.5' => { + '5.1.6' => { 'activerecord-oracle_enhanced-adapter' => '~> 1.8.0', 'ruby-oci8' => '' + }, + '5.2.0' => { + 'activerecord-oracle_enhanced-adapter' => '~> 5.2.0', + 'ruby-oci8' => '' } }.freeze diff --git a/gemfiles/rails_5.0.6.gemfile b/gemfiles/rails_5.0.7.gemfile similarity index 92% rename from gemfiles/rails_5.0.6.gemfile rename to gemfiles/rails_5.0.7.gemfile index 86904ba2..e31d7c24 100644 --- a/gemfiles/rails_5.0.6.gemfile +++ b/gemfiles/rails_5.0.7.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "5.0.6" +gem "rails", "5.0.7" gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/gemfiles/rails_5.1.5.gemfile b/gemfiles/rails_5.1.6.gemfile similarity index 92% rename from gemfiles/rails_5.1.5.gemfile rename to gemfiles/rails_5.1.6.gemfile index 57e7ca9e..25ae1251 100644 --- a/gemfiles/rails_5.1.5.gemfile +++ b/gemfiles/rails_5.1.6.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org/" -gem "rails", "5.1.5" +gem "rails", "5.1.6" gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" diff --git a/gemfiles/rails_5.2.0.gemfile b/gemfiles/rails_5.2.0.gemfile new file mode 100644 index 00000000..f3b915c7 --- /dev/null +++ b/gemfiles/rails_5.2.0.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rails", "5.2.0" +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 ce67b6ae1da21cd501897b0e73a3c781978194bc Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 17 Apr 2018 02:37:59 +0200 Subject: [PATCH 046/364] Test with latest Ruby versions --- .travis.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index d25cf8fc..63c9957e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: ruby sudo: required cache: bundler rvm: - - 2.2.9 - - 2.3.6 + - 2.2.10 + - 2.3.7 gemfile: - gemfiles/rails_4.0.13.gemfile - gemfiles/rails_4.1.16.gemfile @@ -14,31 +14,31 @@ gemfile: - gemfiles/rails_5.2.0.gemfile matrix: include: - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_5.0.7.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_5.1.6.gemfile env: DB_ADAPTER=postgresql - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_5.0.7.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_5.1.6.gemfile env: DB_ADAPTER=mysql2 - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_4.2.10.gemfile env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_5.0.7.gemfile env: DB_ADAPTER=oracle_enhanced - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/rails_5.1.6.gemfile env: DB_ADAPTER=oracle_enhanced after_success: From 46afca5a016a395eeb2516a0813c7bfe2d3b8d34 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 17 Apr 2018 02:49:32 +0200 Subject: [PATCH 047/364] Fix test with Rails 4.2.10 --- gemfiles/rails_4.2.10.gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/gemfiles/rails_4.2.10.gemfile b/gemfiles/rails_4.2.10.gemfile index 3fb5d20d..e4d87c7b 100644 --- a/gemfiles/rails_4.2.10.gemfile +++ b/gemfiles/rails_4.2.10.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org/" gem "rails", "4.2.10" +gem "mysql2", "0.4.10" gem "activerecord-oracle_enhanced-adapter", "~> 1.6.0" gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced" From 690e25d1a2c0042a8aa4c7cf9e399886eef784ed Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 17 Apr 2018 03:10:43 +0200 Subject: [PATCH 048/364] Fix LoadError: cannot load such file -- bundler/dep_proxy --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 63c9957e..757da7e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,6 +54,8 @@ addons: - mysql-client-core-5.6 - mysql-client-5.6 before_install: + - gem update --system + - gem install bundler - 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 de87bfd046de9326ac414f54a7b4f7e4f207acdb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 01:01:26 +0200 Subject: [PATCH 049/364] Update README [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35b959b7..0326edb8 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ > This gem is targeted at Datatables version 1.10.x. > > It's tested against : -> * Rails 4.0.13 / 4.1.16 / 4.2.10 / 5.0.6 / 5.1.5 -> * Ruby 2.2.8 / 2.3.5 / 2.4.2 +> * 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 > * Postgresql > * MySQL > * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) From 16a999308409231a5314454936734cfc3247c21d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 01:05:28 +0200 Subject: [PATCH 050/364] Add tests for Rails 5.2.0 x Ruby 2.4.4 --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index 757da7e1..b05d792d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,9 @@ matrix: - 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 @@ -32,6 +35,9 @@ matrix: - 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 @@ -41,6 +47,9 @@ matrix: - 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: From bf23c7a8f284521a0473ae71f79f3962751c087f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 01:13:21 +0200 Subject: [PATCH 051/364] Update README [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0326edb8..17ce7f4c 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,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 -> * Postgresql -> * MySQL +> * Postgresql 9.6 +> * MySQL 5.6 > * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) ## Description From 55ce81d6c8127d4fb0e3db2fd5daa7087c31adeb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 01:19:15 +0200 Subject: [PATCH 052/364] Update README [ci skip] --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 17ce7f4c..936e92e3 100644 --- a/README.md +++ b/README.md @@ -573,7 +573,7 @@ class MyCustomDatatable < AjaxDatatablesRails::Base { id: check_box_tag('users[]', record.id), first_name: link_to(record.fname, edit_resource_path(record)), - email: mail_to(record.email) + email: mail_to(record.email), # other attributes } end @@ -583,15 +583,16 @@ 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. +On the long term it's much more cleaner than using `def_delegator` since decorators are reusable. ```ruby ... def data records.map do |record| { - id: record.decorate.id, + id: record.decorate.id, first_name: record.decorate.first_name, - email: record.decorate.email + email: record.decorate.email, # other attributes } end From da7fb0efa2e95927bc369394fad970e26d71e230 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 01:28:25 +0200 Subject: [PATCH 053/364] Coding style --- .rubocop.yml | 3 +++ lib/ajax-datatables-rails/datatable/column.rb | 4 +--- lib/generators/rails/datatable_generator.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b94fc819..d8a8671e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -32,6 +32,9 @@ Metrics/LineLength: Metrics/BlockLength: Max: 30 +Metrics/MethodLength: + Max: 15 + Metrics/ClassLength: Max: 130 diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index d1958a66..81ce4b77 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -18,10 +18,8 @@ class Column include Search include Order + prepend DateFilter unless AjaxDatatablesRails.old_rails? - unless AjaxDatatablesRails.old_rails? - prepend DateFilter - end def initialize(datatable, index, options) @datatable = datatable diff --git a/lib/generators/rails/datatable_generator.rb b/lib/generators/rails/datatable_generator.rb index 606016a7..5ef5afdb 100644 --- a/lib/generators/rails/datatable_generator.rb +++ b/lib/generators/rails/datatable_generator.rb @@ -6,7 +6,7 @@ module Rails module Generators class DatatableGenerator < ::Rails::Generators::Base desc 'Creates a *_datatable model in the app/datatables directory.' - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path('templates', __dir__) argument :name, type: :string def generate_datatable From df625c4fc94be330fa293c9070cd9fab5b65ca98 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 01:55:46 +0200 Subject: [PATCH 054/364] Coding style [ci skip] --- .rubocop.yml | 3 +++ lib/ajax-datatables-rails/orm/active_record.rb | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index d8a8671e..5786d29b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,6 +26,9 @@ Layout/EmptyLinesAroundModuleBody: Layout/EmptyLineBetweenDefs: Enabled: false +Metrics/CyclomaticComplexity: + Max: 7 + Metrics/LineLength: Enabled: false diff --git a/lib/ajax-datatables-rails/orm/active_record.rb b/lib/ajax-datatables-rails/orm/active_record.rb index a30e7008..0a10e984 100644 --- a/lib/ajax-datatables-rails/orm/active_record.rb +++ b/lib/ajax-datatables-rails/orm/active_record.rb @@ -12,6 +12,7 @@ def filter_records(records) records.where(build_conditions) end + # rubocop:disable Style/EachWithObject def sort_records(records) sort_by = datatable.orders.inject([]) do |queries, order| column = order.column @@ -20,6 +21,7 @@ def sort_records(records) end records.order(sort_by.join(', ')) end + # rubocop:enable Style/EachWithObject def paginate_records(records) records.offset(datatable.offset).limit(datatable.per_page) From 4ea4df2cbbc8f95b13a71d0ea1c53598019c11f0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 02:15:25 +0200 Subject: [PATCH 055/364] Update CHANGELOG [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376beac3..fb371ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fix: "orderable" option has no effect [Issue #245](https://github.com/jbox-web/ajax-datatables-rails/issues/245) * Change: Rename `additional_datas` method as `additional_data` [PR #251](https://github.com/jbox-web/ajax-datatables-rails/pull/251) * Change: Added timezone support for daterange [PR #261](https://github.com/jbox-web/ajax-datatables-rails/pull/261) +* Various improvements in internal API **Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x From d85e1daa34b796255e29bea38a05f51f9fcd8ef8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 02:40:35 +0200 Subject: [PATCH 056/364] Update README [ci skip] --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 936e92e3..9798a33a 100644 --- a/README.md +++ b/README.md @@ -583,7 +583,11 @@ 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. -On the long term it's much more cleaner than using `def_delegator` since decorators are reusable. +On the long term it's much more cleaner than using `def_delegator` since decorators are reusable so we strongly recommand you to +use Draper decorators. It will help you to keep your DataTables class small and clean and keep focused on what they should do (mostly) : filtering records ;) +The presentation layer should rely on Decorators class. + +Example : ```ruby ... @@ -591,13 +595,34 @@ On the long term it's much more cleaner than using `def_delegator` since decorat records.map do |record| { id: record.decorate.id, - first_name: record.decorate.first_name, + first_name: record.decorate.link_to, email: record.decorate.email, # other attributes + dt_actions: record.decorate.dt_actions, + DT_RowId: record.id, } end end ... + +class UserDecorator < ApplicationDecorator + delegate :id, :first_name + + def link_to + h.link_to first_name, h.user_path(object) + end + + def email + h.mail_to object.email + end + + def dt_actions + links = [] + links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update? + links << h.link_to 'Delete', h.user_path(object), remote: true if h.policy(object).destroy? + h.safe_join(links, '') + end +end ``` From 5fd462b754758c5db8650341066dcdea4a92b45f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 19 Apr 2018 02:43:25 +0200 Subject: [PATCH 057/364] Update README [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9798a33a..3b361cba 100644 --- a/README.md +++ b/README.md @@ -618,8 +618,8 @@ class UserDecorator < ApplicationDecorator def dt_actions links = [] - links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update? - links << h.link_to 'Delete', h.user_path(object), remote: true if h.policy(object).destroy? + links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update? + links << h.link_to 'Delete', h.user_path(object), method: :delete, remote: true if h.policy(object).destroy? h.safe_join(links, '') end end From 831087a9866917b41e52746c594751609131262c Mon Sep 17 00:00:00 2001 From: Nate Bird Date: Tue, 1 May 2018 19:19:46 -0400 Subject: [PATCH 058/364] Remove commented out code. --- spec/support/test_helpers.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index 550b6735..73c6e89b 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -82,9 +82,6 @@ def get_raw_records User.all end end - -# class ComplexDatatableHash < ComplexDatatable -# end class ComplexDatatableArray < ComplexDatatable def data From 18c0b9e5730897aa8c024af230944c573eea5ae9 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 5 May 2018 09:13:42 +0200 Subject: [PATCH 059/364] Coding style --- lib/ajax-datatables-rails/datatable/column/order.rb | 4 ++-- lib/ajax-datatables-rails/datatable/simple_order.rb | 2 +- spec/ajax-datatables-rails/datatable/column_spec.rb | 2 +- spec/support/test_helpers.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/order.rb b/lib/ajax-datatables-rails/datatable/column/order.rb index b793e6ad..89319d69 100644 --- a/lib/ajax-datatables-rails/datatable/column/order.rb +++ b/lib/ajax-datatables-rails/datatable/column/order.rb @@ -19,8 +19,8 @@ def sort_query end # Add option to sort null values last - def nulls_last - @view_column[:nulls_last] || (@options[:nulls_last] == 'true') + def nulls_last? + @view_column[:nulls_last] || @options[:nulls_last] == 'true' end end diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index f10c6cdd..41e8b934 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -38,7 +38,7 @@ def column_direction end def sort_nulls_last? - column.nulls_last == true || AjaxDatatablesRails.config.nulls_last == true + column.nulls_last? || AjaxDatatablesRails.config.nulls_last == true end end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 56b4c880..760ccf09 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -18,7 +18,7 @@ end it 'should sort nulls last' do - expect(column.nulls_last).to eq(true) + expect(column.nulls_last?).to eq(true) end it 'should be searchable' do diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index 73c6e89b..ffe760e8 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -82,7 +82,7 @@ def get_raw_records User.all end end - + class ComplexDatatableArray < ComplexDatatable def data records.map do |record| From 05b1565fc927cfea6b89fc4aba34541b33b25f7f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sat, 5 May 2018 09:16:34 +0200 Subject: [PATCH 060/364] :nulls_last is optin and cannot be set from request params --- lib/ajax-datatables-rails/datatable/column/order.rb | 2 +- spec/ajax-datatables-rails/datatable/column_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column/order.rb b/lib/ajax-datatables-rails/datatable/column/order.rb index 89319d69..2c784781 100644 --- a/lib/ajax-datatables-rails/datatable/column/order.rb +++ b/lib/ajax-datatables-rails/datatable/column/order.rb @@ -20,7 +20,7 @@ def sort_query # Add option to sort null values last def nulls_last? - @view_column[:nulls_last] || @options[:nulls_last] == 'true' + @view_column.fetch(:nulls_last, false) end end diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index 760ccf09..7e540d2a 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -10,7 +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'}, 'nulls_last'=>'true'}} + datatable.params[:columns] = {'0'=>{'data'=>'username', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} end it 'should be orderable' do @@ -18,7 +18,7 @@ end it 'should sort nulls last' do - expect(column.nulls_last?).to eq(true) + expect(column.nulls_last?).to eq(false) end it 'should be searchable' do From 968de7cabb82401df66947bc8638fe1116ca1b36 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 00:38:16 +0200 Subject: [PATCH 061/364] Update README [ci skip] --- README.md | 693 +++++++++++++++++++++++-------------------------- doc/webpack.md | 50 ++++ 2 files changed, 381 insertions(+), 362 deletions(-) create mode 100644 doc/webpack.md diff --git a/README.md b/README.md index 3b361cba..21d65dd6 100644 --- a/README.md +++ b/README.md @@ -8,57 +8,53 @@ [![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. -> -> 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 -> * Postgresql 9.6 -> * MySQL 5.6 -> * Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) +**Important : This gem is targeted at DataTables version 1.10.x.** -## Description +It's tested against : -[Datatables](https://datatables.net/) is a nifty jquery plugin that adds the ability to paginate, sort, -and search your html tables. When dealing with large tables -(more than a couple hundred rows) however, we run into performance issues. -These can be fixed by using server-side pagination, but this breaks some -datatables functionality. +* 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 +* Postgresql 9.6 +* MySQL 5.6 +* Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle)) +* SQLite3 -`ajax-datatables-rails` is a wrapper around datatable's ajax methods that allow -synchronization with server-side pagination in a rails app. It was inspired by -this [Railscast](http://railscasts.com/episodes/340-datatables). I needed to -implement a similar solution in a couple projects I was working on, so I -extracted a solution into a gem. +## Description -The final goal of this gem is to **generate a JSON** content that will be given to JQuery Datatable. -All the datatable customizations (header, tr, td, css classes, width, height, etc, etc) **must** take place in the [javascript definition](#wire-up-the-javascript) of the datatable. -JQuery Datatable is a very powerful tool with a lot of customizations available. Take the time to [read the doc](https://datatables.net/reference/option/). +> [DataTables](https://datatables.net/) is a nifty jQuery plugin that adds the ability to paginate, sort, and search your html tables. +> When dealing with large tables (more than a couple of hundred rows) however, we run into performance issues. +> These can be fixed by using server-side pagination, but this breaks some DataTables functionality. +> +> `ajax-datatables-rails` is a wrapper around DataTables ajax methods that allow synchronization with server-side pagination in a Rails app. +> It was inspired by this [Railscast](http://railscasts.com/episodes/340-datatables). +> I needed to implement a similar solution in a couple projects I was working on, so I extracted a solution into a gem. +> +> Joel Quenneville (original author) +> +> I needed a good gem to manage a lot of DataTables so I chose this one :) +> +> Nicolas Rodriguez (current maintainer) -## ORM support +The final goal of this gem is to **generate a JSON** content that will be given to jQuery DataTables. +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/). -Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for -performing database queries. -Adding support for `Sequel`, `Mongoid` and `MongoMapper` is a planned feature -for this gem. If you'd be interested in contributing to speed development, -please [open an issue](https://github.com/antillas21/ajax-datatables-rails/issues/new) -and get in touch. +## Warning +**Breaking changes :** the *v0.4* version is a **major break** from *v0.3*. -## Breaking changes +The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). -**Warning:** the v0.4 version is a **major break** from v0.3. The core has been rewriten to remove dependency on Kaminari (or WillPaginate). +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. -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](#customize-the-generated-datatables-class) for more infos. +[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](#wire-up-the-javascript)) +* update your views to declare your columns bindings ([See here](#5-wire-up-the-javascript)) ## Installation @@ -66,33 +62,81 @@ To migrate on the v0.4 you'll need to : Add these lines to your application's Gemfile: ```ruby -gem 'jquery-datatables-rails' gem 'ajax-datatables-rails' ``` And then execute: ```sh -$ bundle +$ bundle install ``` -The `jquery-datatables-rails` gem is listed as a convenience, to ease adding -jQuery dataTables to your Rails project. You can always add the plugin assets -manually via the assets pipeline. If you decide to use the -`jquery-datatables-rails` gem, please refer to its installation instructions -[here](https://github.com/rweng/jquery-datatables-rails). +We assume here that you have already installed [jQuery DataTables](https://datatables.net/). + +You can install jQuery DataTables : +* with the [`jquery-datatables-rails`](https://github.com/rweng/jquery-datatables-rails) gem (which is a bit outdated) +* 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) -## Usage -*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__, if not, please refer to the -[Searching on non text-based columns](#searching-on-non-text-based-columns) -entry in the Additional Notes section.* +## Configuration +Generate the `ajax-datatables-rails` config file with this command : -### Generate +```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 + + # 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. + +Adding support for `Sequel`, `Mongoid` and `MongoMapper` is (more or less) a planned feature for this gem. + +If you'd be interested in contributing to speed development, please [open an issue](https://github.com/antillas21/ajax-datatables-rails/issues/new) and get in touch. + + +## 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)) + +The goal is to render a users table and display : `id`, `first name`, `last name`, `email`, and `bio` for each user. + +Something like this: + +|ID |First Name|Last Name|Email |Brief Bio| +|---|----------|---------|----------------------|---------| +| 1 |John |Doe |john.doe@example.net |Is your default user everywhere| +| 2 |Jane |Doe |jane.doe@example.net |Is John's wife| +| 3 |James |Doe |james.doe@example.net |Is John's brother and best friend| + +Here the steps we're going through : + +1. [Generate the datatable class](#1-generate-the-datatable-class) +2. [Build the View](#2-build-the-view) +3. [Customize the generated Datatables class](#3-customize-the-generated-datatables-class) +4. [Setup the Controller action](#4-setup-the-controller-action) +5. [Wire up the Javascript](#5-wire-up-the-javascript) + +### 1) Generate the datatable class Run the following command: @@ -106,31 +150,24 @@ Open the file and customize in the functions as directed by the comments. Take a look [here](#generator-syntax) for an explanation about the generator syntax. -### Build the View - -You should always start by the single source of truth, which is your html view. Suppose we need to render a users table and display: first name, last name, and bio for each user. - -Something like this: - -|First Name|Last Name|Brief Bio| -|----------|---------|---------| -|John |Doe |Is your default user everywhere| -|Jane |Doe |Is John's wife| -|James |Doe |Is John's brother and best friend| +### 2) Build the View +You should always start by the single source of truth, which is your html view. * Set up an html `` with a `` and `` * Add in your table headers if desired -* Don't add any rows to the body of the table, datatables does this automatically +* Don't add any rows to the body of the table, DataTables does this automatically * Add a data attribute to the `
` tag with the url of the JSON feed, in our case is the `users_path` as we're pointing to the `UsersController#index` action ```html -
+
+ + @@ -140,25 +177,22 @@ Something like this: ``` -### Customize the generated Datatables class +### 3) Customize the generated Datatables class -```ruby -def view_columns - # Declare strings in this format: ModelName.column_name - # or in aliased_join_table.column_name format - @view_columns ||= {} -end -``` +#### a. Declare columns mapping -* In this method, add a list of the model(s) columns mapped to the data you need to present. In this case: `first_name`, `last_name` and `bio`. +First we need to declare in `view_columns` the list of the model(s) columns mapped to the data we need to present. +In this case: `id`, `first_name`, `last_name`, `email` and `bio`. This gives us: ```ruby 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 }, + email: { source: "User.email" }, bio: { source: "User.bio" }, } end @@ -174,48 +208,28 @@ 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) -[See here](#searching-on-non-text-based-columns) for notes about the `view_columns` settings (if using something different from `postgres`). -[Read these notes](#columns-syntax) about considerations for the `view_columns` method. - +See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models. -#### Map data +#### b. Map data -```ruby -def data - records.map do |record| - { - # a hash of key value pairs - } - end -end -``` +Then we need to map the records retrieved by the `get_raw_records` method to the real values we want to display : ```ruby def data records.map do |record| { + id: record.id, first_name: record.first_name, 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 set the id attribute on the corresponding in the datatable } end end ``` - You can either use the v0.3 Array style for your columns : -```ruby -def data - records.map do |record| - [ - # comma separated list of the values for each cell of a table row - # example: record.first_name, record.last_name - ] - end -end -``` - This method builds a 2d array that is used by datatables to construct the html table. Insert the values you want on each column. @@ -223,30 +237,26 @@ table. Insert the values you want on each column. def data records.map do |record| [ + record.id, record.first_name, record.last_name, + record.email, record.bio ] end end ``` -[See here](#using-view-helpers) if you need to use view helpers like `link_to`, `mail_to`, `resource_path`, etc. - +The drawback of this method is that you can't pass the `DT_RowId` so it's tricky to set the id attribute on the corresponding `` in the datatable (need to be done on JS side). -#### Get Raw Records +[See here](#using-view-helpers) if you need to use view helpers like `link_to`, `mail_to`, etc... -```ruby -def get_raw_records - # insert query here -end -``` +#### c. Get Raw Records This is where your query goes. ```ruby def get_raw_records - # suppose we need all User records User.all end ``` @@ -261,100 +271,12 @@ def get_raw_records end ``` -You can put any logic in `get_raw_records` [based on any parameters you inject](#options) in the `Datatable` object. - -> __IMPORTANT:__ Make sure to return an `ActiveRecord::Relation` object -> as the end product of this method. -> -> Why? Because the result from this method, will be chained (for now) -> to `ActiveRecord` methods for sorting, filtering and pagination. - - -#### Associated and nested models - -The previous example has only one single model. But what about if you have -some associated nested models and in a report you want to show fields from -these tables. - -Take an example that has an `Event, Course, Coursetype, Allocation, Teacher, -Contact, Competency and CompetencyType` models. We want to have a datatables -report which has the following column: +You can put any logic in `get_raw_records` [based on any parameters you inject](#pass-options-to-the-datatable-class) in the `Datatable` object. -```ruby -'coursetypes.name', -'courses.name', -'events.title', -'events.event_start', -'events.event_end', -'contacts.full_name', -'competency_types.name', -'events.status' -``` +**IMPORTANT :** Because the result of this method will be chained to `ActiveRecord` methods for sorting, filtering and pagination, +make sure to return an `ActiveRecord::Relation` object. -We want to sort and search on all columns of the list. The related definition -would be: - -```ruby -def view_columns - @view_columns ||= [ - 'Coursetype.name', - 'Course.name', - 'Event.title', - 'Event.event_start', - 'Event.event_end', - 'Contact.last_name', - 'CompetencyType.name', - 'Event.status' - ] -end - -def get_raw_records - Event.joins( - { course: :coursetype }, - { allocations: { - teacher: [:contact, {competencies: :competency_type}] - } - }).distinct -end -``` - -__Some comments for the above code:__ - -1. In the `get_raw_records` method we have quite a complex query having one to -many and many to many associations using the joins ActiveRecord method. -The joins will generate INNER JOIN relations in the SQL query. In this case, -we do not include all event in the report if we have events which is not -associated with any model record from the relation. - -2. To have all event records in the list we should use the `.includes` method, -which generate LEFT OUTER JOIN relation of the SQL query. -__IMPORTANT:__ Make sure to append `.references(:related_model)` with any -associated model. That forces the eager loading of all the associated models -by one SQL query, and the search condition for any column works fine. -Otherwise the `:recordsFiltered => filter_records(get_raw_records).count(:all)` -will generate 2 SQL queries (one for the Event model, and then another for the -associated tables). The `:recordsFiltered => filter_records(get_raw_records).count(:all)` -will use only the first one to return from the ActiveRecord::Relation object -in `get_raw_records` and you will get an error message of __Unknown column -'yourtable.yourfield' in 'where clause'__ in case the search field value -is not empty. - -So the query using the `.includes()` method is: - -```ruby -def get_raw_records - Event.includes( - { course: :coursetype }, - { allocations: { - teacher: [:contact, { competencies: :competency_type }] - } - } - ).references(:course).distinct -end -``` - - -#### Additional data +#### d. Additional data You can inject other key/value pairs in the rendered JSON by defining the `#additional_data` method : @@ -369,7 +291,7 @@ end Very useful with https://github.com/vedmack/yadcf to provide values for dropdown filters. -### Setup the Controller action +### 4) Setup the Controller action Set the controller to respond to JSON @@ -384,9 +306,9 @@ end Don't forget to make sure the proper route has been added to `config/routes.rb`. -[See here](#options) to inject params in the `UserDatatable`. +[See here](#pass-options-to-the-datatable-class) if you need to inject params in the `UserDatatable`. -### Wire up the Javascript +### 5) Wire up the Javascript Finally, the javascript to tie this all together. In the appropriate `coffee` file: @@ -394,14 +316,16 @@ Finally, the javascript to tie this all together. In the appropriate `coffee` fi # users.coffee $ -> - $('#users-table').dataTable + $('#users-datatable').dataTable processing: true serverSide: true - ajax: $('#users-table').data('source') + ajax: $('#users-datatable').data('source') pagingType: 'full_numbers' columns: [ + {data: 'id'} {data: 'first_name'} {data: 'last_name'} + {data: 'email'} {data: 'bio'} ] # pagingType is optional, if you want full pagination controls. @@ -410,18 +334,21 @@ $ -> ``` or, if you're using plain javascript: + ```javascript // users.js jQuery(document).ready(function() { - $('#users-table').dataTable({ + $('#users-datatable').dataTable({ "processing": true, "serverSide": true, - "ajax": $('#users-table').data('source'), + "ajax": $('#users-datatable').data('source'), "pagingType": "full_numbers", "columns": [ + {"data": "id"}, {"data": "first_name"}, {"data": "last_name"}, + {"data": "email"}, {"data": "bio"} ] // pagingType is optional, if you want full pagination controls. @@ -431,150 +358,38 @@ jQuery(document).ready(function() { }); ``` +## Advanced usage -### Additional Notes - -#### Columns syntax - -Since version `0.3.0`, we are implementing a pseudo code way of declaring -the array columns to use when querying the database. - -Example. Suppose we have the following models: `User`, `PurchaseOrder`, -`Purchase::LineItem` and we need to have several columns from those models -available in our datatable to search and sort by. - -```ruby -# we use the ModelName.column_name notation to declare our columns - -def view_columns - @view_columns ||= [ - 'User.first_name', - 'User.last_name', - 'PurchaseOrder.number', - 'PurchaseOrder.created_at', - 'Purchase::LineItem.quantity', - 'Purchase::LineItem.unit_price', - 'Purchase::LineItem.item_total' - ] -end -``` - +### Using view helpers -#### What if the datatable itself is namespaced? - -Example: what if the datatable is namespaced into an `Admin` module? - -```ruby -module Admin - class PurchasesDatatable < AjaxDatatablesRails::Base - end -end -``` - -Taking the same models and columns, we would define it like this: - -```ruby -def view_columns - @view_columns ||= [ - '::User.first_name', - '::User.last_name', - '::PurchaseOrder.number', - '::PurchaseOrder.created_at', - '::Purchase::LineItem.quantity', - '::Purchase::LineItem.unit_price', - '::Purchase::LineItem.item_total' - ] -end -``` - -Pretty much like you would do it, if you were inside a namespaced controller. - - -#### Searching on non text-based columns - -It always comes the time when you need to add a non-string/non-text based -column to the `@view_columns` array, so you can perform searches against -these column types (example: numeric, date, time). - -We recently added the ability to (automatically) typecast these column types -and have this scenario covered. Please note however, if you are using -something different from `postgresql` (with the `:pg` gem), like `mysql` or -`sqlite`, then you need to add an initializer in your application's -`config/initializers` directory. - -If you don't perform this step (again, if using something different from -`postgresql`), your database will complain that it does not understand the -default typecast used to enable such searches. - - -#### Configuration initializer - -You have two options to create this initializer: - -* use the provided (and recommended) generator (and then just edit the file); -* create the file from scratch. - -To use the generator, from the terminal execute: - -```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 - - # 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`. - -If you want to make the file from scratch, just copy the above code block into -a file inside the `config/initializers` directory. - - -#### Using view helpers - -Sometimes you'll need to use view helper methods like `link_to`, `h`, `mailto`, -`edit_resource_path`, `check_box_tag` in the returned JSON representation returned by the `data` -method. +Sometimes you'll need to use view helper methods like `link_to`, `mail_to`, +`edit_user_path`, `check_box_tag` and so on in the returned JSON representation returned by the [`data`](#b-map-data) method. To have these methods available to be used, this is the way to go: ```ruby class MyCustomDatatable < AjaxDatatablesRails::Base # either define them one-by-one + def_delegator :@view, :check_box_tag def_delegator :@view, :link_to - def_delegator :@view, :h def_delegator :@view, :mail_to + def_delegator :@view, :edit_user_path # or define them in one pass - def_delegators :@view, :link_to, :h, :mailto, :edit_resource_path, :check_box_tag, :other_method + def_delegators :@view, :check_box_tag, :link_to, :mail_to, :edit_user_path - # Define columns as described above for `id`, `first_name`, `email`, and others - def view_columns - ... - end + # ... other methods (view_columns, get_raw_records...) # now, you'll have these methods available to be used anywhere - # example: mapping the 2d jsonified array returned. def data records.map do |record| { id: check_box_tag('users[]', record.id), - first_name: link_to(record.fname, edit_resource_path(record)), + first_name: link_to(record.first_name, edit_user_path(record)), + last_name: record.last_name, email: mail_to(record.email), - # other attributes + bio: record.bio + DT_RowId: record.id, } end end @@ -583,9 +398,6 @@ 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. -On the long term it's much more cleaner than using `def_delegator` since decorators are reusable so we strongly recommand you to -use Draper decorators. It will help you to keep your DataTables class small and clean and keep focused on what they should do (mostly) : filtering records ;) -The presentation layer should rely on Decorators class. Example : @@ -594,11 +406,11 @@ Example : def data records.map do |record| { - id: record.decorate.id, + id: record.decorate.check_box, first_name: record.decorate.link_to, + last_name: record.decorate.last_name email: record.decorate.email, - # other attributes - dt_actions: record.decorate.dt_actions, + bio: record.decorate.bio DT_RowId: record.id, } end @@ -606,16 +418,23 @@ Example : ... class UserDecorator < ApplicationDecorator - delegate :id, :first_name + delegate :last_name, :bio + + def check_box + h.check_box_tag 'users[]', object.id + end def link_to - h.link_to first_name, h.user_path(object) + h.link_to object.first_name, h.edit_user_path(object) end def email h.mail_to object.email end + # Just an example of a complex method you can add to you decorator + # To render it in a datatable just add a column 'dt_actions' in + # 'view_columns' and 'data' methods and call record.decorate.dt_actions def dt_actions links = [] links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update? @@ -625,46 +444,164 @@ 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 :) -#### Options +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 ;) -An `AjaxDatatablesRails::Base` inherited class can accept an options hash at -initialization. This provides room for flexibility when required. Example: +**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 :) + +### 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. + +Example: ```ruby -class UnrespondedMessagesDatatable < AjaxDatatablesRails::Base - # customized methods here +# In the controller +def index + respond_to do |format| + format.html + format.json { render json: UserDatatable.new(view_context, user: current_user, from: 1.month.ago) } + end end -datatable = UnrespondedMessagesDatatable.new(view_context, - { user: current_user, from: 1.month.ago } -) +# The datatable class +class UnrespondedMessagesDatatable < AjaxDatatablesRails::Base + + # ... other methods (view_columns, data...) + + def user + @user ||= options[:user] + end + + def from + @from ||= options[:from].beginning_of_day + end + + def to + @to ||= Date.today.end_of_day + end + + # We can now customize the get_raw_records method + # with the options we've injected + def get_raw_records + user.messages.unresponded.where(received_at: from..to) + end + +end ``` -So, now inside your class code, you can use those options like this: +### Columns syntax +You can mix several model in the same datatable. + +Suppose we have the following models: `User`, `PurchaseOrder`, +`Purchase::LineItem` and we need to have several columns from those models +available in our datatable to search and sort by. ```ruby -# let's see an example -def user - @user ||= options[:user] -end +# we use the ModelName.column_name notation to declare our columns -def from - @from ||= options[:from].beginning_of_day +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' + } end +``` + +### Associated and nested models + +The previous example has only one single model. But what about if you have +some associated nested models and in a report you want to show fields from +these tables. + +Take an example that has an `Event, Course, CourseType, Allocation, Teacher, +Contact, Competency and CompetencyType` models. We want to have a datatables +report which has the following column: -def to - @to ||= Date.today.end_of_day +```ruby +'course_types.name' +'courses.name' +'contacts.full_name' +'competency_types.name' +'events.title' +'events.event_start' +'events.event_end' +'events.status' +``` + +We want to sort and search on all columns of the list. +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', + } end def get_raw_records - user.messages.unresponded.where(received_at: from..to) + Event.joins( + { course: :course_type }, + { allocations: { + teacher: [:contact, { competencies: :competency_type }] + } + }).distinct end ``` +**Some comments for the above code :** + +1. In the `get_raw_records` method we have quite a complex query having one to +many and many to many associations using the joins ActiveRecord method. +The joins will generate INNER JOIN relations in the SQL query. In this case, +we do not include all event in the report if we have events which is not +associated with any model record from the relation. + +2. To have all event records in the list we should use the `.includes` method, +which generate LEFT OUTER JOIN relation of the SQL query. + +**IMPORTANT :** + +Make sure to append `.references(:related_model)` with any +associated model. That forces the eager loading of all the associated models +by one SQL query, and the search condition for any column works fine. +Otherwise the `:recordsFiltered => filter_records(get_raw_records).count(:all)` +will generate 2 SQL queries (one for the Event model, and then another for the +associated tables). The `:recordsFiltered => filter_records(get_raw_records).count(:all)` +will use only the first one to return from the ActiveRecord::Relation object +in `get_raw_records` and you will get an error message of **Unknown column +'yourtable.yourfield' in 'where clause'** in case the search field value +is not empty. + +So the query using the `.includes()` method is: + +```ruby +def get_raw_records + Event.includes( + { course: :course_type }, + { allocations: { + teacher: [:contact, { competencies: :competency_type }] + } + }).references(:course).distinct +end +``` -#### Generator Syntax +### Generator Syntax Also, a class that inherits from `AjaxDatatablesRails::Base` is not tied to an existing model, module, constant or any type of class in your Rails app. @@ -686,19 +623,51 @@ 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 -## Tutorial +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: -Tutorial for Integrating `ajax-datatables-rails` on Rails 4. +```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 -[Part-1 The-Installation](https://github.com/jbox-web/ajax-datatables-rails/wiki/Part-1----The-Installation) +Install [yajl-ruby](https://github.com/brianmario/yajl-ruby), basically : + +```ruby +gem 'yajl-ruby', require: 'yajl' +``` -[Part 2 The Datatables with ajax functionality](https://github.com/jbox-web/ajax-datatables-rails/wiki/Part-2-The-Datatables-with-ajax-functionality) +then -The complete project code for this tutorial series is available on [github](https://github.com/trkrameshkumar/simple_app). +```sh +$ bundle install +``` -Another sample project [code](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to). Its real world example. +That's all :) ([Automatically prefer Yajl or JSON backend over Yaml, if available](https://github.com/rails/rails/commit/63bb955a99eb46e257655c93dd64e86ebbf05651)) +## 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. ## Contributing diff --git a/doc/webpack.md b/doc/webpack.md new file mode 100644 index 00000000..e0d001e0 --- /dev/null +++ b/doc/webpack.md @@ -0,0 +1,50 @@ +### Webpack + +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 datatables.net +$ yarn add datatables.net-bs +$ yarn add datatables.net-buttons +$ yarn add datatables.net-buttons-bs +$ yarn add datatables.net-responsive +$ yarn add datatables.net-responsive-bs +$ yarn add datatables.net-select +$ yarn add datatables.net-select-bs +``` + +In `config/webpack/loaders/datatables.js` : + +```js +module.exports = { + test: /datatables\.net.*/, + loader: 'imports-loader?define=>false' +} +``` + +In `config/webpack/environment.js` : + +```js +const { environment } = require('@rails/webpacker') +const datatables = require('./loaders/datatables') +environment.loaders.append('datatables', datatables) +module.exports = environment +``` + +in `app/javascript/pack/application.js` : + +```js +// Load Datatables +require('datatables.net-bs')(window, $) +require('datatables.net-buttons-bs')(window, $) +require('datatables.net-buttons/js/buttons.colVis.js')(window, $) +require('datatables.net-buttons/js/buttons.html5.js')(window, $) +require('datatables.net-buttons/js/buttons.print.js')(window, $) +require('datatables.net-responsive-bs')(window, $) +require('datatables.net-select')(window, $) +// require('yadcf')(window, $) // Uncomment if you use yadcf (need a recent version of yadcf) +``` From 5e04caeda0d1271a25b5ab50bfafb39f11be76d8 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 04:33:41 +0200 Subject: [PATCH 062/364] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb371ca3..96b71e50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * Fix: Restore behavior of #filter method [Comment](https://github.com/jbox-web/ajax-datatables-rails/commit/07795fd26849ff1b3b567f4ce967f722907a45be#comments) * Fix: Fix erroneous offset/start behavior [PR #264](https://github.com/jbox-web/ajax-datatables-rails/pull/264) * Fix: "orderable" option has no effect [Issue #245](https://github.com/jbox-web/ajax-datatables-rails/issues/245) +* Fix: Fix undefined method #and [PR #235](https://github.com/jbox-web/ajax-datatables-rails/pull/235) +* Add: Add "order nulls last" option [PR #79](https://github.com/jbox-web/ajax-datatables-rails/pull/279) * Change: Rename `additional_datas` method as `additional_data` [PR #251](https://github.com/jbox-web/ajax-datatables-rails/pull/251) * Change: Added timezone support for daterange [PR #261](https://github.com/jbox-web/ajax-datatables-rails/pull/261) * Various improvements in internal API From 82633ef948ed57bea482192cf90e0f0a1de4d277 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 04:41:21 +0200 Subject: [PATCH 063/364] Add release dates in CHANGELOG --- CHANGELOG.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b71e50..f042b0af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 0.4.1 +## 0.4.1 (to come) * Fix: Restore behavior of #filter method [Comment](https://github.com/jbox-web/ajax-datatables-rails/commit/07795fd26849ff1b3b567f4ce967f722907a45be#comments) * Fix: Fix erroneous offset/start behavior [PR #264](https://github.com/jbox-web/ajax-datatables-rails/pull/264) @@ -14,16 +14,16 @@ **Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x -## 0.4.0 +## 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). 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. Take a look at the [README](https://github.com/jbox-web/ajax-datatables-rails#customize-the-generated-datatables-class) for more infos. -## 0.3.1 +## 0.3.1 (2015-07-13) * Adds `:oracle` as supported `db_adapter`. Thanks to [lutechspa](https://github.com/lutechspa) for this contribution. -## 0.3.0 +## 0.3.0 (2015-01-30) * Changes to the `sortable_columns` and `searchable_columns` syntax as it required us to do unnecessary guessing. New syntax is `ModelName.column_name` or `Namespace::ModelName.column_name`. Old syntax of `table_name.column_name` @@ -34,7 +34,7 @@ It also brings a new (more natural) way of defining columns, based on hash defin for this contribution. * Moves paginator settings to configuration initializer. -## 0.2.1 +## 0.2.1 (2014-11-26) * Fix count method to work with select statements under Rails 4.1. Thanks to [Jason Mitchell](https://github.com/mitchej123) for the contribution. * Edits to `README` documentation about the `options` hash. Thanks to @@ -52,22 +52,22 @@ text-based columns and perform searches depending on the use of `:mysql2`, `:sqlite3` or `:pg`. Thanks to [M. Saiqul Haq](https://github.com/saiqulhaq) for contributing this feature. -## 0.2.0 +## 0.2.0 (2014-06-19) * This version works with jQuery dataTables ver. 1.10 and it's new API syntax. * Added `legacy` branch to repo. If your project is working with jQuery dataTables ver. 1.9, this is the branch you need to pull, or use the last `0.1.x` version of this gem. -## 0.1.2 +## 0.1.2 (2014-06-18) * Fixes `where` clause being built even when search term is an empty string. Thanks to [e-fisher](https://github.com/e-fisher) for spotting and fixing this. -## 0.1.1 +## 0.1.1 (2014-06-13) * Fixes problem on `searchable_columns` where the corresponding model is a composite model name, e.g. `UserData`, `BillingAddress`. Thanks to [iruca3](https://github.com/iruca3) for the fix. -## 0.1.0 +## 0.1.0 (2014-05-21) * A fresh start. Sets base class name to: `AjaxDatatablesRails::Base`. * Extracts pagination functions to mixable modules. * A user would have the option to stick to the base @@ -85,3 +85,7 @@ Thanks to [iruca3](https://github.com/iruca3) for the fix. * Sets generator inside the `Rails` namespace. To generate an `AjaxDatatablesRails` child class, just execute the generator like this: `$ rails generate datatable NAME`. + +## 0.0.1 (2012-09-10) + +First release! From 94ba6a168de4777e64db928e1b3f67a250ab5d16 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 04:47:47 +0200 Subject: [PATCH 064/364] Update README [ci skip] --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 21d65dd6..ef13fe62 100644 --- a/README.md +++ b/README.md @@ -665,10 +665,13 @@ $ bundle install ``` That's all :) ([Automatically prefer Yajl or JSON backend over Yaml, if available](https://github.com/rails/rails/commit/63bb955a99eb46e257655c93dd64e86ebbf05651)) + ## 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. +Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277) + ## Contributing 1. Fork it From 30095db7afb0bad70fe879a4fa862fcab8e3e0f6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 04:53:33 +0200 Subject: [PATCH 065/364] Fix https://github.com/jbox-web/ajax-datatables-rails/issues/144 --- .../datatable/templates/ajax_datatables_rails_config.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb index 52fa23cb..321f7d6b 100644 --- a/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +++ b/lib/generators/datatable/templates/ajax_datatables_rails_config.rb @@ -4,6 +4,9 @@ # 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 + # available options for orm are: :active_record, :mongoid # config.orm = :active_record end From fc1c987cd40a87610b9d5c0fef9c496aa90e8d02 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 04:57:18 +0200 Subject: [PATCH 066/364] Update README [ci skip] --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef13fe62..64e354a0 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,9 @@ 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 + # available options for orm are: :active_record, :mongoid # config.orm = :active_record end @@ -204,7 +207,7 @@ end * `:like`, `:start_with`, `:end_with` 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) +* `:date_range` for date range (only for Rails > 4.2.x, see [here](#daterange-search)) * `: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) @@ -601,6 +604,21 @@ def get_raw_records end ``` +### Default scope + +See [DefaultScope is evil](https://rails-bestpractices.com/posts/2013/06/15/default_scope-is-evil/) and [#223](https://github.com/jbox-web/ajax-datatables-rails/issues/223) and [#233](https://github.com/jbox-web/ajax-datatables-rails/issues/233). + +### DateRange search + +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 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 +
ID First Name Last NameEmail Brief Bio
` 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 + ### Generator Syntax Also, a class that inherits from `AjaxDatatablesRails::Base` is not tied to an From d5e7a6711fad0b53300db6c02a53f9cea3ae477a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 06:48:29 +0200 Subject: [PATCH 067/364] Update CHANGELOG [ci skip] --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f042b0af..8cc97a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## 0.4.1 (to come) +## 0.4.1 (2018-05-06) * Fix: Restore behavior of #filter method [Comment](https://github.com/jbox-web/ajax-datatables-rails/commit/07795fd26849ff1b3b567f4ce967f722907a45be#comments) * Fix: Fix erroneous offset/start behavior [PR #264](https://github.com/jbox-web/ajax-datatables-rails/pull/264) @@ -9,6 +9,7 @@ * Add: Add "order nulls last" option [PR #79](https://github.com/jbox-web/ajax-datatables-rails/pull/279) * Change: Rename `additional_datas` method as `additional_data` [PR #251](https://github.com/jbox-web/ajax-datatables-rails/pull/251) * Change: Added timezone support for daterange [PR #261](https://github.com/jbox-web/ajax-datatables-rails/pull/261) +* 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 From fc61d691b37e779bbcf32e2a751deff824726d40 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 06:53:01 +0200 Subject: [PATCH 068/364] Bump to 0.4.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 3f795c6d..f918a55a 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.0' + VERSION = '0.4.1' end From 55b450c2fd25046769cff55e69afe9098441e89f Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 6 May 2018 07:04:15 +0200 Subject: [PATCH 069/364] 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 070/364] 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 071/364] 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 072/364] 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 073/364] 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
+ +# 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 074/364] 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 075/364] 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 076/364] 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 077/364] 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 078/364] 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 079/364] 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 080/364] 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 081/364] 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 082/364] 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 083/364] 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 084/364] 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 085/364] 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 086/364] 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 087/364] 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 088/364] 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 089/364] 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 090/364] 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 091/364] 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 092/364] 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 093/364] 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 094/364] 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 095/364] 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 096/364] 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 097/364] 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 098/364] 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 099/364] 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 100/364] 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 101/364] 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 102/364] 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 103/364] 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 104/364] 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 105/364] 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 106/364] 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 107/364] 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 108/364] 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 109/364] 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 110/364] 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 111/364] 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 112/364] 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 113/364] 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 114/364] 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 115/364] 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 116/364] 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 117/364] 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 118/364] 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 119/364] 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 120/364] 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 121/364] 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 122/364] 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 123/364] 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 124/364] 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 125/364] 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 126/364] 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 127/364] 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 128/364] 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 129/364] 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 130/364] 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 131/364] 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 132/364] 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 133/364] 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 134/364] 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 135/364] 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 136/364] 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 137/364] 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 138/364] 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 139/364] 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 140/364] 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 141/364] 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 142/364] 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 143/364] 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 144/364] 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 145/364] 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 146/364] 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 147/364] 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 148/364] 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 149/364] 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 150/364] 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 151/364] 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 152/364] 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 153/364] 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 154/364] 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 155/364] 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 156/364] 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 157/364] 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 158/364] 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 159/364] 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 160/364] 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 161/364] 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 162/364] 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 163/364] 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 164/364] 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 165/364] 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 166/364] 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 167/364] 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 168/364] 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 169/364] 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 170/364] 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 171/364] 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 172/364] 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 173/364] 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 174/364] 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 175/364] 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 176/364] 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 177/364] 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 178/364] 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 179/364] 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 180/364] 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 181/364] 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 182/364] 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 183/364] 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 184/364] 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 185/364] 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 186/364] 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 187/364] 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 188/364] 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 189/364] 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 190/364] 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 191/364] 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 192/364] 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 193/364] 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 194/364] 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 195/364] 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 196/364] 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 197/364] 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 198/364] 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 199/364] 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 200/364] 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 201/364] 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 202/364] 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 203/364] 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 204/364] 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 205/364] 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 206/364] 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 207/364] 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 208/364] 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 209/364] 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 210/364] 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 211/364] 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 212/364] 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 213/364] 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 214/364] 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 215/364] 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 216/364] 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 217/364] 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 218/364] 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 219/364] 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 220/364] 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 221/364] 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 222/364] 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 223/364] 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 224/364] 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 225/364] 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 226/364] 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 227/364] 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 228/364] 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 229/364] 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 230/364] 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 231/364] 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 232/364] 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 233/364] 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 234/364] 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 235/364] 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 236/364] 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 237/364] 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 238/364] 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 239/364] 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 240/364] 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 241/364] 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 242/364] 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 243/364] 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 244/364] 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('http://github.com/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 245/364] 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 246/364] 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 247/364] 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 248/364] 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 249/364] 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 250/364] 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 251/364] 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 252/364] 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 253/364] 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 254/364] 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 255/364] 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 256/364] 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 257/364] 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 258/364] 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('http://github.com/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 259/364] 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 260/364] 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 261/364] 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 262/364] 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 263/364] 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 264/364] 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 265/364] 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 266/364] 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 267/364] 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 268/364] 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 269/364] 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 270/364] 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('http://github.com/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('http://github.com/USER') %> + password: <%= ENV.fetch('http://github.com/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('http://github.com/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 271/364] 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 272/364] 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 273/364] 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 274/364] 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 275/364] 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 276/364] 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 277/364] 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 278/364] 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 279/364] 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 280/364] 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 281/364] 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 282/364] 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 283/364] 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 284/364] 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 285/364] 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 286/364] 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 287/364] 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 288/364] 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('http://github.com/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 289/364] 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 290/364] 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 291/364] 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 292/364] 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 293/364] 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 294/364] 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 295/364] 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 296/364] 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 297/364] 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 298/364] 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 299/364] 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 300/364] 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 301/364] 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 302/364] 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 303/364] 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 304/364] 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 305/364] 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 306/364] 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 307/364] 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 308/364] 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 309/364] 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 310/364] 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 311/364] 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 312/364] 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 313/364] 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 314/364] 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 315/364] 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 316/364] 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 317/364] 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 318/364] 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 319/364] 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 320/364] 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 321/364] 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 322/364] 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 323/364] 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 324/364] 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 325/364] 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 326/364] 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 327/364] 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 328/364] 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 329/364] 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 330/364] 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 331/364] 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 332/364] 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 333/364] 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 334/364] 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 335/364] 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 336/364] 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 337/364] 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 338/364] 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 339/364] 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 340/364] 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 341/364] 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 342/364] 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 343/364] 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 344/364] 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 345/364] 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 346/364] 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 347/364] 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 348/364] 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 349/364] 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 350/364] 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 351/364] 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 352/364] 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 353/364] 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 354/364] 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 355/364] 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 356/364] 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 357/364] 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 358/364] 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('http://github.com/DB_ADAPTER', nil)) end def self.postgresql? - ENV['DB_ADAPTER'] == 'postgresql' || ENV['DB_ADAPTER'] == 'postgis' + %w[postgresql postgis].include?(ENV.fetch('http://github.com/DB_ADAPTER', nil)) end end From cce00219bf6bbcc00e2c48d8fd4723ec266f9324 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 2 Jul 2025 00:51:38 +0200 Subject: [PATCH 359/364] Switch to qlty --- .github/workflows/ci.yml | 11 +++++++---- .qlty/qlty.toml | 35 +++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 2 ++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 .qlty/qlty.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b22f5e2..6ce48f8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -142,10 +142,13 @@ jobs: env: DB_ADAPTER: ${{ matrix.adapter }} - - name: RSpec & publish code coverage - uses: paambaati/codeclimate-action@v9.0.0 + - name: Run RSpec env: DB_ADAPTER: ${{ matrix.adapter }} - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + run: bin/rspec + + - name: Publish code coverage + uses: qltysh/qlty-action/coverage@v1 with: - coverageCommand: bin/rspec + token: ${{ secrets.QLTY_COVERAGE_TOKEN }} + files: coverage/coverage.json diff --git a/.qlty/qlty.toml b/.qlty/qlty.toml new file mode 100644 index 00000000..75811a42 --- /dev/null +++ b/.qlty/qlty.toml @@ -0,0 +1,35 @@ +config_version = "0" + +[[source]] +name = "default" +default = true + +[[plugin]] +name = "actionlint" + +[[plugin]] +name = "checkov" +version = "3.2.49" + +[[plugin]] +name = "markdownlint" +version = "0.31.1" + +[[plugin]] +name = "osv-scanner" + +[[plugin]] +name = "prettier" +version = "2.8.4" + +[[plugin]] +name = "ripgrep" + +[[plugin]] +name = "trivy" + +[[plugin]] +name = "trufflehog" + +[[plugin]] +name = "yamllint" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 86ed53d9..822b8c5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,7 @@ Combustion.initialize! :active_record, :action_controller require 'simplecov' +require 'simplecov_json_formatter' require 'rspec' require 'rspec/retry' require 'database_cleaner' @@ -15,6 +16,7 @@ # Start Simplecov SimpleCov.start do + formatter SimpleCov::Formatter::JSONFormatter add_filter 'spec/' end From 8e60fbf88a43b54ef6bfbb8210587915768b8ad7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 2 Jul 2025 05:26:33 +0200 Subject: [PATCH 360/364] Fix postgis CI --- Appraisals | 6 +++--- gemfiles/rails_7.1_with_postgis.gemfile | 2 +- gemfiles/rails_7.2_with_postgis.gemfile | 2 +- gemfiles/rails_8.0_with_postgis.gemfile | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Appraisals b/Appraisals index dc6bea81..51c1c707 100644 --- a/Appraisals +++ b/Appraisals @@ -36,7 +36,7 @@ end appraise 'rails_7.1_with_postgis' do gem 'rails', '~> 7.1.0' gem 'pg' - gem 'activerecord-postgis-adapter' + gem 'activerecord-postgis-adapter', '~> 9.0.0' end ############### @@ -75,7 +75,7 @@ end 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' + gem 'activerecord-postgis-adapter', '~> 10.0.0' end ############### @@ -114,5 +114,5 @@ 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' + gem 'activerecord-postgis-adapter', '~> 11.0.0' end diff --git a/gemfiles/rails_7.1_with_postgis.gemfile b/gemfiles/rails_7.1_with_postgis.gemfile index ffaad7df..189ab407 100644 --- a/gemfiles/rails_7.1_with_postgis.gemfile +++ b/gemfiles/rails_7.1_with_postgis.gemfile @@ -21,6 +21,6 @@ gem "rubocop-performance", require: false gem "rubocop-rake", require: false gem "rubocop-rspec", require: false gem "rails", "~> 7.1.0" -gem "activerecord-postgis-adapter" +gem "activerecord-postgis-adapter", "~> 9.0.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2_with_postgis.gemfile b/gemfiles/rails_7.2_with_postgis.gemfile index 7f0a4e17..7ce4286b 100644 --- a/gemfiles/rails_7.2_with_postgis.gemfile +++ b/gemfiles/rails_7.2_with_postgis.gemfile @@ -21,6 +21,6 @@ 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" +gem "activerecord-postgis-adapter", "~> 10.0.0" gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_postgis.gemfile b/gemfiles/rails_8.0_with_postgis.gemfile index c2498b58..3af883bf 100644 --- a/gemfiles/rails_8.0_with_postgis.gemfile +++ b/gemfiles/rails_8.0_with_postgis.gemfile @@ -21,6 +21,6 @@ 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" +gem "activerecord-postgis-adapter", "~> 11.0.0" gemspec path: "../" From 2e6315a9a716ba0efd7bd87b549f41065407c5f7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Wed, 2 Jul 2025 05:26:52 +0200 Subject: [PATCH 361/364] Disable oracle CI for now --- .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 6ce48f8f..57054599 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: - sqlite3 - postgresql - mysql2 - - oracle_enhanced + # - 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 From 169fd461d5ad608a95dbb917a8b18e5da0dbf5e0 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 8 Jul 2025 01:15:14 +0200 Subject: [PATCH 362/364] Update Oracle CI --- .github/workflows/ci.yml | 26 ----- .github/workflows/ci_oracle.yml | 104 ++++++++++++++++++ Appraisals | 4 +- ci/network/admin/tnsnames.ora | 15 +++ ci/setup_accounts.sh | 8 ++ .../rails_7.2_with_oracle_enhanced.gemfile | 2 +- .../rails_8.0_with_oracle_enhanced.gemfile | 2 +- .../orm/active_record_filter_records_spec.rb | 2 +- spec/dummy/config/database.yml | 8 +- spec/install_oracle.sh | 18 --- spec/support/create_oracle_enhanced_users.sql | 7 ++ 11 files changed, 143 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/ci_oracle.yml create mode 100644 ci/network/admin/tnsnames.ora create mode 100755 ci/setup_accounts.sh delete mode 100755 spec/install_oracle.sh create mode 100644 spec/support/create_oracle_enhanced_users.sql diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57054599..9d1a58d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,10 +37,6 @@ jobs: env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps 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 - ORACLE_SID: XE services: postgres: @@ -86,7 +82,6 @@ jobs: - sqlite3 - postgresql - 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 @@ -98,20 +93,6 @@ jobs: - 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 #>, - # @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' - adapter: 'oracle_enhanced' - steps: - name: Checkout uses: actions/checkout@v4 @@ -119,7 +100,6 @@ jobs: - name: Set DB Adapter env: 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: | @@ -128,12 +108,6 @@ jobs: 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 uses: ruby/setup-ruby@v1 with: diff --git a/.github/workflows/ci_oracle.yml b/.github/workflows/ci_oracle.yml new file mode 100644 index 00000000..7df46ebf --- /dev/null +++ b/.github/workflows/ci_oracle.yml @@ -0,0 +1,104 @@ +--- +name: CI Oracle + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + schedule: + - cron: '0 4 1 * *' + # Run workflow manually + workflow_dispatch: + +jobs: + rspec: + 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 }}_with_${{ matrix.adapter }}.gemfile + ORACLE_HOME: /opt/oracle/instantclient_23_8 + LD_LIBRARY_PATH: /opt/oracle/instantclient_23_8 + TNS_ADMIN: ./ci/network/admin + DATABASE_SYS_PASSWORD: Oracle18 + DATABASE_NAME: FREEPDB1 + + services: + oracle: + image: gvenzl/oracle-free:latest + ports: + - 1521:1521 + env: + TZ: Europe/Paris + ORACLE_PASSWORD: Oracle18 + options: >- + --health-cmd healthcheck.sh + --health-interval 10s + --health-timeout 5s + --health-retries 10 + + strategy: + fail-fast: false + matrix: + ruby: + - '3.4' + - '3.3' + - '3.2' + - '3.1' + - 'head' + rails: + - rails_8.0 + - rails_7.2 + - rails_7.1 + adapter: + - oracle_enhanced + exclude: + - rails: 'rails_8.0' + ruby: '3.1' + adapter: 'oracle_enhanced' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Create symbolic link for libaio library compatibility + run: | + sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1 + + - name: Download Oracle instant client + run: | + wget -q https://download.oracle.com/otn_software/linux/instantclient/2380000/instantclient-basic-linux.x64-23.8.0.25.04.zip + wget -q https://download.oracle.com/otn_software/linux/instantclient/2380000/instantclient-sdk-linux.x64-23.8.0.25.04.zip + wget -q https://download.oracle.com/otn_software/linux/instantclient/2380000/instantclient-sqlplus-linux.x64-23.8.0.25.04.zip + + - name: Install Oracle instant client + run: | + sudo unzip instantclient-basic-linux.x64-23.8.0.25.04.zip -d /opt/oracle/ + sudo unzip -o instantclient-sdk-linux.x64-23.8.0.25.04.zip -d /opt/oracle/ + sudo unzip -o instantclient-sqlplus-linux.x64-23.8.0.25.04.zip -d /opt/oracle/ + echo "/opt/oracle/instantclient_23_8" >> $GITHUB_PATH + + - name: Create database user + run: | + ./ci/setup_accounts.sh + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + env: + DB_ADAPTER: ${{ matrix.adapter }} + + - name: Run RSpec + env: + DB_ADAPTER: ${{ matrix.adapter }} + run: bin/rspec + + - name: Publish code coverage + uses: qltysh/qlty-action/coverage@v1 + with: + token: ${{ secrets.QLTY_COVERAGE_TOKEN }} + files: coverage/coverage.json diff --git a/Appraisals b/Appraisals index 51c1c707..d39912b0 100644 --- a/Appraisals +++ b/Appraisals @@ -68,7 +68,7 @@ end 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' + gem 'activerecord-oracle_enhanced-adapter', '~> 7.2.0' remove_gem 'pg' end @@ -107,7 +107,7 @@ 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' + gem 'activerecord-oracle_enhanced-adapter', '~> 8.0.0' remove_gem 'pg' end diff --git a/ci/network/admin/tnsnames.ora b/ci/network/admin/tnsnames.ora new file mode 100644 index 00000000..d1ba8183 --- /dev/null +++ b/ci/network/admin/tnsnames.ora @@ -0,0 +1,15 @@ +FREEPDB1 = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) + (CONNECT_DATA = + (SERVICE_NAME = FREEPDB1) + ) + ) + +XE = + (DESCRIPTION = + (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) + (CONNECT_DATA = + (SERVICE_NAME = XE) + ) + ) diff --git a/ci/setup_accounts.sh b/ci/setup_accounts.sh new file mode 100755 index 00000000..3ed4d2ff --- /dev/null +++ b/ci/setup_accounts.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -ev + +sqlplus sys/${DATABASE_SYS_PASSWORD}@${DATABASE_NAME} as sysdba< 7.2.0" -gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced.git" +gem "activerecord-oracle_enhanced-adapter", "~> 7.2.0" gemspec path: "../" diff --git a/gemfiles/rails_8.0_with_oracle_enhanced.gemfile b/gemfiles/rails_8.0_with_oracle_enhanced.gemfile index 563ac16c..a18d301a 100644 --- a/gemfiles/rails_8.0_with_oracle_enhanced.gemfile +++ b/gemfiles/rails_8.0_with_oracle_enhanced.gemfile @@ -20,6 +20,6 @@ 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" +gem "activerecord-oracle_enhanced-adapter", "~> 8.0.0" gemspec path: "../" 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 2d6a4bb6..4bcbd541 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 @@ -198,7 +198,7 @@ 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%'" + "UPPER(CAST(\"USERS\".\"USERNAME\" AS VARCHAR2(4000))) LIKE UPPER('%doe%') AND UPPER(CAST(\"USERS\".\"EMAIL\" AS VARCHAR2(4000))) LIKE UPPER('%example%')" # rubocop:disable Layout/LineLength ) end end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 7f6a6759..a9de41f6 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -15,10 +15,10 @@ test: username: 'root' password: 'root' <% elsif adapter == 'oracle_enhanced' %> - host: '127.0.0.1/xe' - username: <%= ENV.fetch('http://github.com/USER') %> - password: <%= ENV.fetch('http://github.com/USER') %> - database: 'xe' + host: '127.0.0.1' + username: 'oracle_enhanced' + password: 'oracle_enhanced' + database: 'FREEPDB1' <% elsif adapter == 'sqlite3' %> # database: ':memory:' database: db/ajax_datatables_rails.sqlite3 diff --git a/spec/install_oracle.sh b/spec/install_oracle.sh deleted file mode 100755 index 07537f79..00000000 --- a/spec/install_oracle.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -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 -else - ~/.travis/oracle/download.sh -fi - -~/.travis/oracle/install.sh - -# in dev env: sqlplus system/password@localhost/XE -"${ORACLE_HOME}/bin/sqlplus" -L -S / AS SYSDBA < Date: Sun, 24 Aug 2025 00:34:48 +0200 Subject: [PATCH 363/364] Fix rubocop warnings --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3f8009ae..63074818 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ --- -require: +plugins: - rubocop-factory_bot - rubocop-performance - rubocop-rake From fdd7d0660269910b7aa656bdc0e16462e7bae1fb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 24 Aug 2025 00:38:44 +0200 Subject: [PATCH 364/364] Use SimpleCov::Formatter::MultiFormatter --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 822b8c5a..c7bfe759 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,7 @@ # Start Simplecov SimpleCov.start do - formatter SimpleCov::Formatter::JSONFormatter + formatter SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::JSONFormatter]) add_filter 'spec/' end