diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e3de3c3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: Tests + +on: + push: + branches: [master, modernize-test-suite] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + 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: + fail-fast: false + matrix: + database: [sqlite, mysql, postgres] + # Explicit pairs: ActiveRecord 7.x needs Ruby 3.1+, and 6.1 is the oldest version the specs support. + 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" } + - { 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: ${{ matrix.combo.ruby }} + + - 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.combo.activerecord }} 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..657fd3c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,24 @@ # `flex_columns` Changelog +## 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) + +**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 * Relax ActiveRecord/ActiveSupport constraints to allow Rails 7.x (`< 8`) diff --git a/Gemfile b/Gemfile index 9c0f13b..8192ca4 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\d/ && Gem::Version.new(ar_version) < Gem::Version.new("7.1") diff --git a/README.md b/README.md index 8551269..ea8e8e2 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,44 @@ 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 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.) -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 +``` + +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: + +```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 diff --git a/flex_columns.gemspec b/flex_columns.gemspec index 7c99c86..9c0eabc 100644 --- a/flex_columns.gemspec +++ b/flex_columns.gemspec @@ -13,16 +13,17 @@ 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)/}) 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 +40,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\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 s.add_development_dependency(database_gem_name) end end 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/lib/flex_columns/version.rb b/lib/flex_columns/version.rb index 3ce1c04..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.12" + VERSION = "2.0.0" end 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! 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)