Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Ruby & Rails versions on CI and fix Sequel spec failures #617

Merged
merged 5 commits into from
Mar 20, 2024
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
142 changes: 2 additions & 140 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,17 @@ jobs:
- '3.2'
- '3.1'
- '3.0'
- '2.7'
- '2.6'
database:
- 'sqlite3'
- 'mysql'
- 'postgres'
orm:
- name: 'active_record'
version: '4.2'
- name: 'active_record'
version: '5.0'
- name: 'active_record'
version: '5.1'
- name: 'active_record'
version: '5.2'
- name: 'active_record'
version: '6.0'
- name: 'active_record'
version: '6.1'
- name: 'active_record'
version: '7.0'
- name: 'active_record'
version: '7.1'
- name: 'sequel'
version: '5'
experimental: [false]
Expand All @@ -66,14 +56,6 @@ jobs:
feature: 'unit'
orm:
experimental: false
- ruby: '2.7'
feature: 'unit'
orm:
experimental: false
- ruby: '2.6'
feature: 'unit'
orm:
experimental: false
- ruby: '3.2'
feature: 'rails'
orm:
Expand Down Expand Up @@ -155,126 +137,6 @@ jobs:
- ruby: '3.0'
feature: 'i18n_fallbacks'
experimental: false
- ruby: '3.0'
database: 'sqlite3'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '3.0'
database: 'mysql'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '3.0'
database: 'postgres'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '2.7'
feature: 'rails'
orm:
name: 'active_record'
version: '7.0'
database: 'sqlite3'
experimental: false
- ruby: '2.7'
feature: 'performance'
experimental: false
- ruby: '2.7'
feature: 'i18n_fallbacks'
experimental: false
- ruby: '2.7'
database: 'sqlite3'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '2.7'
database: 'mysql'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '2.7'
database: 'postgres'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
exclude:
- ruby: '2.6'
orm:
name: 'active_record'
version: '7.0'
- ruby: '2.7'
orm:
name: 'active_record'
version: '4.2'
- ruby: '3.0'
orm:
name: 'active_record'
version: '4.2'
- ruby: '3.0'
orm:
name: 'active_record'
version: '5.0'
- ruby: '3.0'
orm:
name: 'active_record'
version: '5.1'
- ruby: '3.0'
orm:
name: 'active_record'
version: '5.2'
- ruby: '3.1'
orm:
name: 'active_record'
version: '4.2'
- ruby: '3.1'
orm:
name: 'active_record'
version: '5.0'
- ruby: '3.1'
orm:
name: 'active_record'
version: '5.1'
- ruby: '3.1'
orm:
name: 'active_record'
version: '5.2'
- ruby: '3.1'
orm:
name: 'active_record'
version: '6.0'
- ruby: '3.2'
orm:
name: 'active_record'
version: '4.2'
- ruby: '3.2'
orm:
name: 'active_record'
version: '5.0'
- ruby: '3.2'
orm:
name: 'active_record'
version: '5.1'
- ruby: '3.2'
orm:
name: 'active_record'
version: '5.2'
- ruby: '3.2'
orm:
name: 'active_record'
version: '6.0'

env:
DB: ${{ matrix.database }}
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ group :development, :test do
when 'active_record'
orm_version ||= '7.0'
case orm_version
when '4.2', '5.0', '5.1', '5.2', '6.0', '6.1', '7.0'
when '6.1', '7.0', '7.1'
gem 'activerecord', "~> #{orm_version}.0"
when 'edge'
git 'https://github.com/rails/rails.git', branch: 'main' do
Expand Down
8 changes: 7 additions & 1 deletion lib/mobility/backends/active_record/serialized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ def self.build_node(attr, _locale)

setup do |attributes, options|
coder = { yaml: YAMLCoder, json: JSONCoder }[options[:format]]
attributes.each { |attribute| serialize (options[:column_affix] % attribute), coder }
attributes.each do |attribute|
if (::ActiveRecord::VERSION::STRING >= "7.1")
serialize (options[:column_affix] % attribute), coder: coder
else
serialize (options[:column_affix] % attribute), coder
end
end
end

