Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.8
69 changes: 0 additions & 69 deletions .travis.yml

This file was deleted.

19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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`)
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 9 additions & 17 deletions flex_columns.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 9 additions & 1 deletion lib/flex_columns/contents/flex_column_contents_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/flex_columns/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FlexColumns
# The current version of FlexColumns.
VERSION = "1.0.12"
VERSION = "2.0.0"
end
Loading