From 77e7330ea3a02d814a1b379569c00b15bdd0c0a1 Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Tue, 27 Aug 2024 12:06:50 +0900 Subject: [PATCH 1/6] CI: refactor name with rails version --- .github/workflows/test_ruby_2_7.yml | 2 +- .github/workflows/test_ruby_3_0.yml | 2 +- .github/workflows/test_ruby_3_2.yml | 0 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test_ruby_3_2.yml diff --git a/.github/workflows/test_ruby_2_7.yml b/.github/workflows/test_ruby_2_7.yml index 3f1051b4..d9c95dbb 100644 --- a/.github/workflows/test_ruby_2_7.yml +++ b/.github/workflows/test_ruby_2_7.yml @@ -1,5 +1,5 @@ name: Exec Rspec -run-name: Matrix building for ruby 2.7 ✖️ 【rails 5.0 - 6.0】 🚀 +run-name: Matrix building for ruby 2.7 ✖️ 【rails 5.0 - 6.1】 🚀 on: [push] jobs: diff --git a/.github/workflows/test_ruby_3_0.yml b/.github/workflows/test_ruby_3_0.yml index a763e5cd..06a92116 100644 --- a/.github/workflows/test_ruby_3_0.yml +++ b/.github/workflows/test_ruby_3_0.yml @@ -1,5 +1,5 @@ name: Exec Rspec -run-name: Matrix building for ruby 3.0 ✖️ 【rails 6.0】 🚀 +run-name: Matrix building for ruby 3.0 ✖️ 【rails 6.0 - 6.1】 🚀 on: [push] jobs: diff --git a/.github/workflows/test_ruby_3_2.yml b/.github/workflows/test_ruby_3_2.yml new file mode 100644 index 00000000..e69de29b From 4341e121261a03ec49bf932b02142b5fb8792344 Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Tue, 27 Aug 2024 12:15:53 +0900 Subject: [PATCH 2/6] CI: add config for Ruby 3.2 --- .github/workflows/test_ruby_3_2.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/workflows/test_ruby_3_2.yml b/.github/workflows/test_ruby_3_2.yml index e69de29b..0d72c963 100644 --- a/.github/workflows/test_ruby_3_2.yml +++ b/.github/workflows/test_ruby_3_2.yml @@ -0,0 +1,29 @@ +name: Exec Rspec +run-name: Matrix building for ruby 3.2 ✖️ 【rails 6.1】 🚀 +on: [push] + +jobs: + ruby_3_2: + strategy: + fail-fast: false + matrix: + arversion: ['6_1_0', '6_1_1', '6_1_2', '6_1_3', '6_1_4', '6_1_5', '6_1_6', '6_1_7'] + runs-on: ubuntu-22.04 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails${{ matrix.arversion }}.gemfile + MYSQL_PWD: root + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler: latest + bundler-cache: true + - name: Start mysql + run: sudo systemctl start mysql.service + - name: Reset DB + run: bundle exec rake turntable:db:reset + - name: Run RSpec + run: RUBYOPT='-W:deprecated' bundle exec rake spec From ae8f4f8fa428d318369e30ec78877873f575f1de Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Tue, 27 Aug 2024 12:43:36 +0900 Subject: [PATCH 3/6] Fix: YAML.load to compatible Ruby 3.2 --- Rakefile | 2 +- lib/active_record/turntable/configuration/loader/yaml.rb | 2 +- .../turntable/active_record_ext/fixture_set_spec.rb | 2 +- .../turntable/active_record_ext/test_fixtures_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 16c6c7cf..089723fa 100644 --- a/Rakefile +++ b/Rakefile @@ -27,7 +27,7 @@ namespace :turntable do task :load_config => :rails_env do yaml_file = File.join(File.dirname(__FILE__), "spec/config/database.yml") - ActiveRecord::Base.configurations = YAML.load ERB.new(IO.read(yaml_file)).result + ActiveRecord::Base.configurations = YAML.safe_load ERB.new(IO.read(yaml_file)).result, permitted_classes: [Symbol], aliases: true end desc "create turntable test database" diff --git a/lib/active_record/turntable/configuration/loader/yaml.rb b/lib/active_record/turntable/configuration/loader/yaml.rb index 5548dc15..193e2ef7 100644 --- a/lib/active_record/turntable/configuration/loader/yaml.rb +++ b/lib/active_record/turntable/configuration/loader/yaml.rb @@ -14,7 +14,7 @@ def self.load(path, env, configuration = Configuration.new) end def load(env) - yaml = YAML.load(ERB.new(IO.read(path)).result).with_indifferent_access[env] + yaml = YAML.safe_load(ERB.new(IO.read(path)).result, permitted_classes: [Symbol], aliases: true).with_indifferent_access[env] load_clusters(yaml[:clusters]) load_global_settings(yaml) diff --git a/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb b/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb index f2ea8fdd..95f33f45 100644 --- a/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb +++ b/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb @@ -6,7 +6,7 @@ describe ActiveRecord::FixtureSet do let(:fixtures_root) { File.join(File.dirname(__FILE__), "../../../fixtures") } let(:fixture_file) { File.join(fixtures_root, "items.yml") } - let(:items) { YAML.load(ERB.new(IO.read(fixture_file)).result) } + let(:items) { YAML.safe_load(ERB.new(IO.read(fixture_file)).result) } before do ActiveRecord::FixtureSet.reset_cache diff --git a/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb b/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb index f8a8dfb2..15c5316b 100644 --- a/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb +++ b/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb @@ -12,7 +12,7 @@ let(:fixture_file) { File.join(fixtures_root, "items.yml") } let(:test_fixture_class) { Class.new(ActiveSupport::TestCase) { include ActiveRecord::TestFixtures } } let(:test_fixture) { test_fixture_class.new("test") } - let(:items) { YAML.load(ERB.new(IO.read(fixture_file)).result) } + let(:items) { YAML.safe_load(ERB.new(IO.read(fixture_file)).result) } describe "#setup_fixtures" do after do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a8ccfdf4..8c0c4e63 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,7 +44,7 @@ # in ./support/ and its subdirectories. database_yaml = File.read(File.join(File.dirname(__FILE__), "config/database.yml")) database_yaml = ERB.new(database_yaml).result -ActiveRecord::Base.configurations = YAML.load(database_yaml) +ActiveRecord::Base.configurations = YAML.safe_load(database_yaml, permitted_classes: [Symbol], aliases: true) ActiveRecord::Base.establish_connection(:test) Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } From d9ba72b4f4212c4db4fca6274ac299b2857a6020 Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Tue, 27 Aug 2024 13:16:40 +0900 Subject: [PATCH 4/6] Fix: Object#=~ for Ruby 3.2 --- lib/active_record/turntable/connection_proxy/mixable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_record/turntable/connection_proxy/mixable.rb b/lib/active_record/turntable/connection_proxy/mixable.rb index 247c4cfb..6f926730 100644 --- a/lib/active_record/turntable/connection_proxy/mixable.rb +++ b/lib/active_record/turntable/connection_proxy/mixable.rb @@ -9,8 +9,8 @@ module Mixable def mixable?(method, *args) (method.to_s =~ METHODS_REGEXP && - args.first !~ EXCLUDE_QUERY_REGEXP) || - (method.to_s == "execute" && args.first =~ QUERY_REGEXP) + !(args.first.is_a?(String) && args.first =~ EXCLUDE_QUERY_REGEXP)) || + (method.to_s == "execute" && (args.first.is_a?(String) && args.first =~ QUERY_REGEXP)) end end end From 6fa2ffa04b1d48859ff523ca98c3a9cc36f4f9e1 Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Tue, 27 Aug 2024 13:17:02 +0900 Subject: [PATCH 5/6] Fix: Struct kwargs for Ruby 3.2 --- .../turntable/active_record_ext/log_subscriber_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/active_record/turntable/active_record_ext/log_subscriber_spec.rb b/spec/active_record/turntable/active_record_ext/log_subscriber_spec.rb index 27d468a1..3fdfd93f 100644 --- a/spec/active_record/turntable/active_record_ext/log_subscriber_spec.rb +++ b/spec/active_record/turntable/active_record_ext/log_subscriber_spec.rb @@ -34,23 +34,23 @@ def duration it "ignore SCHEMA log" do expect(subscriber.debugs.length).to eq 0 - subscriber.sql(TestEvent.new(name: "bar", turntable_shard_name: "shard_1")) + subscriber.sql(TestEvent.new({name: "bar", turntable_shard_name: "shard_1"})) expect(subscriber.debugs.length).to eq 1 - subscriber.sql(TestEvent.new(name: "SCHEMA", turntable_shard_name: "shard_1")) + subscriber.sql(TestEvent.new({name: "SCHEMA", turntable_shard_name: "shard_1"})) expect(subscriber.debugs.length).to eq 1 end context "When payload name is `SQL`" do it "logs in MAGENTA color" do - subscriber.sql(TestEvent.new(name: "SQL", turntable_shard_name: "shard_1")) + subscriber.sql(TestEvent.new({name: "SQL", turntable_shard_name: "shard_1"})) expect(subscriber.debugs.first).to match(/#{REGEXP_MAGENTA}SQL \(0\.7ms\) \[Shard: shard_1\]#{REGEXP_CLEAR}/) end end context "When payload name is `Model Load`" do it "logs in CYAN color" do - subscriber.sql(TestEvent.new(name: "Model Load", turntable_shard_name: "shard_1")) + subscriber.sql(TestEvent.new({name: "Model Load", turntable_shard_name: "shard_1"})) expect(subscriber.debugs.first).to match(/#{REGEXP_CYAN}Model Load \(0\.7ms\) \[Shard: shard_1\]#{REGEXP_CLEAR}/) end end @@ -59,7 +59,7 @@ def duration it "logs binds parameters" do binds = [ActiveRecord::Relation::QueryAttribute.new("id", 10, ActiveRecord::Type::Value.new)] type_casted_binds = [10] - subscriber.sql(TestEvent.new(name: "Model Load", binds: binds, type_casted_binds: type_casted_binds)) + subscriber.sql(TestEvent.new({name: "Model Load", binds: binds, type_casted_binds: type_casted_binds})) expect(subscriber.debugs.first).to match(/\[\["id", 10\]\]/) end end From b48e1812c3329204bd065618732df5148611bd22 Mon Sep 17 00:00:00 2001 From: MATSUBARA Nobutada Date: Sat, 28 Sep 2024 14:50:42 +0900 Subject: [PATCH 6/6] CI: trilogy with Ruby 3.2 --- .github/workflows/test_ruby_3_2_trilogy.yml | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/test_ruby_3_2_trilogy.yml diff --git a/.github/workflows/test_ruby_3_2_trilogy.yml b/.github/workflows/test_ruby_3_2_trilogy.yml new file mode 100644 index 00000000..0ea066fd --- /dev/null +++ b/.github/workflows/test_ruby_3_2_trilogy.yml @@ -0,0 +1,33 @@ +name: Exec Rspec +run-name: Matrix building for ruby 3.2 ✖️ 【rails 6.1】✖️ Trilogy 🚀 +on: [push] + +jobs: + ruby_3_0: + strategy: + fail-fast: false + matrix: + arversion: ['6_0_6_trilogy', '6_1_7_trilogy'] + runs-on: ubuntu-22.04 + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails${{ matrix.arversion }}.gemfile + MYSQL_PWD: root + DATABASE_ADAPTER: trilogy + DATABASE_PASSWORD: root + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler: latest + bundler-cache: true + - name: Start mysql + run: | + sudo systemctl start mysql.service + mysql -h 127.0.0.1 --port 3306 -u root --password=root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" + - name: Reset DB + run: bundle exec rake turntable:db:reset + - name: Run RSpec + run: RUBYOPT='-W:deprecated' bundle exec rake spec