Skip to content

Commit

Permalink
Merge pull request #170 from madeintandem/rails-7.1-drop-support-for-…
Browse files Browse the repository at this point in the history
…enums

Drop support for ActiveRecord::Enum
  • Loading branch information
haffla authored Oct 15, 2023
2 parents f1c2db8 + 221f7e8 commit 120767d
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 15 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
needs: lint
services:
db:
image: postgres:9.4
image: postgres
env:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: jsonb_accessor
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
- gemfile: activerecord_6.1.0
ruby: '2.7'

- gemfile: activerecord_7.0.1
- gemfile: activerecord_7.0.8
ruby: '2.7'

- gemfile: activerecord_6.1.0
Expand All @@ -102,13 +102,22 @@ jobs:
- gemfile: activerecord_6.1.0
ruby: '3.2'

- gemfile: activerecord_7.0.1
- gemfile: activerecord_7.0.8
ruby: '3.0'

- gemfile: activerecord_7.0.1
- gemfile: activerecord_7.0.8
ruby: '3.1'

- gemfile: activerecord_7.0.1
- gemfile: activerecord_7.0.8
ruby: '3.2'

- gemfile: activerecord_7.1
ruby: '3.0'

- gemfile: activerecord_7.1
ruby: '3.1'

- gemfile: activerecord_7.1
ruby: '3.2'

- gemfile: activerecord_5.1.0
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ end
appraise "activerecord-7.0.8" do
gem "activerecord", "~> 7.0.8"
end

appraise "activerecord-7.1" do
gem "activerecord", "~> 7.1"
end
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require "rspec"
require File.expand_path("../spec/spec_helper.rb", __dir__)

dbconfig = YAML.safe_load(ERB.new(File.read(File.join("db", "config.yml"))).result, aliases: true)
ActiveRecord::Base.establish_connection(dbconfig["development"])
ActiveRecord::Base.establish_connection(dbconfig["test"])

# rubocop:disable Lint/UselessAssignment
x = Product.new
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2015_04_07_031737) do
ActiveRecord::Schema.define(version: 2015_04_07_031737) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:


postgres:
image: postgres:12
image: postgres
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_DB=jsonb_accessor
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/activerecord_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 7.1"

gemspec path: "../"
4 changes: 2 additions & 2 deletions jsonb_accessor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "activerecord", ">= 5.0", "< 7.1"
spec.add_dependency "activesupport", ">= 5.0", "< 7.1"
spec.add_dependency "activerecord", ">= 5.0"
spec.add_dependency "activesupport", ">= 5.0"
if is_java
spec.add_dependency "activerecord-jdbcpostgresql-adapter", ">= 50.0"
else
Expand Down
5 changes: 5 additions & 0 deletions lib/jsonb_accessor/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

module JsonbAccessor
VERSION = "1.3.10"

def self.enum_support?
# From AR 7.1 on, enums require a database column.
Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("7.1")
end
end
12 changes: 7 additions & 5 deletions spec/jsonb_accessor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def build_class(jsonb_accessor_config, &block)
bazzle: [:integer, { default: 5 }],
dates: [:datetime, { array: true }]
) do
enum ban: { foo: 1, bar: 2 }
enum ban: { foo: 1, bar: 2 } if JsonbAccessor.enum_support?
end
end
let(:instance) { klass.new }
Expand Down Expand Up @@ -74,10 +74,12 @@ def build_class(jsonb_accessor_config, &block)
expect(instance.bazzle).to eq(5)
end

it "supports enums" do
instance.ban = :foo
expect(instance.ban).to eq("foo")
expect(instance.options["ban"]).to eq(1)
if JsonbAccessor.enum_support?
it "supports enums" do
instance.ban = :foo
expect(instance.ban).to eq("foo")
expect(instance.options["ban"]).to eq(1)
end
end

it "initializes without the jsonb_accessor field selected" do
Expand Down

0 comments on commit 120767d

Please sign in to comment.