Skip to content

Commit

Permalink
Require Rails 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock authored and jrafanie committed Jul 30, 2024
1 parent 321d028 commit f60f428
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 36 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
- '2.7'
- '3.0'
- '3.1'
rails-version:
- '6.1'
- '7.0'
services:
postgres:
image: postgres:13
Expand All @@ -42,7 +39,6 @@ jobs:
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: password
TEST_RAILS_VERSION: ${{ matrix.rails-version }}
# for the mysql cli (mysql, mysqladmin)
MYSQL_HOST: 127.0.0.1
MYSQL_PWD: password
Expand All @@ -68,7 +64,7 @@ jobs:
DB: mysql2
run: bundle exec rake
- name: Report code coverage
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.1' && matrix.rails-version == '6.1' }}
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.1' }}
continue-on-error: true
uses: paambaati/codeclimate-action@v8
env:
Expand Down
10 changes: 1 addition & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

source "https://rubygems.org"

minimum_version =
case ENV['TEST_RAILS_VERSION']
when "7.0"
"~>7.0.8"
else
"~>6.1.4"
end

gem "activerecord", minimum_version
gem "activerecord", "~>7.0.8"
gem "mysql2"
gem "pg"
gem "sqlite3", "< 2"
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/virtual_attributes/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveRecord
module VirtualAttributes
VERSION = "6.1.2".freeze
VERSION = "7.0.0".freeze
end
end
20 changes: 6 additions & 14 deletions lib/active_record/virtual_attributes/virtual_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,12 @@ def assert_klass_has_instance_method(klass, instance_method)
raise NameError, msg
end

if ActiveRecord.version >= Gem::Version.new(7.0) # Rails 7.0 expected methods to patch
%w[
grouped_records
].each { |method| assert_klass_has_instance_method(ActiveRecord::Associations::Preloader::Branch, method) }
elsif ActiveRecord.version >= Gem::Version.new(6.1) # Rails 6.1 methods to patch
%w[
preloaders_for_reflection
preloaders_for_hash
preloaders_for_one
grouped_records
].each { |method| assert_klass_has_instance_method(ActiveRecord::Associations::Preloader, method) }
end
# Expect these methods to exist. (Otherwise we are patching the wrong methods)
%w[
grouped_records
preloaders_for_reflection
].each { |method| assert_klass_has_instance_method(ActiveRecord::Associations::Preloader::Branch, method) }

# Expected methods to patch on any version
%w[
build_select
arel_column
Expand Down Expand Up @@ -201,7 +193,7 @@ def preloaders_for_reflection(reflection, reflection_records)
end
end
})
end if ActiveRecord.version >= Gem::Version.new(7.0)
end
end
end

Expand Down
9 changes: 2 additions & 7 deletions spec/virtual_includes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,8 @@
end

def preloaded(records, associations, preload_scope = nil)
if ActiveRecord::Associations::Preloader.instance_methods.include?(:preload)
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(records, associations, preload_scope)
else
# Rails 7+ interface, see rails commit: e3b9779cb701c63012bc1af007c71dc5a888d35a
ActiveRecord::Associations::Preloader.new(records: records, associations: associations, scope: preload_scope).call
end
# Rails 7+ interface, see rails commit: e3b9779cb701c63012bc1af007c71dc5a888d35a
ActiveRecord::Associations::Preloader.new(:records => records, :associations => associations, :scope => preload_scope).call
records
end
end

0 comments on commit f60f428

Please sign in to comment.