Skip to content

Commit

Permalink
Merge pull request #53 from kickstarter/activerecord-7.2
Browse files Browse the repository at this point in the history
Support `ActiveRecord` 7.2
  • Loading branch information
a-lavis authored Oct 15, 2024
2 parents 9673ab9 + 82a9d45 commit aa619e7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
14 changes: 14 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dotenv:
- .env

vars:
RUBY_VERSION: 3.2.2
RUBY_VERSION: 3.3.5

tasks:
init:
Expand Down
4 changes: 4 additions & 0 deletions lib/replica_pools/active_record_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions lib/replica_pools/hijack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/query_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aa619e7

Please sign in to comment.