From db4a118ebd923f761f6b6558a7561814e19189b7 Mon Sep 17 00:00:00 2001 From: Joseph Southan Date: Fri, 3 Nov 2023 14:54:02 +0000 Subject: [PATCH 1/4] Fixup deprecation in Rails 7.2 --- .github/workflows/tests.yml | 2 ++ .ruby-version | 2 +- lib/statesman/adapters/active_record_transition.rb | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 56717533..3d24115c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,6 +28,7 @@ jobs: rails-version: - "6.1.5" - "7.0.4" + - "7.1.1" - "main" postgres-version: ["9.6", "11", "14"] exclude: @@ -70,6 +71,7 @@ jobs: rails-version: - "6.1.5" - "7.0.4" + - "7.1.1" - "main" mysql-version: ["5.7", "8.0"] exclude: diff --git a/.ruby-version b/.ruby-version index 944880fa..be94e6f5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.0 +3.2.2 diff --git a/lib/statesman/adapters/active_record_transition.rb b/lib/statesman/adapters/active_record_transition.rb index bdbb6c15..63141001 100644 --- a/lib/statesman/adapters/active_record_transition.rb +++ b/lib/statesman/adapters/active_record_transition.rb @@ -10,7 +10,11 @@ module ActiveRecordTransition extend ActiveSupport::Concern included do - serialize :metadata, JSON + if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.1") + serialize :metadata, coder: JSON + else + serialize :metadata, JSON + end class_attribute :updated_timestamp_column self.updated_timestamp_column = DEFAULT_UPDATED_TIMESTAMP_COLUMN From cfea282535626f467164ddd482c9275e88f2118b Mon Sep 17 00:00:00 2001 From: Joseph Southan Date: Fri, 3 Nov 2023 15:18:50 +0000 Subject: [PATCH 2/4] Fixup more deprecations and remove explict serialises --- Gemfile | 4 +- lib/statesman/adapters/active_record.rb | 9 +---- .../adapters/active_record_transition.rb | 2 +- spec/spec_helper.rb | 4 +- .../adapters/active_record_queries_spec.rb | 2 +- spec/statesman/adapters/active_record_spec.rb | 38 ++++++------------- .../adapters/active_record_transition_spec.rb | 6 ++- .../type_safe_active_record_queries_spec.rb | 2 +- spec/support/active_record.rb | 10 ++--- 9 files changed, 29 insertions(+), 48 deletions(-) diff --git a/Gemfile b/Gemfile index 012d1a45..a258f5dd 100644 --- a/Gemfile +++ b/Gemfile @@ -9,8 +9,8 @@ if ENV['RAILS_VERSION'] == 'main' elsif ENV['RAILS_VERSION'] gem "rails", "~> #{ENV['RAILS_VERSION']}" end + group :development do - # test/unit is no longer bundled with Ruby 2.2, but required by Rails gem "pry" - gem "test-unit", "~> 3.3" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0") + gem "test-unit", "~> 3.3" end diff --git a/lib/statesman/adapters/active_record.rb b/lib/statesman/adapters/active_record.rb index 5176d2af..ff7b3b9f 100644 --- a/lib/statesman/adapters/active_record.rb +++ b/lib/statesman/adapters/active_record.rb @@ -246,13 +246,8 @@ def next_sort_key end def serialized?(transition_class) - if ::ActiveRecord.respond_to?(:gem_version) && - ::ActiveRecord.gem_version >= Gem::Version.new("4.2.0.a") - transition_class.type_for_attribute("metadata"). - is_a?(::ActiveRecord::Type::Serialized) - else - transition_class.serialized_attributes.include?("metadata") - end + transition_class.type_for_attribute("metadata"). + is_a?(::ActiveRecord::Type::Serialized) end def transition_conflict_error?(err) diff --git a/lib/statesman/adapters/active_record_transition.rb b/lib/statesman/adapters/active_record_transition.rb index 63141001..c25eb03d 100644 --- a/lib/statesman/adapters/active_record_transition.rb +++ b/lib/statesman/adapters/active_record_transition.rb @@ -10,7 +10,7 @@ module ActiveRecordTransition extend ActiveSupport::Concern included do - if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.1") + if ::ActiveRecord.gem_version >= Gem::Version.new("7.1") serialize :metadata, coder: JSON else serialize :metadata, JSON diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c269171e..f0775b9e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,7 +40,7 @@ def connection_failure ActiveRecord::Migration.verbose = false end - config.before(:each, active_record: true) do + config.before(:each, :active_record) do tables = %w[ my_active_record_models my_active_record_model_transitions @@ -82,7 +82,5 @@ def prepare_sti_transitions_table CreateStiActiveRecordModelTransitionMigration.migrate(:up) StiActiveRecordModelTransition.reset_column_information end - - MyNamespace::MyActiveRecordModelTransition.serialize(:metadata, JSON) end end diff --git a/spec/statesman/adapters/active_record_queries_spec.rb b/spec/statesman/adapters/active_record_queries_spec.rb index e57dc9e6..e3f725d9 100644 --- a/spec/statesman/adapters/active_record_queries_spec.rb +++ b/spec/statesman/adapters/active_record_queries_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe Statesman::Adapters::ActiveRecordQueries, active_record: true do +describe Statesman::Adapters::ActiveRecordQueries, :active_record do def configure_old(klass, transition_class) klass.define_singleton_method(:transition_class) { transition_class } klass.define_singleton_method(:initial_state) { :initial } diff --git a/spec/statesman/adapters/active_record_spec.rb b/spec/statesman/adapters/active_record_spec.rb index db55c04b..a0950b4b 100644 --- a/spec/statesman/adapters/active_record_spec.rb +++ b/spec/statesman/adapters/active_record_spec.rb @@ -5,12 +5,12 @@ require "statesman/adapters/shared_examples" require "statesman/exceptions" -describe Statesman::Adapters::ActiveRecord, active_record: true do +describe Statesman::Adapters::ActiveRecord, :active_record do before do prepare_model_table prepare_transitions_table - MyActiveRecordModelTransition.serialize(:metadata, JSON) + # MyActiveRecordModelTransition.serialize(:metadata, JSON) prepare_sti_model_table prepare_sti_transitions_table @@ -38,15 +38,9 @@ allow(metadata_column).to receive_messages(sql_type: "") allow(MyActiveRecordModelTransition).to receive_messages(columns_hash: { "metadata" => metadata_column }) - if ActiveRecord.respond_to?(:gem_version) && - ActiveRecord.gem_version >= Gem::Version.new("4.2.0.a") - expect(MyActiveRecordModelTransition). - to receive(:type_for_attribute).with("metadata"). - and_return(ActiveRecord::Type::Value.new) - else - expect(MyActiveRecordModelTransition). - to receive_messages(serialized_attributes: {}) - end + expect(MyActiveRecordModelTransition). + to receive(:type_for_attribute).with("metadata"). + and_return(ActiveRecord::Type::Value.new) end it "raises an exception" do @@ -91,18 +85,12 @@ allow(metadata_column).to receive_messages(sql_type: "jsonb") allow(MyActiveRecordModelTransition).to receive_messages(columns_hash: { "metadata" => metadata_column }) - if ActiveRecord.respond_to?(:gem_version) && - ActiveRecord.gem_version >= Gem::Version.new("4.2.0.a") - serialized_type = ActiveRecord::Type::Serialized.new( - "", ActiveRecord::Coders::JSON - ) - expect(MyActiveRecordModelTransition). - to receive(:type_for_attribute).with("metadata"). - and_return(serialized_type) - else - expect(MyActiveRecordModelTransition). - to receive_messages(serialized_attributes: { "metadata" => "" }) - end + serialized_type = ActiveRecord::Type::Serialized.new( + "", ActiveRecord::Coders::JSON + ) + expect(MyActiveRecordModelTransition). + to receive(:type_for_attribute).with("metadata"). + and_return(serialized_type) end it "raises an exception" do @@ -467,10 +455,6 @@ CreateNamespacedARModelTransitionMigration.migrate(:up) end - before do - MyNamespace::MyActiveRecordModelTransition.serialize(:metadata, JSON) - end - let(:observer) { double(Statesman::Machine, execute: nil) } let(:model) do MyNamespace::MyActiveRecordModel.create(current_state: :pending) diff --git a/spec/statesman/adapters/active_record_transition_spec.rb b/spec/statesman/adapters/active_record_transition_spec.rb index b321d7eb..d97b8a9b 100644 --- a/spec/statesman/adapters/active_record_transition_spec.rb +++ b/spec/statesman/adapters/active_record_transition_spec.rb @@ -8,7 +8,11 @@ describe "including behaviour" do it "calls Class.serialize" do - expect(transition_class).to receive(:serialize).with(:metadata, JSON).once + if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.1") + expect(transition_class).to receive(:serialize).with(:metadata, coder: JSON).once + else + expect(transition_class).to receive(:serialize).with(:metadata, JSON).once + end transition_class.send(:include, described_class) end end diff --git a/spec/statesman/adapters/type_safe_active_record_queries_spec.rb b/spec/statesman/adapters/type_safe_active_record_queries_spec.rb index c5c68a59..215c7ed6 100644 --- a/spec/statesman/adapters/type_safe_active_record_queries_spec.rb +++ b/spec/statesman/adapters/type_safe_active_record_queries_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe Statesman::Adapters::TypeSafeActiveRecordQueries, active_record: true do +describe Statesman::Adapters::TypeSafeActiveRecordQueries, :active_record do def configure(klass, transition_class) klass.send(:extend, described_class) klass.configure_state_machine( diff --git a/spec/support/active_record.rb b/spec/support/active_record.rb index 2b30578c..82d739ed 100644 --- a/spec/support/active_record.rb +++ b/spec/support/active_record.rb @@ -24,7 +24,6 @@ class MyActiveRecordModelTransition < ActiveRecord::Base include Statesman::Adapters::ActiveRecordTransition belongs_to :my_active_record_model - serialize :metadata, JSON end class MyActiveRecordModel < ActiveRecord::Base @@ -51,7 +50,11 @@ class MyActiveRecordModelTransitionWithoutInclude < ActiveRecord::Base self.table_name = "my_active_record_model_transitions" belongs_to :my_active_record_model - serialize :metadata, JSON + if ::ActiveRecord.gem_version >= Gem::Version.new("7.1") + serialize :metadata, coder: JSON + else + serialize :metadata, JSON + end end class CreateMyActiveRecordModelMigration < MIGRATION_CLASS @@ -129,7 +132,6 @@ class OtherActiveRecordModelTransition < ActiveRecord::Base include Statesman::Adapters::ActiveRecordTransition belongs_to :other_active_record_model - serialize :metadata, JSON end class CreateOtherActiveRecordModelMigration < MIGRATION_CLASS @@ -221,7 +223,6 @@ class MyActiveRecordModelTransition < ActiveRecord::Base belongs_to :my_active_record_model, class_name: "MyNamespace::MyActiveRecordModel" - serialize :metadata, JSON def self.table_name_prefix "my_namespace_" @@ -310,7 +311,6 @@ class StiActiveRecordModelTransition < ActiveRecord::Base include Statesman::Adapters::ActiveRecordTransition belongs_to :sti_active_record_model - serialize :metadata, JSON end class StiAActiveRecordModelTransition < StiActiveRecordModelTransition From 3bc3e8c1bb16ea0337743bf127f3b0c6019fe74d Mon Sep 17 00:00:00 2001 From: Joseph Southan Date: Fri, 3 Nov 2023 15:25:53 +0000 Subject: [PATCH 3/4] Update build matrix Deprecate: - Ruby 2.7 - MySql 5.5 - Postgres 9.6..11 --- .github/workflows/tests.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3d24115c..3cc0fd7b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,16 +24,16 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ["2.7", "3.0", "3.1", "3.2"] + ruby-version: ["3.0", "3.1", "3.2"] rails-version: - - "6.1.5" - - "7.0.4" + - "6.1.7.6" + - "7.0.8" - "7.1.1" - "main" - postgres-version: ["9.6", "11", "14"] + postgres-version: ["12", "13", "14", "15", "16"] exclude: - ruby-version: "3.2" - rails-version: "6.1.5" + rails-version: "6.1.7.6" runs-on: ubuntu-latest services: postgres: @@ -67,16 +67,16 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ["2.7", "3.0", "3.1", "3.2"] + ruby-version: ["3.0", "3.1", "3.2"] rails-version: - - "6.1.5" - - "7.0.4" + - "6.1.7.6" + - "7.0.8" - "7.1.1" - "main" - mysql-version: ["5.7", "8.0"] + mysql-version: ["8.0", "8.2"] exclude: - ruby-version: 3.2 - rails-version: "6.1.5" + rails-version: "6.1.7.6" runs-on: ubuntu-latest services: mysql: From 517b3521e2cfc35ca67848aec171eebaa2f0732c Mon Sep 17 00:00:00 2001 From: Joseph Southan Date: Fri, 3 Nov 2023 15:32:22 +0000 Subject: [PATCH 4/4] Bump v11.0.0 --- CHANGELOG.md | 9 +++++++++ lib/statesman/version.rb | 2 +- spec/statesman/exceptions_spec.rb | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eb4a9f7..a94b8ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v11.0.0 3rd November 2023 + +### Changed +- Updated to support ActiveRecord > 7.2 +- Remove support for: + - Ruby; 2.7 + - Postgres; 9.6, 10, 11 + - MySQL; 5.7 + ## v10.2.3 2nd Aug 2023 ### Changed diff --git a/lib/statesman/version.rb b/lib/statesman/version.rb index 62573a4f..bdb77a11 100644 --- a/lib/statesman/version.rb +++ b/lib/statesman/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Statesman - VERSION = "10.2.3" + VERSION = "11.0.0" end diff --git a/spec/statesman/exceptions_spec.rb b/spec/statesman/exceptions_spec.rb index 275a6d60..3f1eefdb 100644 --- a/spec/statesman/exceptions_spec.rb +++ b/spec/statesman/exceptions_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe Statesman do +describe "Exceptions" do describe "InvalidStateError" do subject(:error) { Statesman::InvalidStateError.new }