diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index ba9d7b8..d7cebae 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -23,8 +23,12 @@ jobs: - "2.7" - "3.1" - "3.2" + - "3.3" + activerecord: + - "7.1" + - "7.2" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} @@ -42,7 +46,7 @@ jobs: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: - ruby-version: "3.2" + ruby-version: "3.3" # The kickstarter/actions/setup-rubygems action is not available # because this is a public repo - name: setup-rubygems @@ -53,5 +57,5 @@ jobs: :rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }} YAML chmod 0600 ~/.gem/credentials - - run: bundle install + - run: ACTIVE_RECORD_VERSION=${{ matrix.activerecord }} bundle install - run: bundle exec rake release diff --git a/Gemfile b/Gemfile index 3be9c3c..1c249f6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,16 @@ source "https://rubygems.org" gemspec + +group :development do + # This allows us to easily switch between different versions of ActiveRecord. + # To use this in local dev, you can do: + # ``` + # rm Gemfile.lock + # ACTIVE_RECORD_VERSION="7.1" bundle install + # ``` + active_record_version = ENV.fetch("ACTIVE_RECORD_VERSION", nil) + gem "activerecord", "~> #{active_record_version}.0" if active_record_version&.length&.positive? + + # Just helping out the bundler resolver: + gem "rails", "> 6.0" +end diff --git a/Taskfile.yml b/Taskfile.yml index 160cb8e..390a7d7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,7 +6,7 @@ dotenv: - .env vars: - RUBY_VERSION: 3.2.2 + RUBY_VERSION: 3.3.5 tasks: init: diff --git a/lib/replica_pools/active_record_extensions.rb b/lib/replica_pools/active_record_extensions.rb index ebd58bb..1513628 100644 --- a/lib/replica_pools/active_record_extensions.rb +++ b/lib/replica_pools/active_record_extensions.rb @@ -17,6 +17,10 @@ def connection_proxy ReplicaPools.proxy end + def with_connection_proxy + yield ReplicaPools.proxy + end + # Make sure transactions run on leader # Even if they're initiated from ActiveRecord::Base # (which doesn't have our hijack). diff --git a/lib/replica_pools/hijack.rb b/lib/replica_pools/hijack.rb index 8bfe9de..1d92f04 100644 --- a/lib/replica_pools/hijack.rb +++ b/lib/replica_pools/hijack.rb @@ -18,6 +18,7 @@ def inherited(child) def hijack_connection class << self alias_method :connection, :connection_proxy + alias_method :with_connection, :with_connection_proxy end end end diff --git a/spec/query_cache_spec.rb b/spec/query_cache_spec.rb index 51135d8..df2457d 100644 --- a/spec/query_cache_spec.rb +++ b/spec/query_cache_spec.rb @@ -22,7 +22,7 @@ @default_replica2.should_not_receive(:select_all) @leader.should_not_receive(:select_all) 3.times { @proxy.select_all(@sql) } - @leader.query_cache.keys.size.should == 1 + @leader.query_cache.size.should == 1 end end @@ -38,9 +38,9 @@ 5.times do |i| @proxy.select_all(@sql) @proxy.select_all(@sql) - @leader.query_cache.keys.size.should == 1 + @leader.query_cache.size.should == 1 @proxy.send(meths[i], '') - @leader.query_cache.keys.size.should == 0 + @leader.query_cache.size.should == 0 end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 68b8a4d..54810e3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,4 +50,7 @@ def reset_proxy(proxy) c.mock_with :rspec do |c| c.syntax = [:expect, :should] end + + c.filter_run focus: true + c.run_all_when_everything_filtered = true end