# @!group Cache Methods
Expand Down
7 changes: 1 addition & 6 deletions spec/active_record/schema.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module Mobility
module Test
if ::ActiveRecord::VERSION::MAJOR < 5
parent_class = ::ActiveRecord::Migration
else
parent_class = ::ActiveRecord::Migration[[::ActiveRecord::VERSION::MAJOR, ::ActiveRecord::VERSION::MINOR].join(".")]
end
class Schema < parent_class
class Schema < ::ActiveRecord::Migration[[::ActiveRecord::VERSION::MAJOR, ::ActiveRecord::VERSION::MINOR].join(".")]
class << self
def up
create_table "posts" do |t|
Expand Down
12 changes: 2 additions & 10 deletions spec/generators/rails/mobility/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
directory "db" do
directory "migrate" do
migration "create_text_translations" do
if ActiveRecord::VERSION::MAJOR < 5
contains "class CreateTextTranslations < ActiveRecord::Migration"
else
contains "class CreateTextTranslations < ActiveRecord::Migration[#{version_string_}]"
end
contains "class CreateTextTranslations < ActiveRecord::Migration[#{version_string_}]"
contains "def change"
contains "create_table :mobility_text_translations"
contains "t.text :value"
Expand All @@ -67,11 +63,7 @@
directory "db" do
directory "migrate" do
migration "create_string_translations" do
if ActiveRecord::VERSION::MAJOR < 5
contains "class CreateStringTranslations < ActiveRecord::Migration"
else
contains "class CreateStringTranslations < ActiveRecord::Migration[#{version_string_}]"
end
contains "class CreateStringTranslations < ActiveRecord::Migration[#{version_string_}]"
contains "def change"
contains "create_table :mobility_string_translations"
contains "t.string :value"
Expand Down
18 changes: 3 additions & 15 deletions spec/generators/rails/mobility/translations_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@
directory "db" do
directory "migrate" do
migration "create_post_title_and_content_translations_for_mobility_table_backend" do
if ActiveRecord::VERSION::MAJOR < 5
contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration"
else
contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration[#{version_string_}]"
end
contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration[#{version_string_}]"
contains "def change"
contains "create_table :post_translations"
contains "t.string :title"
Expand Down Expand Up @@ -110,11 +106,7 @@
directory "db" do
directory "migrate" do
migration "create_post_title_and_content_translations_for_mobility_table_backend" do
if ActiveRecord::VERSION::MAJOR < 5
contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration"
else
contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration[#{version_string_}]"
end
contains "class CreatePostTitleAndContentTranslationsForMobilityTableBackend < ActiveRecord::Migration[#{version_string_}]"
contains "add_column :post_translations, :title, :string"
contains "add_index :post_translations, [:title, :locale], name: :index_post_translations_on_title_and_locale"
contains "add_column :post_translations, :content, :text"
Expand Down Expand Up @@ -158,11 +150,7 @@
directory "db" do
directory "migrate" do
migration "create_foo_title_and_content_translations_for_mobility_column_backend" do
if ActiveRecord::VERSION::MAJOR < 5
contains "class CreateFooTitleAndContentTranslationsForMobilityColumnBackend < ActiveRecord::Migration"
else
contains "class CreateFooTitleAndContentTranslationsForMobilityColumnBackend < ActiveRecord::Migration[#{version_string_}]"
end
contains "class CreateFooTitleAndContentTranslationsForMobilityColumnBackend < ActiveRecord::Migration[#{version_string_}]"
contains "add_column :foos, :title_en, :string"
contains "add_index :foos, :title_en, name: :index_foos_on_title_en"
contains "add_column :foos, :title_ja, :string"
Expand Down
2 changes: 1 addition & 1 deletion spec/mobility/backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def self.foobar

it "returns value when configured" do
model_class = double("model class")
options = double("options")
options = {}
subclass = backend_class.build_subclass(model_class, options)
expect(subclass.model_class).to eq(model_class)
expect(subclass.options).to eq(options)
Expand Down
2 changes: 1 addition & 1 deletion spec/mobility/backends/active_record/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
m.drop_table :json_container_posts
end
include_accessor_examples 'JsonContainerPost'
include_querying_examples 'JsonContainerPost' unless ActiveRecord::VERSION::MAJOR < 5
include_querying_examples 'JsonContainerPost'
end

context "with a non-json/jsonb column" do
Expand Down
2 changes: 1 addition & 1 deletion spec/mobility/backends/active_record/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
plugins :active_record, :reader, :writer, :query
before { translates JsonPost, :title, :content, backend: :json, **column_options }

include_querying_examples 'JsonPost' unless ActiveRecord::VERSION::MAJOR < 5
include_querying_examples 'JsonPost'
include_validation_examples 'JsonPost'
end

Expand Down
2 changes: 0 additions & 2 deletions spec/mobility/backends/active_record/serialized_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
post = SerializedPost.new
post.title = "foo"
post.save
post.reload if ActiveRecord::VERSION::MAJOR < 5 # don't ask me why
expect(post.public_send("#{(column_affix % "title")}_before_type_cast")).to eq("---\n:en: foo\n")
end

Expand Down Expand Up @@ -70,7 +69,6 @@
post = SerializedPost.new
post.title = "foo"
post.save
post.reload if ActiveRecord::VERSION::MAJOR < 5 # don't ask me why
expect(post.public_send("#{column_affix % "title"}_before_type_cast")).to eq("{\"en\":\"foo\"}")
end
end
Expand Down
18 changes: 7 additions & 11 deletions spec/mobility/plugins/active_model/dirty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,15 @@ def save
expect(instance.title_changed?).to eq(false)
expect(instance.attribute_changed?(:title_en)).to eq(false)

if ActiveRecord::VERSION::MAJOR >= 5
expect(instance.title_previously_changed?).to eq(true)
expect(instance.title_previous_change).to eq(["foo", "bar"])
expect(instance.title_changed?).to eq(false)
expect(instance.title_previously_changed?).to eq(true)
expect(instance.title_previous_change).to eq(["foo", "bar"])
expect(instance.title_changed?).to eq(false)

expect(instance.attribute_previously_changed?(:title_en)).to eq(true)
expect(instance.attribute_changed?(:title_en)).to eq(false)
expect(instance.attribute_previously_changed?(:title_en)).to eq(true)
expect(instance.attribute_changed?(:title_en)).to eq(false)

if ActiveRecord::VERSION::STRING >= '6.1'
expect(instance.title_previously_was).to eq('foo')
expect(instance.attribute_previously_was(:title_en)).to eq('foo')
end
end
expect(instance.title_previously_was).to eq('foo')
expect(instance.attribute_previously_was(:title_en)).to eq('foo')

instance.title_will_change!
expect(instance.title_changed?).to eq(true)
Expand Down
6 changes: 1 addition & 5 deletions spec/mobility/plugins/active_record/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
model_class.include translations

instance = model_class.create
if ::ActiveRecord::VERSION::MAJOR == 4
expect(instance.mobility_backends[:title]).to receive(:clear_cache).at_least(1).time
else
expect(instance.mobility_backends[:title]).to receive(:clear_cache).once
end
expect(instance.mobility_backends[:title]).to receive(:clear_cache).once
instance.reload
end
end
Loading
Loading