From 8934aac04514e578a8119f456fde0900bfa00cff Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 10:49:59 +0200 Subject: [PATCH 1/9] Fix validation errors copied with a wrong name on ActiveModel 6.1+, fix specs on Ruby 3 ActiveModel::Errors#each yields an error object instead of a name and a message on ActiveModel 6.1+, so errors from a flex column ended up on the model under an attribute name built from the error object's inspect string. The specs also needed updating for Ruby 3: lambdas used as blocks are strict about arity, and expectations on a trailing options hash must pass it explicitly rather than as keyword arguments. Co-Authored-By: Claude Sonnet 5.5 --- lib/flex_columns/contents/flex_column_contents_base.rb | 10 +++++++++- spec/flex_columns/unit/active_record/base_spec.rb | 4 ++-- .../unit/definition/flex_column_contents_class_spec.rb | 2 +- .../unit/including/include_flex_columns_spec.rb | 8 ++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/flex_columns/contents/flex_column_contents_base.rb b/lib/flex_columns/contents/flex_column_contents_base.rb index e7a14d6..bd7caab 100644 --- a/lib/flex_columns/contents/flex_column_contents_base.rb +++ b/lib/flex_columns/contents/flex_column_contents_base.rb @@ -146,7 +146,15 @@ def deserialized? def before_validation! return unless model_instance unless valid? - errors.each do |name, message| + errors.each do |*args| + # ActiveModel 6.1+ yields a single error object; older versions yield the attribute name and message. + error = args.first + if error.respond_to?(:attribute) && error.respond_to?(:message) + name, message = error.attribute, error.message + else + name, message = args + end + model_instance.errors.add("#{column_name}.#{name}", message) end end diff --git a/spec/flex_columns/unit/active_record/base_spec.rb b/spec/flex_columns/unit/active_record/base_spec.rb index 19b98d6..8a94682 100644 --- a/spec/flex_columns/unit/active_record/base_spec.rb +++ b/spec/flex_columns/unit/active_record/base_spec.rb @@ -11,7 +11,7 @@ end it "should include HasFlexColumns on flex_column" do - block = lambda { "hi!" } + block = proc { "hi!" } expect(@klass).to receive(:include).once.with(FlexColumns::HasFlexColumns) do expect(@klass).to receive(:flex_column).once.with(:foo, &block) @@ -21,7 +21,7 @@ end it "should include IncludeFlexColumns on include_flex_columns_from" do - block = lambda { "hi!" } + block = proc { "hi!" } expect(@klass).to receive(:include).once.with(FlexColumns::Including::IncludeFlexColumns) do expect(@klass).to receive(:include_flex_columns_from).once.with(:foo, &block) diff --git a/spec/flex_columns/unit/definition/flex_column_contents_class_spec.rb b/spec/flex_columns/unit/definition/flex_column_contents_class_spec.rb index 355539a..5519025 100644 --- a/spec/flex_columns/unit/definition/flex_column_contents_class_spec.rb +++ b/spec/flex_columns/unit/definition/flex_column_contents_class_spec.rb @@ -511,7 +511,7 @@ def cm1(*args, &block) end it "should pass through :field to the field set" do - expect(@field_set).to receive(:field).once.with(:foo, :bar, :baz => :quux) + expect(@field_set).to receive(:field).once.with(:foo, :bar, { :baz => :quux }) @klass.field(:foo, :bar, :baz => :quux) end diff --git a/spec/flex_columns/unit/including/include_flex_columns_spec.rb b/spec/flex_columns/unit/including/include_flex_columns_spec.rb index dd0f617..f5ffe20 100644 --- a/spec/flex_columns/unit/including/include_flex_columns_spec.rb +++ b/spec/flex_columns/unit/including/include_flex_columns_spec.rb @@ -105,10 +105,10 @@ allow(ac1).to receive(:_all_flex_column_names).with(no_args).and_return([ :ac1fc1, :ac1fc2 ]) ac1fc1_fcc = double("ac1fc1_fcc") - expect(ac1fc1_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc1, @klass, :prefix => 'abz', :delegate => false, :visibility => :private) + expect(ac1fc1_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc1, @klass, { :prefix => 'abz', :delegate => false, :visibility => :private }) allow(ac1).to receive(:_flex_column_class_for).with(:ac1fc1).and_return(ac1fc1_fcc) ac1fc2_fcc = double("ac1fc2_fcc") - expect(ac1fc2_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc1, @klass, :prefix => 'abz', :delegate => false, :visibility => :private) + expect(ac1fc2_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc1, @klass, { :prefix => 'abz', :delegate => false, :visibility => :private }) allow(ac1).to receive(:_flex_column_class_for).with(:ac1fc2).and_return(ac1fc2_fcc) ac2 = double("ac2") @@ -117,10 +117,10 @@ allow(ac2).to receive(:_all_flex_column_names).with(no_args).and_return([ :ac2fc1, :ac2fc2 ]) ac2fc1_fcc = double("ac2fc1_fcc") - expect(ac2fc1_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc2, @klass, :prefix => 'abz', :delegate => false, :visibility => :private) + expect(ac2fc1_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc2, @klass, { :prefix => 'abz', :delegate => false, :visibility => :private }) allow(ac2).to receive(:_flex_column_class_for).with(:ac2fc1).and_return(ac2fc1_fcc) ac2fc2_fcc = double("ac2fc2_fcc") - expect(ac2fc2_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc2, @klass, :prefix => 'abz', :delegate => false, :visibility => :private) + expect(ac2fc2_fcc).to receive(:include_fields_into).once.ordered.with(dmm, :assoc2, @klass, { :prefix => 'abz', :delegate => false, :visibility => :private }) allow(ac2).to receive(:_flex_column_class_for).with(:ac2fc2).and_return(ac2fc2_fcc) @klass.include_flex_columns_from(:assoc1, :assoc2, :prefix => 'abz', :delegate => false, :visibility => :private) From b37063524a6156162df011abda44b4d44460e0ba Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 10:49:59 +0200 Subject: [PATCH 2/9] Make the development setup work on Ruby 3.2 and ActiveRecord 6.1/7.2 Drop the Ruby 1.8-era dependency pins and conditionals (bundler 1.x, rake < 11, rspec 2), add .ruby-version, remove the Travis configuration, pin json < 3 and the ActiveRecord 6-only test pins (sqlite3 1.x, concurrent-ruby < 1.3.5), and document how to run the specs. Bump the version to 1.0.13. Co-Authored-By: Claude Sonnet 5.5 --- .ruby-version | 1 + .travis.yml | 69 ------------------------------------- CHANGES.md | 7 ++++ Gemfile | 3 ++ README.md | 17 ++++++--- flex_columns.gemspec | 24 ++++--------- lib/flex_columns/version.rb | 2 +- 7 files changed, 32 insertions(+), 91 deletions(-) create mode 100644 .ruby-version delete mode 100644 .travis.yml diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..f092941 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.8 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5a6dfc2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,69 +0,0 @@ -rvm: - - "1.8.7" - - "1.9.3-p551" - - "2.0.0-p598" - - "2.1.5" - - "2.2.0" - - "jruby-1.7.19" -env: - - FLEX_COLUMNS_AR_TEST_VERSION=3.0.20 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - FLEX_COLUMNS_AR_TEST_VERSION=3.0.20 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - FLEX_COLUMNS_AR_TEST_VERSION=3.0.20 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - FLEX_COLUMNS_AR_TEST_VERSION=3.1.12 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - FLEX_COLUMNS_AR_TEST_VERSION=3.1.12 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - FLEX_COLUMNS_AR_TEST_VERSION=3.1.12 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - FLEX_COLUMNS_AR_TEST_VERSION=3.2.21 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - FLEX_COLUMNS_AR_TEST_VERSION=3.2.21 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - FLEX_COLUMNS_AR_TEST_VERSION=3.2.21 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - FLEX_COLUMNS_AR_TEST_VERSION=4.0.13 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - FLEX_COLUMNS_AR_TEST_VERSION=4.0.13 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - FLEX_COLUMNS_AR_TEST_VERSION=4.0.13 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - FLEX_COLUMNS_AR_TEST_VERSION=4.1.9 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - FLEX_COLUMNS_AR_TEST_VERSION=4.1.9 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - FLEX_COLUMNS_AR_TEST_VERSION=4.1.9 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite -before_script: - - mysql -e 'create database myapp_test;' - - psql -c 'create database myapp_test;' -U postgres -matrix: - exclude: - # ActiveRecord 4.x doesn't support Ruby 1.8.7 - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.0.13 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.0.13 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.0.13 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.1.9 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.1.9 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.1.9 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - rvm: 1.8.7 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - # There's a bug in ActiveRecord 3.1.x that makes it incompatible with Ruby 2.0 - - rvm: 2.0.0-p598 - env: FLEX_COLUMNS_AR_TEST_VERSION=3.1.12 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - rvm: 2.0.0-p598 - env: FLEX_COLUMNS_AR_TEST_VERSION=3.1.12 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - rvm: 2.0.0-p598 - env: FLEX_COLUMNS_AR_TEST_VERSION=3.1.12 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite - allow_failures: - # Rails 4.2.0 has a bug with PostgreSQL and binary columns - # (https://github.com/rails/rails/pull/17680) - - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - # As of this writing (2015-02-18), activerecord-jdbc doesn't support ActiveRecord 4.2.x - # completely. - - rvm: jruby-1.7.19 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=mysql - - rvm: jruby-1.7.19 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=postgres - - rvm: jruby-1.7.19 - env: FLEX_COLUMNS_AR_TEST_VERSION=4.2.0 FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite diff --git a/CHANGES.md b/CHANGES.md index 9b1f133..6b5264d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # `flex_columns` Changelog +## 1.0.13 + +* Fix validation errors from a flex column being copied onto the model with a garbage attribute name on + ActiveModel 6.1+ (`errors.each` yields an error object there, not a name and a message) +* Require `json < 3` (ActiveSupport 7.x still passes `quirks_mode`, which json 3 removed) +* Make the specs and development dependencies installable and passing on Ruby 3.2 (RSpec 3, ActiveRecord 6.1 and 7.2) + ## 1.0.12 * Relax ActiveRecord/ActiveSupport constraints to allow Rails 7.x (`< 8`) diff --git a/Gemfile b/Gemfile index 9c0f13b..cd69fda 100644 --- a/Gemfile +++ b/Gemfile @@ -15,3 +15,6 @@ end if version_spec gem("activerecord", version_spec) end + +# concurrent-ruby 1.3.5 dropped its implicit require of 'logger', which breaks ActiveSupport < 7.1. +gem("concurrent-ruby", "< 1.3.5") if ar_version && ar_version =~ /\A[0-6]\./ diff --git a/README.md b/README.md index 8551269..dbaa6dc 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,20 @@ while relying on the most reliable, manageable, proven data engines out there. Supported platforms: -* Ruby 1.8.7, 1.9.3, 2.0.0, 2.1.2, and JRuby 1.7.12. -* ActiveRecord 3.0.20, 3.1.12, 3.2.19, 4.0.8, and 4.1.4. (Should be compatible with future versions, as well...just sits on top of the public API of ActiveRecord.) -* Tested against MySQL, PostgreSQL, and SQLite 3. (Should be compatible with all RDBMSes supported by ActiveRecord.) +* Ruby 3.2 (MRI). Older Rubies may work but are no longer tested. +* ActiveRecord 6.1 and 7.2 are tested; the gemspec allows 3.0 up to (but not including) 8. (Should be compatible with future versions, as well...just sits on top of the public API of ActiveRecord.) +* Tested against MySQL and SQLite 3. (Should be compatible with all RDBMSes supported by ActiveRecord.) -Current build status: ![Current Build Status](https://api.travis-ci.org/ageweke/flex_columns.png?branch=master) +### Running the specs + +``` +bundle install +FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite bundle exec rspec +``` + +Set `FLEX_COLUMNS_AR_TEST_VERSION` (for example `6.1.7.10`) to run against a specific ActiveRecord version. To use MySQL +or PostgreSQL, create `spec_database_config.rb` (git-ignored) as described in the error message that the specs print +when no database is configured. ### Installing flex_columns diff --git a/flex_columns.gemspec b/flex_columns.gemspec index 7c99c86..ecb76cf 100644 --- a/flex_columns.gemspec +++ b/flex_columns.gemspec @@ -18,11 +18,10 @@ Gem::Specification.new do |s| s.test_files = s.files.grep(%r{^(test|spec|features)/}) s.require_paths = ["lib"] - s.add_dependency 'json' + s.add_dependency 'json', '< 3' - s.add_development_dependency "bundler", "~> 1.16.2" - s.add_development_dependency "rake", '< 11.0' - s.add_development_dependency "rspec", "~> 2.14" + s.add_development_dependency "rake", ">= 13" + s.add_development_dependency "rspec", "~> 3.12" ar_version = ENV['FLEX_COLUMNS_AR_TEST_VERSION'] ar_version = ar_version.strip if ar_version @@ -39,22 +38,13 @@ Gem::Specification.new do |s| s.add_dependency "activesupport", ">= 3.0", "< 8" - # i18n released an 0.7.0 that's incompatible with Ruby 1.8. - if RUBY_VERSION =~ /^1\.8\./ - s.add_development_dependency 'i18n', '< 0.7.0' - end - require File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'flex_columns', 'helpers', 'database_helper')) database_gem_name = FlexColumns::Helpers::DatabaseHelper.maybe_database_gem_name - # Ugh. Later versions of the 'mysql2' gem are incompatible with AR 3.0.x; so, here, we explicitly trap that case - # and use an earlier version of that Gem. - if database_gem_name && database_gem_name == 'mysql2' && ar_version && ar_version =~ /^3\.0\./ - s.add_development_dependency(database_gem_name, '~> 0.2.0') - # The 'pg' gem removed Ruby 1.8 compatibility as of 0.18. - elsif database_gem_name && database_gem_name == 'pg' && RUBY_VERSION =~ /^1\.8\./ - s.add_development_dependency(database_gem_name, '< 0.18.0') - else + if database_gem_name == 'sqlite3' && ar_version && ar_version =~ /\A[0-6]\./ + # ActiveRecord before 7.1 does not accept sqlite3 2.x. + s.add_development_dependency(database_gem_name, '~> 1.4') + elsif database_gem_name s.add_development_dependency(database_gem_name) end end diff --git a/lib/flex_columns/version.rb b/lib/flex_columns/version.rb index 3ce1c04..dbe996e 100644 --- a/lib/flex_columns/version.rb +++ b/lib/flex_columns/version.rb @@ -1,4 +1,4 @@ module FlexColumns # The current version of FlexColumns. - VERSION = "1.0.12" + VERSION = "1.0.13" end From e179e983fe8160d01a47a3582a4cacd1bab6b63f Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 10:59:42 +0200 Subject: [PATCH 3/9] Document PostgreSQL in the README Co-Authored-By: Claude Sonnet 5.5 --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbaa6dc..020e4a1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Supported platforms: * Ruby 3.2 (MRI). Older Rubies may work but are no longer tested. * ActiveRecord 6.1 and 7.2 are tested; the gemspec allows 3.0 up to (but not including) 8. (Should be compatible with future versions, as well...just sits on top of the public API of ActiveRecord.) -* Tested against MySQL and SQLite 3. (Should be compatible with all RDBMSes supported by ActiveRecord.) +* Tested against MySQL, PostgreSQL and SQLite 3. (Should be compatible with all RDBMSes supported by ActiveRecord.) ### Running the specs @@ -24,7 +24,18 @@ FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite bundle exec rspec Set `FLEX_COLUMNS_AR_TEST_VERSION` (for example `6.1.7.10`) to run against a specific ActiveRecord version. To use MySQL or PostgreSQL, create `spec_database_config.rb` (git-ignored) as described in the error message that the specs print -when no database is configured. +when no database is configured. For example, for PostgreSQL: + +```ruby +FLEX_COLUMNS_SPEC_DATABASE_CONFIG = { + :require => 'pg', :database_gem_name => 'pg', + :config => { :adapter => 'postgresql', :database => 'myapp_test', :username => 'postgres', + :host => '127.0.0.1', :min_messages => 'WARNING' } +} +``` + +The file takes priority over `FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE`. Delete `Gemfile.lock` when you switch databases or +ActiveRecord versions. ### Installing flex_columns From b2f0e1ad3f4886caefd1b24e87991f0ef0336dfe Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 11:02:43 +0200 Subject: [PATCH 4/9] Add script/test-docker to run the specs against containerized databases Starts throwaway MySQL and PostgreSQL containers on random local ports (SQLite runs in memory), runs the specs for each ActiveRecord version and prints a summary table. The spec helper can now read its database configuration from the path in FLEX_COLUMNS_SPEC_DATABASE_CONFIG_FILE, so a developer's own spec_database_config.rb is left alone. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 15 +- script/test-docker | 173 +++++++++++++++++++ spec/flex_columns/helpers/database_helper.rb | 3 +- 3 files changed, 189 insertions(+), 2 deletions(-) create mode 100755 script/test-docker diff --git a/README.md b/README.md index 020e4a1..6471d79 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,20 @@ bundle install FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE=sqlite bundle exec rspec ``` -Set `FLEX_COLUMNS_AR_TEST_VERSION` (for example `6.1.7.10`) to run against a specific ActiveRecord version. To use MySQL +To run the specs against throwaway MySQL and PostgreSQL containers (and SQLite) without installing any database, use +`script/test-docker` (requires Docker): + +``` +script/test-docker # all databases, ActiveRecord 7.2.3.2 and 6.1.7.10 +script/test-docker postgres 7.2.3.2 # one database, one ActiveRecord version +script/test-docker mysql -- spec/flex_columns/system/validations_system_spec.rb +``` + +It uses its own database configuration, so your `spec_database_config.rb` is neither used nor modified. The `mysql2` +gem needs the MySQL client library on the host (for example `brew install mysql-client` or +`apt-get install libmysqlclient-dev`). + +To run by hand, set `FLEX_COLUMNS_AR_TEST_VERSION` (for example `6.1.7.10`) to run against a specific ActiveRecord version. To use MySQL or PostgreSQL, create `spec_database_config.rb` (git-ignored) as described in the error message that the specs print when no database is configured. For example, for PostgreSQL: diff --git a/script/test-docker b/script/test-docker new file mode 100755 index 0000000..5b90260 --- /dev/null +++ b/script/test-docker @@ -0,0 +1,173 @@ +#!/usr/bin/env bash +# +# Runs the specs against throwaway database containers, so that you only need Docker and Ruby. +# +# script/test-docker [sqlite|mysql|postgres|all ...] [ACTIVERECORD_VERSION ...] [-- RSPEC_ARGS] +# +# Examples: +# script/test-docker # all databases, ActiveRecord 7.2.3.2 and 6.1.7.10 +# script/test-docker postgres 7.2.3.2 # one database, one ActiveRecord version +# script/test-docker mysql -- spec/flex_columns/system/validations_system_spec.rb +# +# Notes: +# * MySQL and PostgreSQL run in containers on random local ports and are always removed on exit. +# SQLite runs in memory and needs no container. +# * The 'mysql2' and 'pg' gems are installed on the host; 'mysql2' needs the MySQL client library +# (for example `brew install mysql-client` or `apt-get install libmysqlclient-dev`). +# * Your own spec_database_config.rb is not used or modified. Gemfile.lock is regenerated for every +# combination and your existing one is restored on exit. +# * Override the images with FLEX_COLUMNS_MYSQL_IMAGE and FLEX_COLUMNS_POSTGRES_IMAGE. + +set -u -o pipefail + +MYSQL_IMAGE="${FLEX_COLUMNS_MYSQL_IMAGE:-mysql:8}" +POSTGRES_IMAGE="${FLEX_COLUMNS_POSTGRES_IMAGE:-postgres:16}" +DEFAULT_AR_VERSIONS="7.2.3.2 6.1.7.10" +DB_PASSWORD="flexcolumns" +DB_NAME="myapp_test" +READY_TIMEOUT=90 + +cd "$(dirname "$0")/.." || exit 2 + +databases=() +ar_versions=() +rspec_args=() +while [ $# -gt 0 ]; do + case "$1" in + sqlite|mysql|postgres) databases+=("$1") ;; + all) databases+=(sqlite mysql postgres) ;; + --) shift; rspec_args=("$@"); break ;; + [0-9]*) ar_versions+=("$1") ;; + -h|--help) sed -n '2,/^$/p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + *) echo "Unknown argument: $1 (see --help)" >&2; exit 2 ;; + esac + shift +done +[ ${#databases[@]} -eq 0 ] && databases=(sqlite mysql postgres) +[ ${#ar_versions[@]} -eq 0 ] && read -r -a ar_versions <<< "$DEFAULT_AR_VERSIONS" + +needs_docker=false +for db in "${databases[@]}"; do [ "$db" != sqlite ] && needs_docker=true; done +if $needs_docker && ! docker info >/dev/null 2>&1; then + echo "Docker is required for mysql/postgres but 'docker info' failed. Is Docker running?" >&2 + exit 2 +fi + +work_dir="$(mktemp -d)" +containers=() +lock_backup="" +if [ -f Gemfile.lock ]; then lock_backup="$work_dir/Gemfile.lock.orig"; cp Gemfile.lock "$lock_backup"; fi + +cleanup() { + local c + for c in ${containers[@]+"${containers[@]}"}; do docker rm -f "$c" >/dev/null 2>&1; done + if [ -n "$lock_backup" ]; then cp "$lock_backup" Gemfile.lock; else rm -f Gemfile.lock; fi +} +trap cleanup EXIT +trap 'exit 130' INT TERM + +# Starts a container for $1 (mysql|postgres), waits until it accepts TCP connections and writes the +# spec database configuration to $2. Prints the container name on stdout; returns non-zero on failure. +start_database() { + local db="$1" config_file="$2" name="flex-columns-test-$1-$$" image port i ready_cmd + + if [ "$db" = mysql ]; then + image="$MYSQL_IMAGE" + docker run -d --rm --name "$name" -e MYSQL_ROOT_PASSWORD="$DB_PASSWORD" -e MYSQL_DATABASE="$DB_NAME" \ + -p 127.0.0.1::3306 "$image" >/dev/null || return 1 + containers+=("$name") + # Checking over TCP inside the container skips the temporary server that the image starts for initialization. + ready_cmd="mysql -uroot -p$DB_PASSWORD -h127.0.0.1 -e 'select 1'" + port="$(docker port "$name" 3306/tcp | head -n1 | sed 's/.*://')" + else + image="$POSTGRES_IMAGE" + docker run -d --rm --name "$name" -e POSTGRES_PASSWORD="$DB_PASSWORD" -e POSTGRES_DB="$DB_NAME" \ + -p 127.0.0.1::5432 "$image" >/dev/null || return 1 + containers+=("$name") + ready_cmd="pg_isready -h 127.0.0.1 -U postgres" + port="$(docker port "$name" 5432/tcp | head -n1 | sed 's/.*://')" + fi + + for i in $(seq 1 "$READY_TIMEOUT"); do + docker exec "$name" sh -c "$ready_cmd" >/dev/null 2>&1 && break + sleep 1 + if [ "$i" -eq "$READY_TIMEOUT" ]; then echo "$db did not become ready in ${READY_TIMEOUT}s" >&2; return 1; fi + done + + if [ "$db" = mysql ]; then + cat > "$config_file" < 'mysql2', :database_gem_name => 'mysql2', + :config => { :adapter => 'mysql2', :database => '$DB_NAME', :username => 'root', :password => '$DB_PASSWORD', + :host => '127.0.0.1', :port => $port, :encoding => 'utf8' } +} +RUBY + else + cat > "$config_file" < 'pg', :database_gem_name => 'pg', + :config => { :adapter => 'postgresql', :database => '$DB_NAME', :username => 'postgres', :password => '$DB_PASSWORD', + :host => '127.0.0.1', :port => $port, :min_messages => 'WARNING' } +} +RUBY + fi + echo "$name" +} + +write_sqlite_config() { + cat > "$1" <<'RUBY' +FLEX_COLUMNS_SPEC_DATABASE_CONFIG = { + :require => 'sqlite3', :database_gem_name => 'sqlite3', + :config => { :adapter => 'sqlite3', :database => ':memory:' } +} +RUBY +} + +results=() +failed=false + +for db in "${databases[@]}"; do + config_file="$work_dir/spec_database_config_$db.rb" + container="" + + if [ "$db" = sqlite ]; then + write_sqlite_config "$config_file" + else + echo "==> Starting $db container..." + if ! container="$(start_database "$db" "$config_file")"; then + for ar in "${ar_versions[@]}"; do results+=("$db|$ar|container did not start"); done + failed=true + continue + fi + fi + + for ar in "${ar_versions[@]}"; do + log="$work_dir/$db-$ar.log" + echo "==> $db / ActiveRecord $ar (log: $log)" + rm -f Gemfile.lock + export FLEX_COLUMNS_AR_TEST_VERSION="$ar" + export FLEX_COLUMNS_SPEC_DATABASE_CONFIG_FILE="$config_file" + unset FLEX_COLUMNS_TRAVIS_CI_DATABASE_TYPE + + if ! bundle install > "$log" 2>&1; then + results+=("$db|$ar|bundle install failed") + failed=true + continue + fi + bundle exec rspec ${rspec_args[@]+"${rspec_args[@]}"} >> "$log" 2>&1 + status=$? + summary="$(grep -E '^[0-9]+ examples?,' "$log" | tail -n1)" + [ -z "$summary" ] && summary="no summary (see log)" + if [ $status -eq 0 ]; then results+=("$db|$ar|PASS: $summary"); else results+=("$db|$ar|FAIL: $summary"); failed=true; fi + done + + if [ -n "$container" ]; then docker rm -f "$container" >/dev/null 2>&1; fi +done + +echo +printf '%-10s %-12s %s\n' DATABASE ACTIVERECORD RESULT +for r in "${results[@]}"; do IFS='|' read -r db ar res <<< "$r"; printf '%-10s %-12s %s\n' "$db" "$ar" "$res"; done +echo +echo "Logs: $work_dir" +$failed && exit 1 +exit 0 diff --git a/spec/flex_columns/helpers/database_helper.rb b/spec/flex_columns/helpers/database_helper.rb index e2a4720..cc05b84 100644 --- a/spec/flex_columns/helpers/database_helper.rb +++ b/spec/flex_columns/helpers/database_helper.rb @@ -151,7 +151,8 @@ def travis_ci_config_from_environment end def config_file_path - @config_file_path ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_database_config.rb')) + @config_file_path ||= ENV['FLEX_COLUMNS_SPEC_DATABASE_CONFIG_FILE'] || + File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_database_config.rb')) end def invalid_config_file! From 710ed739e3346f658bfd7f54334aeb8fadfe9827 Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 11:03:03 +0200 Subject: [PATCH 5/9] Run the specs on GitHub Actions Runs script/test-docker for SQLite, MySQL and PostgreSQL against ActiveRecord 6.1 and 7.2 on Ruby 3.2. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e65ef18 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Tests + +on: + push: + branches: [master] + pull_request: + +permissions: + contents: read + +jobs: + test: + name: ${{ matrix.database }} / ActiveRecord ${{ matrix.activerecord }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + database: [sqlite, mysql, postgres] + activerecord: ["6.1.7.10", "7.2.3.2"] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: ruby/setup-ruby@e81a8fa391b11a595c1b7ed84177cc0fe02faf83 # v1.328.0 + with: + ruby-version: .ruby-version + + - name: Install the MySQL client library + if: matrix.database == 'mysql' + run: sudo apt-get update && sudo apt-get install -y libmysqlclient-dev + + # script/test-docker starts the database container itself, so the workflow and local runs stay identical. + - name: Run the specs + run: script/test-docker ${{ matrix.database }} ${{ matrix.activerecord }} From 068139c50a92b2b35860e41f5b9ce8f279c114ba Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 11:04:21 +0200 Subject: [PATCH 6/9] Also run the tests on pushes to modernize-test-suite and on demand Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e65ef18..fc71b3f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,8 +2,9 @@ name: Tests on: push: - branches: [master] + branches: [master, modernize-test-suite] pull_request: + workflow_dispatch: permissions: contents: read From ab03352b9ddfc54e8a0b765188476790700289d9 Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 11:19:16 +0200 Subject: [PATCH 7/9] Test a matrix of Ruby 2.7-3.2 and ActiveRecord 6.1-7.2 on GitHub Actions Replaces the 2.x-era Travis matrix with the Ruby/ActiveRecord pairs that work today. The ActiveRecord-version-dependent test pins now use a real version comparison, so ActiveRecord 7.0 is covered too. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/test.yml | 20 ++++++++++++++++---- Gemfile | 2 +- README.md | 4 ++-- flex_columns.gemspec | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc71b3f..e73ef8a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,19 +11,31 @@ permissions: jobs: test: - name: ${{ matrix.database }} / ActiveRecord ${{ matrix.activerecord }} - runs-on: ubuntu-latest + name: ruby ${{ matrix.ruby }} / ${{ matrix.database }} / ActiveRecord ${{ matrix.activerecord }} + # Ubuntu 22.04 still provides the older Rubies. + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: database: [sqlite, mysql, postgres] - activerecord: ["6.1.7.10", "7.2.3.2"] + # Explicit pairs: ActiveRecord 7.x needs Ruby 3.1+, and 6.1 is the oldest version the specs support. + include: + - { ruby: "2.7", activerecord: "6.1.7.10" } + - { ruby: "3.0", activerecord: "6.1.7.10" } + - { ruby: "3.1", activerecord: "6.1.7.10" } + - { ruby: "3.1", activerecord: "7.0.8.7" } + - { ruby: "3.1", activerecord: "7.1.5.2" } + - { ruby: "3.1", activerecord: "7.2.3.2" } + - { ruby: "3.2", activerecord: "6.1.7.10" } + - { ruby: "3.2", activerecord: "7.0.8.7" } + - { ruby: "3.2", activerecord: "7.1.5.2" } + - { ruby: "3.2", activerecord: "7.2.3.2" } steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: ruby/setup-ruby@e81a8fa391b11a595c1b7ed84177cc0fe02faf83 # v1.328.0 with: - ruby-version: .ruby-version + ruby-version: ${{ matrix.ruby }} - name: Install the MySQL client library if: matrix.database == 'mysql' diff --git a/Gemfile b/Gemfile index cd69fda..8192ca4 100644 --- a/Gemfile +++ b/Gemfile @@ -17,4 +17,4 @@ if version_spec end # concurrent-ruby 1.3.5 dropped its implicit require of 'logger', which breaks ActiveSupport < 7.1. -gem("concurrent-ruby", "< 1.3.5") if ar_version && ar_version =~ /\A[0-6]\./ +gem("concurrent-ruby", "< 1.3.5") if ar_version && ar_version =~ /\A\d/ && Gem::Version.new(ar_version) < Gem::Version.new("7.1") diff --git a/README.md b/README.md index 6471d79..96fab3d 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ while relying on the most reliable, manageable, proven data engines out there. Supported platforms: -* Ruby 3.2 (MRI). Older Rubies may work but are no longer tested. -* ActiveRecord 6.1 and 7.2 are tested; the gemspec allows 3.0 up to (but not including) 8. (Should be compatible with future versions, as well...just sits on top of the public API of ActiveRecord.) +* Ruby 2.7, 3.0, 3.1 and 3.2 (MRI). Older Rubies may work but are no longer tested. +* ActiveRecord 6.1, 7.0, 7.1 and 7.2 are tested (6.1 on every Ruby, 7.x on Ruby 3.1+); the gemspec allows 3.0 up to (but not including) 8. (Should be compatible with future versions, as well...just sits on top of the public API of ActiveRecord.) * Tested against MySQL, PostgreSQL and SQLite 3. (Should be compatible with all RDBMSes supported by ActiveRecord.) ### Running the specs diff --git a/flex_columns.gemspec b/flex_columns.gemspec index ecb76cf..6deee8a 100644 --- a/flex_columns.gemspec +++ b/flex_columns.gemspec @@ -41,7 +41,7 @@ Gem::Specification.new do |s| require File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'flex_columns', 'helpers', 'database_helper')) database_gem_name = FlexColumns::Helpers::DatabaseHelper.maybe_database_gem_name - if database_gem_name == 'sqlite3' && ar_version && ar_version =~ /\A[0-6]\./ + if database_gem_name == 'sqlite3' && ar_version && ar_version =~ /\A\d/ && Gem::Version.new(ar_version) < Gem::Version.new('7.1') # ActiveRecord before 7.1 does not accept sqlite3 2.x. s.add_development_dependency(database_gem_name, '~> 1.4') elsif database_gem_name From d8d73e6f2da93110c3b758e66b28cda360e659a4 Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 11:24:02 +0200 Subject: [PATCH 8/9] Fix the Actions matrix so every Ruby/ActiveRecord pair runs against every database Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e73ef8a..e3de3c3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ permissions: jobs: test: - name: ruby ${{ matrix.ruby }} / ${{ matrix.database }} / ActiveRecord ${{ matrix.activerecord }} + name: ruby ${{ matrix.combo.ruby }} / ${{ matrix.database }} / ActiveRecord ${{ matrix.combo.activerecord }} # Ubuntu 22.04 still provides the older Rubies. runs-on: ubuntu-22.04 strategy: @@ -19,7 +19,7 @@ jobs: matrix: database: [sqlite, mysql, postgres] # Explicit pairs: ActiveRecord 7.x needs Ruby 3.1+, and 6.1 is the oldest version the specs support. - include: + combo: - { ruby: "2.7", activerecord: "6.1.7.10" } - { ruby: "3.0", activerecord: "6.1.7.10" } - { ruby: "3.1", activerecord: "6.1.7.10" } @@ -35,7 +35,7 @@ jobs: - uses: ruby/setup-ruby@e81a8fa391b11a595c1b7ed84177cc0fe02faf83 # v1.328.0 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: ${{ matrix.combo.ruby }} - name: Install the MySQL client library if: matrix.database == 'mysql' @@ -43,4 +43,4 @@ jobs: # script/test-docker starts the database container itself, so the workflow and local runs stay identical. - name: Run the specs - run: script/test-docker ${{ matrix.database }} ${{ matrix.activerecord }} + run: script/test-docker ${{ matrix.database }} ${{ matrix.combo.activerecord }} From fe5152dbe13bc70b071578b3151ff106d6c643f8 Mon Sep 17 00:00:00 2001 From: Richard Fojta Date: Mon, 12 Oct 2026 11:28:02 +0200 Subject: [PATCH 9/9] Release 2.0.0: require Ruby 2.7+, document the dropped Ruby versions Ruby 1.8.7 through 2.6 and JRuby 1.7 (the former Travis matrix) can no longer be tested and are no longer supported; the gemspec now enforces the floor. Co-Authored-By: Claude Sonnet 5.5 --- CHANGES.md | 18 +++++++++++++++--- README.md | 2 +- flex_columns.gemspec | 2 ++ lib/flex_columns/version.rb | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6b5264d..657fd3c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,23 @@ # `flex_columns` Changelog -## 1.0.13 +## 2.0.0 + +**Breaking** + +* Requires Ruby 2.7 or newer (`required_ruby_version`). Ruby 1.8.7 through 2.6 and JRuby 1.7, which the Travis + configuration used to cover, are no longer supported or tested. The continuous-integration matrix is now Ruby 2.7 to + 3.2 with ActiveRecord 6.1 to 7.2 (SQLite, MySQL and PostgreSQL), run on GitHub Actions. +* Requires `json < 3` (ActiveSupport 7.x still passes `quirks_mode`, which json 3 removed). + +**Fixes** * Fix validation errors from a flex column being copied onto the model with a garbage attribute name on ActiveModel 6.1+ (`errors.each` yields an error object there, not a name and a message) -* Require `json < 3` (ActiveSupport 7.x still passes `quirks_mode`, which json 3 removed) -* Make the specs and development dependencies installable and passing on Ruby 3.2 (RSpec 3, ActiveRecord 6.1 and 7.2) + +**Development** + +* The specs and development dependencies install and pass on Ruby 2.7 to 3.2 (RSpec 3); `script/test-docker` runs them + against containerized databases. ## 1.0.12 diff --git a/README.md b/README.md index 96fab3d..ea8e8e2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ while relying on the most reliable, manageable, proven data engines out there. Supported platforms: -* Ruby 2.7, 3.0, 3.1 and 3.2 (MRI). Older Rubies may work but are no longer tested. +* Ruby 2.7, 3.0, 3.1 and 3.2 (MRI). Version 2.0.0 requires Ruby 2.7 or newer; earlier versions of this gem supported Ruby 1.8.7 to 2.2 and JRuby 1.7. * ActiveRecord 6.1, 7.0, 7.1 and 7.2 are tested (6.1 on every Ruby, 7.x on Ruby 3.1+); the gemspec allows 3.0 up to (but not including) 8. (Should be compatible with future versions, as well...just sits on top of the public API of ActiveRecord.) * Tested against MySQL, PostgreSQL and SQLite 3. (Should be compatible with all RDBMSes supported by ActiveRecord.) diff --git a/flex_columns.gemspec b/flex_columns.gemspec index 6deee8a..9c0eabc 100644 --- a/flex_columns.gemspec +++ b/flex_columns.gemspec @@ -13,6 +13,8 @@ Gem::Specification.new do |s| s.summary = %q{Schema-free, structured JSON storage inside a RDBMS.} s.license = "MIT" + s.required_ruby_version = ">= 2.7" + s.files = `git ls-files`.split($/) s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } s.test_files = s.files.grep(%r{^(test|spec|features)/}) diff --git a/lib/flex_columns/version.rb b/lib/flex_columns/version.rb index dbe996e..c511bf6 100644 --- a/lib/flex_columns/version.rb +++ b/lib/flex_columns/version.rb @@ -1,4 +1,4 @@ module FlexColumns # The current version of FlexColumns. - VERSION = "1.0.13" + VERSION = "2.0.0" end