diff --git a/.github/workflows/test_ruby_2_4.yml b/.github/workflows/test_ruby_2_4.yml new file mode 100644 index 00000000..7762ccc3 --- /dev/null +++ b/.github/workflows/test_ruby_2_4.yml @@ -0,0 +1,31 @@ +name: Exec Rspec +run-name: Matrix building for ruby 2.4 โœ–๏ธ rails 5.0 ๐Ÿš€ +on: [push] + +jobs: + ruby_2_4: + strategy: + fail-fast: false + matrix: + arversion: ['5_0_0', '5_0_1', '5_0_2', '5_0_3', '5_0_4', '5_0_5', '5_0_6', '5_0_7', + '5_1_0', '5_1_1', '5_1_2', '5_1_3', '5_1_4', '5_1_5', '5_1_6', '5_1_7', + '5_2_0', '5_2_1', '5_2_2', '5_2_3', '5_2_4', '5_2_5', '5_2_6', '5_2_7', '5_2_8'] + 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@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.4' + bundler: ${{ contains(fromJSON('["5_0_0", "5_0_1", "5_0_2", "5_0_3", "5_0_4", "5_1_0", "5_1_1", "5_1_2"]'), matrix.arversion) && '1.17.3' || '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: bundle exec rake spec diff --git a/.github/workflows/test_ruby_2_5.yml b/.github/workflows/test_ruby_2_5.yml new file mode 100644 index 00000000..91584196 --- /dev/null +++ b/.github/workflows/test_ruby_2_5.yml @@ -0,0 +1,32 @@ +name: Exec Rspec +run-name: Matrix building for ruby 2.5 โœ–๏ธ ใ€rails 5.0 - 6.0ใ€‘ ๐Ÿš€ +on: [push] + +jobs: + ruby_2_5: + strategy: + fail-fast: false + matrix: + arversion: ['5_0_0', '5_0_1', '5_0_2', '5_0_3', '5_0_4', '5_0_5', '5_0_6', '5_0_7', + '5_1_0', '5_1_1', '5_1_2', '5_1_3', '5_1_4', '5_1_5', '5_1_6', '5_1_7', + '5_2_0', '5_2_1', '5_2_2', '5_2_3', '5_2_4', '5_2_5', '5_2_6', '5_2_7', '5_2_8', + '6_0_0', '6_0_1', '6_0_2', '6_0_3', '6_0_4', '6_0_5', '6_0_6'] + 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@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.5' + bundler: ${{ contains(fromJSON('["5_0_0", "5_0_1", "5_0_2", "5_0_3", "5_0_4", "5_1_0", "5_1_1", "5_1_2"]'), matrix.arversion) && '1.17.3' || '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: bundle exec rake spec diff --git a/.github/workflows/test_ruby_2_6.yml b/.github/workflows/test_ruby_2_6.yml new file mode 100644 index 00000000..a3f2c2ed --- /dev/null +++ b/.github/workflows/test_ruby_2_6.yml @@ -0,0 +1,32 @@ +name: Exec Rspec +run-name: Matrix building for ruby 2.6 โœ–๏ธ ใ€rails 5.0 - 6.0ใ€‘ ๐Ÿš€ +on: [push] + +jobs: + ruby_2_6: + strategy: + fail-fast: false + matrix: + arversion: ['5_0_0', '5_0_1', '5_0_2', '5_0_3', '5_0_4', '5_0_5', '5_0_6', '5_0_7', + '5_1_0', '5_1_1', '5_1_2', '5_1_3', '5_1_4', '5_1_5', '5_1_6', '5_1_7', + '5_2_0', '5_2_1', '5_2_2', '5_2_3', '5_2_4', '5_2_5', '5_2_6', '5_2_7', '5_2_8', + '6_0_0', '6_0_1', '6_0_2', '6_0_3', '6_0_4', '6_0_5', '6_0_6'] + 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@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.6' + bundler: ${{ contains(fromJSON('["5_0_0", "5_0_1", "5_0_2", "5_0_3", "5_0_4", "5_1_0", "5_1_1", "5_1_2"]'), matrix.arversion) && '1.17.3' || '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: bundle exec rake spec diff --git a/.github/workflows/test_ruby_2_7.yml b/.github/workflows/test_ruby_2_7.yml new file mode 100644 index 00000000..cba4367e --- /dev/null +++ b/.github/workflows/test_ruby_2_7.yml @@ -0,0 +1,32 @@ +name: Exec Rspec +run-name: Matrix building for ruby 2.7 โœ–๏ธ ใ€rails 5.0 - 6.0ใ€‘ ๐Ÿš€ +on: [push] + +jobs: + ruby_2_7: + strategy: + fail-fast: false + matrix: + arversion: ['5_0_0', '5_0_1', '5_0_2', '5_0_3', '5_0_4', '5_0_5', '5_0_6', '5_0_7', + '5_1_0', '5_1_1', '5_1_2', '5_1_3', '5_1_4', '5_1_5', '5_1_6', '5_1_7', + '5_2_0', '5_2_1', '5_2_2', '5_2_3', '5_2_4', '5_2_5', '5_2_6', '5_2_7', '5_2_8', + '6_0_0', '6_0_1', '6_0_2', '6_0_3', '6_0_4', '6_0_5', '6_0_6'] + 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@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler: ${{ contains(fromJSON('["5_0_0", "5_0_1", "5_0_2", "5_0_3", "5_0_4", "5_1_0", "5_1_1", "5_1_2"]'), matrix.arversion) && '1.17.3' || '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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c7bd4373..00000000 --- a/.travis.yml +++ /dev/null @@ -1,75 +0,0 @@ -language: ruby -sudo: false - -cache: - bundler: true - -rvm: - - 2.2.10 - - 2.3.7 - - 2.4.4 - - 2.5.1 - - ruby-head - -gemfile: - - gemfiles/rails5_0_0.gemfile - - gemfiles/rails5_0_1.gemfile - - gemfiles/rails5_0_2.gemfile - - gemfiles/rails5_0_3.gemfile - - gemfiles/rails5_0_4.gemfile - - gemfiles/rails5_0_5.gemfile - - gemfiles/rails5_0_6.gemfile - - gemfiles/rails5_0_7.gemfile - - gemfiles/rails5_1_0.gemfile - - gemfiles/rails5_1_1.gemfile - - gemfiles/rails5_1_2.gemfile - - gemfiles/rails5_1_3.gemfile - - gemfiles/rails5_1_4.gemfile - - gemfiles/rails5_1_5.gemfile - - gemfiles/rails5_1_6.gemfile - - gemfiles/rails5_2_0.gemfile - - gemfiles/rails5_2_1.gemfile - - gemfiles/rails_edge.gemfile - -env: - - SETUP_TASK=turntable:db:reset BUILD_TASK=spec - - SETUP_TASK=turntable:db:reset BUILD_TASK=spec SPEC_OPTS="--tag with_katsubushi" - - SETUP_TASK=turntable:activerecord:setup BUILD_TASK=turntable:activerecord:test - -services: - - docker - -before_install: - - docker run -d --name turntable-katsubushi -p 11212:11212 katsubushi/katsubushi:latest -worker-id 1 - -before_script: - - bundle exec rake $SETUP_TASK - -script: - - bundle exec rake $BUILD_TASK - -matrix: - exclude: - - rvm: ruby-head - - gemfile: gemfiles/rails_edge.gemfile - - rvm: 2.2.10 - - rvm: 2.3.7 - - rvm: 2.4.4 - include: - - rvm: 2.2.10 - gemfile: gemfiles/rails5_0_7.gemfile - - rvm: 2.2.10 - gemfile: gemfiles/rails5_1_6.gemfile - - rvm: 2.2.10 - gemfile: gemfiles/rails5_2_1.gemfile - - rvm: 2.3.7 - gemfile: gemfiles/rails5_2_1.gemfile - - rvm: 2.4.4 - gemfile: gemfiles/rails5_2_1.gemfile - - rvm: 2.5.1 - gemfile: gemfiles/rails_edge.gemfile - - rvm: ruby-head - gemfile: gemfiles/rails_edge.gemfile - allow_failures: - - rvm: ruby-head - - gemfile: gemfiles/rails_edge.gemfile diff --git a/Appraisals b/Appraisals new file mode 100644 index 00000000..d84c8323 --- /dev/null +++ b/Appraisals @@ -0,0 +1,62 @@ +appraise "rails6_0_0" do + gem "rails", "6.0.0" + gem "railties", "6.0.0" + gem "activerecord", "6.0.0" + gem "activesupport", "6.0.0" + gem "actionview", "6.0.0" + gem "mysql2", "~> 0.5.2" +end + +appraise "rails6_0_1" do + gem "rails", "6.0.1" + gem "railties", "6.0.1" + gem "activerecord", "6.0.1" + gem "activesupport", "6.0.1" + gem "actionview", "6.0.1" + gem "mysql2", "~> 0.5.2" +end + +appraise "rails6_0_2" do + gem "rails", "6.0.2" + gem "railties", "6.0.2" + gem "activerecord", "6.0.2" + gem "activesupport", "6.0.2" + gem "actionview", "6.0.2" + gem "mysql2", "~> 0.5.2" +end + +appraise "rails6_0_3" do + gem "rails", "6.0.3" + gem "railties", "6.0.3" + gem "activerecord", "6.0.3" + gem "activesupport", "6.0.3" + gem "actionview", "6.0.3" + gem "mysql2", "~> 0.5.2" +end + +appraise "rails6_0_4" do + gem "rails", "6.0.4" + gem "railties", "6.0.4" + gem "activerecord", "6.0.4" + gem "activesupport", "6.0.4" + gem "actionview", "6.0.4" + gem "mysql2", "~> 0.5.2" +end + +appraise "rails6_0_5" do + gem "rails", "6.0.5" + gem "railties", "6.0.5" + gem "activerecord", "6.0.5" + gem "activesupport", "6.0.5" + gem "actionview", "6.0.5" + gem "mysql2", "~> 0.5.2" +end + +appraise "rails6_0_6" do + gem "rails", "6.0.6" + gem "railties", "6.0.6" + gem "activerecord", "6.0.6" + gem "activesupport", "6.0.6" + gem "actionview", "6.0.6" + gem "mysql2", "~> 0.5.2" +end diff --git a/Gemfile b/Gemfile index edf1a3cc..3f655e3e 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" gemspec -gem "rails", "5.2.1" +gem "rails", "6.0.6.1" -gem "actionview", "5.2.1" -gem "activerecord", "5.2.1" -gem "activesupport", "5.2.1" +gem "actionview", "6.0.6.1" +gem "activerecord", "6.0.6.1" +gem "activesupport", "6.0.6.1" diff --git a/README.md b/README.md index 62cb7932..2bfae1d4 100644 --- a/README.md +++ b/README.md @@ -700,6 +700,21 @@ raise_on_not_specified_shard_query true raise_on_not_specified_shard_update true ``` +## Run tests locally + +```sh +docker compose up -d +# rbenv shell 2.7.8 +bundle install +bundle exec appraisal install +export TEST_MYSQL_HOST=127.0.0.1 +export TEST_MYSQL_PORT=13306 +bundle exec appraisal rails6_0_6 rake spec +``` + +> [!note] +> Appraisal does not work on Ruby 2.2 or lower. + ## Thanks ConnectionProxy, Distributed Migration implementation is inspired by Octopus and DataFabric. diff --git a/activerecord-turntable.gemspec b/activerecord-turntable.gemspec index def8b879..48033cd8 100644 --- a/activerecord-turntable.gemspec +++ b/activerecord-turntable.gemspec @@ -23,8 +23,8 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.2.2" - spec.add_runtime_dependency "activerecord", ">= 5.0", "< 6.0" - spec.add_runtime_dependency "activesupport", ">= 5.0", "< 6.0" + spec.add_runtime_dependency "activerecord", ">= 5.0", "< 7.0" + spec.add_runtime_dependency "activesupport", ">= 5.0", "< 7.0" spec.add_runtime_dependency "bsearch", "~> 1.5" spec.add_runtime_dependency "sql_tree", "= 0.2.0" @@ -33,7 +33,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "barrage" spec.add_development_dependency "coveralls" spec.add_development_dependency "dalli", ">= 2.7" - spec.add_development_dependency "factory_bot" + spec.add_development_dependency "factory_bot", "<= 6.4.4" spec.add_development_dependency "faker" spec.add_development_dependency "guard-rspec" spec.add_development_dependency "guard-rubocop" @@ -61,4 +61,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "minitest" spec.add_development_dependency "mocha" spec.add_development_dependency "sqlite3", "~> 1.3.6" + spec.add_development_dependency "appraisal", "~> 2.5.0" end diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..5ed15409 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,7 @@ +services: + mysql: + image: "mysql:8.0" + ports: + - "13306:3306" + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: "yes" diff --git a/gemfiles/rails5_0_0.gemfile b/gemfiles/rails5_0_0.gemfile index e64eb756..0012fa6f 100644 --- a/gemfiles/rails5_0_0.gemfile +++ b/gemfiles/rails5_0_0.gemfile @@ -1,10 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.0" +gem "railties", "5.0.0" gem "activerecord", "5.0.0" gem "activesupport", "5.0.0" - +gem "actionview", "5.0.0" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_1.gemfile b/gemfiles/rails5_0_1.gemfile index 780a7948..c0f5d7af 100644 --- a/gemfiles/rails5_0_1.gemfile +++ b/gemfiles/rails5_0_1.gemfile @@ -1,11 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.1" +gem "railties", "5.0.1" gem "activerecord", "5.0.1" gem "activesupport", "5.0.1" - +gem "actionview", "5.0.1" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_2.gemfile b/gemfiles/rails5_0_2.gemfile index 7d023ac7..e9a24164 100644 --- a/gemfiles/rails5_0_2.gemfile +++ b/gemfiles/rails5_0_2.gemfile @@ -1,11 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.2" +gem "railties", "5.0.2" gem "activerecord", "5.0.2" gem "activesupport", "5.0.2" - +gem "actionview", "5.0.2" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_3.gemfile b/gemfiles/rails5_0_3.gemfile index c0173596..bef73186 100644 --- a/gemfiles/rails5_0_3.gemfile +++ b/gemfiles/rails5_0_3.gemfile @@ -1,11 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.3" +gem "railties", "5.0.3" gem "activerecord", "5.0.3" gem "activesupport", "5.0.3" - +gem "actionview", "5.0.3" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_4.gemfile b/gemfiles/rails5_0_4.gemfile index 6d5cd9a0..2fb96bb0 100644 --- a/gemfiles/rails5_0_4.gemfile +++ b/gemfiles/rails5_0_4.gemfile @@ -1,11 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.4" +gem "railties", "5.0.4" gem "activerecord", "5.0.4" gem "activesupport", "5.0.4" - +gem "actionview", "5.0.4" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_5.gemfile b/gemfiles/rails5_0_5.gemfile index 6b4012eb..4d6b87c7 100644 --- a/gemfiles/rails5_0_5.gemfile +++ b/gemfiles/rails5_0_5.gemfile @@ -1,11 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.5" +gem "railties", "5.0.5" gem "activerecord", "5.0.5" gem "activesupport", "5.0.5" - +gem "actionview", "5.0.5" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_6.gemfile b/gemfiles/rails5_0_6.gemfile index f74abf35..afc171c5 100644 --- a/gemfiles/rails5_0_6.gemfile +++ b/gemfiles/rails5_0_6.gemfile @@ -1,11 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.6" +gem "railties", "5.0.6" gem "activerecord", "5.0.6" gem "activesupport", "5.0.6" - +gem "actionview", "5.0.6" gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_0_7.gemfile b/gemfiles/rails5_0_7.gemfile index f21b39c2..dfa736f2 100644 --- a/gemfiles/rails5_0_7.gemfile +++ b/gemfiles/rails5_0_7.gemfile @@ -1,9 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.0.7" +gem "railties", "5.0.7" gem "activerecord", "5.0.7" gem "activesupport", "5.0.7" +gem "actionview", "5.0.7" +gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_0.gemfile b/gemfiles/rails5_1_0.gemfile index c03f6437..cc6502f1 100644 --- a/gemfiles/rails5_1_0.gemfile +++ b/gemfiles/rails5_1_0.gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.0" +gem "railties", "5.1.0" gem "activerecord", "5.1.0" gem "activesupport", "5.1.0" gem "actionview", "5.1.0" - gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_1.gemfile b/gemfiles/rails5_1_1.gemfile index 1f7b9bdd..66f5e3fa 100644 --- a/gemfiles/rails5_1_1.gemfile +++ b/gemfiles/rails5_1_1.gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.1" +gem "railties", "5.1.1" gem "activerecord", "5.1.1" gem "activesupport", "5.1.1" gem "actionview", "5.1.1" - gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_2.gemfile b/gemfiles/rails5_1_2.gemfile index 9528fb51..4b0db053 100644 --- a/gemfiles/rails5_1_2.gemfile +++ b/gemfiles/rails5_1_2.gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.2" +gem "railties", "5.1.2" gem "activerecord", "5.1.2" gem "activesupport", "5.1.2" gem "actionview", "5.1.2" - gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_3.gemfile b/gemfiles/rails5_1_3.gemfile index 0fc52132..31e56c31 100644 --- a/gemfiles/rails5_1_3.gemfile +++ b/gemfiles/rails5_1_3.gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.3" +gem "railties", "5.1.3" gem "activerecord", "5.1.3" gem "activesupport", "5.1.3" gem "actionview", "5.1.3" - gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_4.gemfile b/gemfiles/rails5_1_4.gemfile index fc8ad279..f2e0e12a 100644 --- a/gemfiles/rails5_1_4.gemfile +++ b/gemfiles/rails5_1_4.gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.4" +gem "railties", "5.1.4" gem "activerecord", "5.1.4" gem "activesupport", "5.1.4" gem "actionview", "5.1.4" - gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_5.gemfile b/gemfiles/rails5_1_5.gemfile index 21e5ece1..00b9894b 100644 --- a/gemfiles/rails5_1_5.gemfile +++ b/gemfiles/rails5_1_5.gemfile @@ -1,12 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.5" +gem "railties", "5.1.5" gem "activerecord", "5.1.5" gem "activesupport", "5.1.5" gem "actionview", "5.1.5" - gem "mysql2", "~> 0.4.4" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_6.gemfile b/gemfiles/rails5_1_6.gemfile index 3b95d5f3..75291519 100644 --- a/gemfiles/rails5_1_6.gemfile +++ b/gemfiles/rails5_1_6.gemfile @@ -1,10 +1,14 @@ source "https://rubygems.org" +gem "rails", "5.1.6" +gem "railties", "5.1.6" gem "activerecord", "5.1.6" gem "activesupport", "5.1.6" gem "actionview", "5.1.6" +gem "mysql2", "~> 0.5.2" -gem "minitest", "< 5.3.4" -gem "mocha", "~> 0.14", require: false +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 gemspec :path => '../' diff --git a/gemfiles/rails5_1_7.gemfile b/gemfiles/rails5_1_7.gemfile new file mode 100644 index 00000000..dd03b9b3 --- /dev/null +++ b/gemfiles/rails5_1_7.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.1.7" +gem "railties", "5.1.7" +gem "activerecord", "5.1.7" +gem "activesupport", "5.1.7" +gem "actionview", "5.1.7" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' \ No newline at end of file diff --git a/gemfiles/rails5_2_0.gemfile b/gemfiles/rails5_2_0.gemfile index e786d362..dbb7b8df 100644 --- a/gemfiles/rails5_2_0.gemfile +++ b/gemfiles/rails5_2_0.gemfile @@ -7,4 +7,8 @@ gem "activesupport", "5.2.0" gem "actionview", "5.2.0" gem "mysql2", "~> 0.5.2" +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + gemspec :path => '../' diff --git a/gemfiles/rails5_2_1.gemfile b/gemfiles/rails5_2_1.gemfile index aa08879c..9d4b5e02 100644 --- a/gemfiles/rails5_2_1.gemfile +++ b/gemfiles/rails5_2_1.gemfile @@ -7,4 +7,8 @@ gem "activesupport", "5.2.1" gem "actionview", "5.2.1" gem "mysql2", "~> 0.5.2" +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + gemspec :path => '../' diff --git a/gemfiles/rails5_2_2.gemfile b/gemfiles/rails5_2_2.gemfile new file mode 100644 index 00000000..c0a0d571 --- /dev/null +++ b/gemfiles/rails5_2_2.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.2" +gem "railties", "5.2.2" +gem "activerecord", "5.2.2" +gem "activesupport", "5.2.2" +gem "actionview", "5.2.2" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails5_2_3.gemfile b/gemfiles/rails5_2_3.gemfile new file mode 100644 index 00000000..75420fc5 --- /dev/null +++ b/gemfiles/rails5_2_3.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.3" +gem "railties", "5.2.3" +gem "activerecord", "5.2.3" +gem "activesupport", "5.2.3" +gem "actionview", "5.2.3" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails5_2_4.gemfile b/gemfiles/rails5_2_4.gemfile new file mode 100644 index 00000000..2b4f00a2 --- /dev/null +++ b/gemfiles/rails5_2_4.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.4" +gem "railties", "5.2.4" +gem "activerecord", "5.2.4" +gem "activesupport", "5.2.4" +gem "actionview", "5.2.4" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails5_2_5.gemfile b/gemfiles/rails5_2_5.gemfile new file mode 100644 index 00000000..5ef148e9 --- /dev/null +++ b/gemfiles/rails5_2_5.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.5" +gem "railties", "5.2.5" +gem "activerecord", "5.2.5" +gem "activesupport", "5.2.5" +gem "actionview", "5.2.5" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails5_2_6.gemfile b/gemfiles/rails5_2_6.gemfile new file mode 100644 index 00000000..8bb748ef --- /dev/null +++ b/gemfiles/rails5_2_6.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.6" +gem "railties", "5.2.6" +gem "activerecord", "5.2.6" +gem "activesupport", "5.2.6" +gem "actionview", "5.2.6" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails5_2_7.gemfile b/gemfiles/rails5_2_7.gemfile new file mode 100644 index 00000000..cc489b87 --- /dev/null +++ b/gemfiles/rails5_2_7.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.7" +gem "railties", "5.2.7" +gem "activerecord", "5.2.7" +gem "activesupport", "5.2.7" +gem "actionview", "5.2.7" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails5_2_8.gemfile b/gemfiles/rails5_2_8.gemfile new file mode 100644 index 00000000..4c6bda53 --- /dev/null +++ b/gemfiles/rails5_2_8.gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gem "rails", "5.2.8" +gem "railties", "5.2.8" +gem "activerecord", "5.2.8" +gem "activesupport", "5.2.8" +gem "actionview", "5.2.8" +gem "mysql2", "~> 0.5.2" + +gem "nokogiri", "~> 1.10" if RUBY_VERSION.to_f < 2.5 +gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 +gem "dalli", "~> 2.7" if RUBY_VERSION.to_f < 2.5 + +gemspec :path => '../' diff --git a/gemfiles/rails6_0_0.gemfile b/gemfiles/rails6_0_0.gemfile new file mode 100644 index 00000000..74ed8045 --- /dev/null +++ b/gemfiles/rails6_0_0.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.0" +gem "actionview", "6.0.0" +gem "activerecord", "6.0.0" +gem "activesupport", "6.0.0" +gem "railties", "6.0.0" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/gemfiles/rails6_0_1.gemfile b/gemfiles/rails6_0_1.gemfile new file mode 100644 index 00000000..2b3072fe --- /dev/null +++ b/gemfiles/rails6_0_1.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.1" +gem "actionview", "6.0.1" +gem "activerecord", "6.0.1" +gem "activesupport", "6.0.1" +gem "railties", "6.0.1" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/gemfiles/rails6_0_2.gemfile b/gemfiles/rails6_0_2.gemfile new file mode 100644 index 00000000..03f35902 --- /dev/null +++ b/gemfiles/rails6_0_2.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.2" +gem "actionview", "6.0.2" +gem "activerecord", "6.0.2" +gem "activesupport", "6.0.2" +gem "railties", "6.0.2" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/gemfiles/rails6_0_3.gemfile b/gemfiles/rails6_0_3.gemfile new file mode 100644 index 00000000..6d8e067f --- /dev/null +++ b/gemfiles/rails6_0_3.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.3" +gem "actionview", "6.0.3" +gem "activerecord", "6.0.3" +gem "activesupport", "6.0.3" +gem "railties", "6.0.3" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/gemfiles/rails6_0_4.gemfile b/gemfiles/rails6_0_4.gemfile new file mode 100644 index 00000000..56ef7a90 --- /dev/null +++ b/gemfiles/rails6_0_4.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.4" +gem "actionview", "6.0.4" +gem "activerecord", "6.0.4" +gem "activesupport", "6.0.4" +gem "railties", "6.0.4" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/gemfiles/rails6_0_5.gemfile b/gemfiles/rails6_0_5.gemfile new file mode 100644 index 00000000..c4d78a17 --- /dev/null +++ b/gemfiles/rails6_0_5.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.5" +gem "actionview", "6.0.5" +gem "activerecord", "6.0.5" +gem "activesupport", "6.0.5" +gem "railties", "6.0.5" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/gemfiles/rails6_0_6.gemfile b/gemfiles/rails6_0_6.gemfile new file mode 100644 index 00000000..f4ae1f04 --- /dev/null +++ b/gemfiles/rails6_0_6.gemfile @@ -0,0 +1,12 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.6" +gem "actionview", "6.0.6" +gem "activerecord", "6.0.6" +gem "activesupport", "6.0.6" +gem "railties", "6.0.6" +gem "mysql2", "~> 0.5.2" + +gemspec path: "../" diff --git a/lib/active_record/turntable/active_record_ext/abstract_adapter.rb b/lib/active_record/turntable/active_record_ext/abstract_adapter.rb index c5de0e13..5e6380ec 100644 --- a/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +++ b/lib/active_record/turntable/active_record_ext/abstract_adapter.rb @@ -8,14 +8,19 @@ def self.prepended(klass) klass.class_eval { protected :log } end - def translate_exception_class(e, sql) + def translate_exception_class(e, sql, binds) begin message = "#{e.class.name}: #{e.message}: #{sql} : #{turntable_shard_name}" rescue Encoding::CompatibilityError message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql} : #{turntable_shard_name}" end - exception = translate_exception(e, message) + exception = + if Util.ar60_or_later? + translate_exception(e, message: message, sql: sql, binds: binds) + else + translate_exception(e, message) + end exception.set_backtrace e.backtrace exception end @@ -23,6 +28,28 @@ def translate_exception_class(e, sql) # @note override for append current shard name # rubocop:disable Style/HashSyntax, Style/MultilineMethodCallBraceLayout + module V6_0 + def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) + @instrumenter.instrument( + "sql.active_record", + sql: sql, + name: name, + binds: binds, + type_casted_binds: type_casted_binds, + statement_name: statement_name, + connection: self, + turntable_shard_name: turntable_shard_name) do + begin + @lock.synchronize do + yield + end + rescue => e + raise translate_exception_class(e, sql, binds) + end + end + end + end + module V5_2 def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) @instrumenter.instrument( @@ -39,7 +66,7 @@ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = yield end rescue => e - raise translate_exception_class(e, sql) + raise translate_exception_class(e, sql, binds) end end end @@ -61,7 +88,7 @@ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = end end rescue => e - raise translate_exception_class(e, sql) + raise translate_exception_class(e, sql, binds) end end @@ -77,7 +104,7 @@ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = connection_id: object_id, turntable_shard_name: turntable_shard_name) { yield } rescue => e - raise translate_exception_class(e, sql) + raise translate_exception_class(e, sql, binds) end end @@ -92,7 +119,7 @@ def log(sql, name = "SQL", binds = [], statement_name = nil) :binds => binds, :turntable_shard_name => turntable_shard_name) { yield } rescue => e - raise translate_exception_class(e, sql) + raise translate_exception_class(e, sql, binds) end end # rubocop:enable Style/HashSyntax, Style/MultilineMethodCallBraceLayout diff --git a/lib/active_record/turntable/active_record_ext/fixtures.rb b/lib/active_record/turntable/active_record_ext/fixtures.rb index 608d84e1..18986fa7 100644 --- a/lib/active_record/turntable/active_record_ext/fixtures.rb +++ b/lib/active_record/turntable/active_record_ext/fixtures.rb @@ -86,6 +86,13 @@ def setup_fixtures(config = ActiveRecord::Base) # Load fixtures once and begin transaction. if run_in_transaction? + + # # Support AciveRecrd version 6.0.4 + # # https://github.com/rails/rails/blame/v6.0.4/activerecord/lib/active_record/test_fixtures.rb#L115 + if ActiveRecord::Turntable::Util.ar_version_equals_or_later?("6.0.4") + @saved_pool_configs = Hash.new { |hash, key| hash[key] = {} } + end + if @@already_loaded_fixtures[self.class] @loaded_fixtures = @@already_loaded_fixtures[self.class] else diff --git a/lib/active_record/turntable/active_record_ext/log_subscriber.rb b/lib/active_record/turntable/active_record_ext/log_subscriber.rb index a32637aa..45822dba 100644 --- a/lib/active_record/turntable/active_record_ext/log_subscriber.rb +++ b/lib/active_record/turntable/active_record_ext/log_subscriber.rb @@ -34,7 +34,7 @@ def sql(event) end name = colorize_payload_name(name, payload[:name]) - sql = color(sql, sql_color(sql), true) + sql = color(sql, sql_color(sql), true) if Util.ar60_or_later? && colorize_logging debug " #{name} #{sql}#{binds}" end diff --git a/lib/active_record/turntable/active_record_ext/persistence.rb b/lib/active_record/turntable/active_record_ext/persistence.rb index 03813cfd..affece3a 100644 --- a/lib/active_record/turntable/active_record_ext/persistence.rb +++ b/lib/active_record/turntable/active_record_ext/persistence.rb @@ -87,8 +87,13 @@ def update_columns(attributes) raise ActiveRecord::ActiveRecordError, "cannot update a new record" if new_record? raise ActiveRecord::ActiveRecordError, "cannot update a destroyed record" if destroyed? + attributes = attributes.transform_keys do |key| + name = key.to_s + self.class.attribute_aliases[name] || name + end + attributes.each_key do |key| - verify_readonly_attribute(key.to_s) + verify_readonly_attribute(key) end constraints = { self.class.primary_key => id_in_database } diff --git a/lib/active_record/turntable/active_record_ext/query_cache.rb b/lib/active_record/turntable/active_record_ext/query_cache.rb index 8bcecf25..01dd3aa3 100644 --- a/lib/active_record/turntable/active_record_ext/query_cache.rb +++ b/lib/active_record/turntable/active_record_ext/query_cache.rb @@ -10,6 +10,9 @@ class << klass module ClassMethods extend Compatibility + module V6_0 + end + module V5_2 end diff --git a/lib/active_record/turntable/active_record_ext/schema_dumper.rb b/lib/active_record/turntable/active_record_ext/schema_dumper.rb index 531598b9..974fc529 100644 --- a/lib/active_record/turntable/active_record_ext/schema_dumper.rb +++ b/lib/active_record/turntable/active_record_ext/schema_dumper.rb @@ -13,6 +13,10 @@ def table(table, stream) end begin + if Util.ar60_or_later? + self.table_name = table + end + tbl = StringIO.new tbl.print " create_sequence_for #{remove_prefix_and_suffix(matchdata[1]).inspect}" @@ -38,6 +42,10 @@ def table(table, stream) stream.puts "# Could not dump table #{table.inspect} because of following #{e.class}" stream.puts "# #{e.message}" stream.puts + ensure + if Util.ar60_or_later? + self.table_name = nil + end end stream diff --git a/lib/active_record/turntable/active_record_ext/transactions.rb b/lib/active_record/turntable/active_record_ext/transactions.rb index d4d049e9..3ca64cda 100644 --- a/lib/active_record/turntable/active_record_ext/transactions.rb +++ b/lib/active_record/turntable/active_record_ext/transactions.rb @@ -12,7 +12,18 @@ def with_transaction_returning_status self.id = klass.next_sequence_value end self.class.connection.shards_transaction([self.turntable_shard]) do - add_to_transaction + if Util.ar60_or_later? + if has_transactional_callbacks? + add_to_transaction + else + sync_with_transaction_state if @transaction_state&.finalized? + @transaction_state = self.turntable_shard.connection.transaction_state + end + remember_transaction_record_state + else + add_to_transaction + end + begin status = yield rescue ActiveRecord::Rollback @@ -24,7 +35,7 @@ def with_transaction_returning_status end status ensure - if @transaction_state && @transaction_state.committed? + if !Util.ar60_or_later? && @transaction_state && @transaction_state.committed? clear_transaction_record_state end end @@ -32,13 +43,17 @@ def with_transaction_returning_status def add_to_transaction return super unless self.class.turntable_enabled? - if has_transactional_callbacks? + if Util.ar60_or_later? self.turntable_shard.connection.add_transaction_record(self) else - sync_with_transaction_state - set_transaction_state(self.turntable_shard.connection.transaction_state) + if has_transactional_callbacks? + self.turntable_shard.connection.add_transaction_record(self) + else + sync_with_transaction_state + set_transaction_state(self.turntable_shard.connection.transaction_state) + end + remember_transaction_record_state end - remember_transaction_record_state end end end diff --git a/lib/active_record/turntable/util.rb b/lib/active_record/turntable/util.rb index f417f7ae..3137b6e8 100644 --- a/lib/active_record/turntable/util.rb +++ b/lib/active_record/turntable/util.rb @@ -35,6 +35,10 @@ def ar52_or_later? ar_version_equals_or_later?("5.2") end + def ar60_or_later? + ar_version_equals_or_later?("6.0") + end + module_function :ar_version_equals_or_later?, :ar_version_earlier_than?, :ar_version, @@ -42,6 +46,7 @@ def ar52_or_later? :ar51?, :earlier_than_ar51?, :ar51_or_later?, - :ar52_or_later? + :ar52_or_later?, + :ar60_or_later? end end diff --git a/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb b/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb index 9ae30875..793de993 100644 --- a/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb +++ b/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb @@ -11,7 +11,11 @@ let(:user_profile) { user.user_profile } describe "optimistic locking" do - subject { user_profile.update_attributes(birthday: Date.current) } + if ActiveRecord::Turntable::Util.ar60_or_later? + subject { user_profile.update(birthday: Date.current) } + else + subject { user_profile.update_attributes(birthday: Date.current) } + end it { expect { subject }.to change(user_profile, :lock_version).by(1) } end diff --git a/spec/active_record/turntable/active_record_ext/persistence_spec.rb b/spec/active_record/turntable/active_record_ext/persistence_spec.rb index f8a2fb3f..280fef9c 100644 --- a/spec/active_record/turntable/active_record_ext/persistence_spec.rb +++ b/spec/active_record/turntable/active_record_ext/persistence_spec.rb @@ -23,7 +23,13 @@ let(:user) { create(:user, :created_yesterday) } context "When updating" do - subject { user.update_attributes!(nickname: new_nickname) } + subject { + if ActiveRecord::Turntable::Util.ar60_or_later? + user.update!(nickname: new_nickname) + else + user.update_attributes!(nickname: new_nickname) + end + } let(:new_nickname) { Faker::Name.unique.name } @@ -73,7 +79,13 @@ let!(:user_item) { user.user_items.first } context "When updating" do - subject { user_item.update_attributes!(num: 2) } + subject { + if ActiveRecord::Turntable::Util.ar60_or_later? + user_item.update!(num: 2) + else + user_item.update_attributes!(num: 2) + end + } it { expect { subject }.not_to raise_error } @@ -123,9 +135,16 @@ context "When the model is not sharded" do let(:item) { create(:item) } + let(:item_update_name) { + if ActiveRecord::Turntable::Util.ar60_or_later? + item.update(name: "hoge") + else + item.update_attributes(name: "hoge") + end + } - it { expect { item.update_attributes(name: "hoge") }.not_to raise_error } - it { expect { item.update_attributes(name: "hoge") }.to query_like(/WHERE `items`\.`id` = #{item.id}[^\s]*$/) } + it { expect { item_update_name }.not_to raise_error } + it { expect { item_update_name }.to query_like(/WHERE `items`\.`id` = #{item.id}[^\s]*$/) } it { expect { item.destroy! }.not_to raise_error } it { expect { item.destroy! }.to query_like(/WHERE `items`\.`id` = #{item.id}[^\s]*$/) } diff --git a/spec/active_record/turntable/active_record_ext/query_cache_spec.rb b/spec/active_record/turntable/active_record_ext/query_cache_spec.rb index 370d907c..399ef704 100644 --- a/spec/active_record/turntable/active_record_ext/query_cache_spec.rb +++ b/spec/active_record/turntable/active_record_ext/query_cache_spec.rb @@ -5,7 +5,21 @@ def middleware(&app) executor = Class.new(ActiveSupport::Executor) ActiveRecord::QueryCache.install_executor_hooks executor - lambda { |env| executor.wrap { app.call(env) } } + lambda do |env| + begin + if ActiveRecord::Turntable::Util.ar60_or_later? + original_handlers = ActiveRecord::Base.connection_handlers + ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler, reading: ActiveRecord::ConnectionAdapters::ConnectionHandler.new } + end + executor.wrap do + app.call(env) + end + ensure + if ActiveRecord::Turntable::Util.ar60_or_later? + ActiveRecord::Base.connection_handlers = original_handlers + end + end + end end def disable_query_cache diff --git a/spec/active_record/turntable/connection_proxy_spec.rb b/spec/active_record/turntable/connection_proxy_spec.rb index 5d6f6639..ef626673 100644 --- a/spec/active_record/turntable/connection_proxy_spec.rb +++ b/spec/active_record/turntable/connection_proxy_spec.rb @@ -68,7 +68,11 @@ end context "When updating user in shard1" do - subject { @user_in_shard1.update_attributes!(nickname: new_nickname) } + if ActiveRecord::Turntable::Util.ar60_or_later? + subject { @user_in_shard1.update!(nickname: new_nickname) } + else + subject { @user_in_shard1.update_attributes!(nickname: new_nickname) } + end let(:new_nickname) { Faker::Name.unique.name } @@ -76,7 +80,11 @@ end context "When updating user in shard2" do - subject { @user_in_shard2.update_attributes!(nickname: new_nickname) } + if ActiveRecord::Turntable::Util.ar60_or_later? + subject { @user_in_shard2.update!(nickname: new_nickname) } + else + subject { @user_in_shard2.update_attributes!(nickname: new_nickname) } + end let(:new_nickname) { Faker::Name.unique.name } diff --git a/spec/config/database.yml b/spec/config/database.yml index 142768a6..fb7254a0 100644 --- a/spec/config/database.yml +++ b/spec/config/database.yml @@ -2,8 +2,8 @@ default: &default adapter: mysql2 username: root password: - host: localhost - port: 3306 + host: <%= ENV['TEST_MYSQL_HOST'] || 'localhost' %> + port: <%= ENV['TEST_MYSQL_PORT'] || 3306 %> encoding: utf8 database: turntable_test diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 618f2f9d..05d10e5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,7 +35,9 @@ # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. -ActiveRecord::Base.configurations = YAML.load_file(File.join(File.dirname(__FILE__), "config/database.yml")) +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.establish_connection(:test) Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }