Skip to content

Commit

Permalink
Update the tests matrix (#849)
Browse files Browse the repository at this point in the history
* Update gitignore

* This is the commit message #3:

Do not run rails >= 7 on ruby < 3

* Remove jruby and truffleruby

* Fix rubocop

* Use rspec instead of rake
  • Loading branch information
coorasse authored May 23, 2024
1 parent 54a605c commit d4ef85a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 101 deletions.
47 changes: 22 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,38 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['2.6', '2.7', '3.0', 'jruby', 'truffleruby']
gemfile: ['gemfiles/activerecord_5.0.2.gemfile', 'gemfiles/activerecord_5.1.0.gemfile', 'gemfiles/activerecord_5.2.2.gemfile', 'gemfiles/activerecord_6.0.0.gemfile', 'gemfiles/activerecord_6.1.0.gemfile', 'gemfiles/activerecord_main.gemfile']
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
gemfile: ['gemfiles/activerecord_5.2.2.gemfile', 'gemfiles/activerecord_6.0.0.gemfile', 'gemfiles/activerecord_6.1.0.gemfile', 'gemfiles/activerecord_7.0.0.gemfile', 'gemfiles/activerecord_7.1.0.gemfile', 'gemfiles/activerecord_main.gemfile']
include:
- gemfile: 'gemfiles/activerecord_7.1.0.gemfile'
ruby: '3.3'
- gemfile: 'gemfiles/activerecord_7.1.0.gemfile'
ruby: '3.0'
- gemfile: 'gemfiles/activerecord_7.0.0.gemfile'
ruby: '3.1'
ruby: '3.3'
- gemfile: 'gemfiles/activerecord_7.0.0.gemfile'
ruby: '3.0'
- gemfile: 'gemfiles/activerecord_6.1.0.gemfile'
ruby: '3.1'
ruby: '3.3'
- gemfile: 'gemfiles/activerecord_6.1.0.gemfile'
ruby: '3.0'
exclude:
- gemfile: 'gemfiles/activerecord_5.2.2.gemfile'
ruby: '3.0' # rails 5.2 can't run on ruby 3.0
- gemfile: 'gemfiles/activerecord_5.1.0.gemfile'
ruby: '3.0' # rails 5.1 can't run on ruby 3.0
- gemfile: 'gemfiles/activerecord_5.0.2.gemfile'
ruby: '3.0' # rails 5.0 can't run on ruby 3.0
- gemfile: 'gemfiles/activerecord_5.0.2.gemfile'
ruby: '3.0' # rails 5.0 can't run on ruby 3.0
- gemfile: 'gemfiles/activerecord_5.0.2.gemfile'
ruby: 'truffleruby' # TruffleRuby 21.0 targets Ruby 2.7, same as above
- gemfile: 'gemfiles/activerecord_5.1.0.gemfile'
ruby: 'truffleruby' # TruffleRuby 21.0 targets Ruby 2.7, same as above
ruby: '3.0'
- gemfile: 'gemfiles/activerecord_5.2.2.gemfile'
ruby: '3.1'
- gemfile: 'gemfiles/activerecord_5.2.2.gemfile'
ruby: 'truffleruby' # TruffleRuby 21.0 targets Ruby 2.7, same as above
ruby: '3.2'
- gemfile: 'gemfiles/activerecord_5.2.2.gemfile'
ruby: '3.3'
- gemfile: 'gemfiles/activerecord_7.0.0.gemfile'
ruby: '2.7'
- gemfile: 'gemfiles/activerecord_7.1.0.gemfile'
ruby: '2.7'
- gemfile: 'gemfiles/activerecord_main.gemfile'
ruby: '2.6' # rails 7+ requires ruby 3.0+
- gemfile: 'gemfiles/activerecord_5.0.2.gemfile'
ruby: 'jruby' # this *should* work - there's a test failure; it's not incompatible like the other excludes. could be an issue in Rails 5.0.2?
- gemfile: 'gemfiles/activerecord_6.1.0.gemfile'
ruby: 'jruby' # this *should* work. it seems like there's an issue with rails 6 on jruby.
ruby: '2.7'
- gemfile: 'gemfiles/activerecord_main.gemfile'
ruby: 'jruby' # this *should* work. it seems like there's an issue with rails 6 on jruby.

ruby: '3.0'
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}

Expand Down Expand Up @@ -84,10 +81,10 @@ jobs:
bundler-cache: true

- name: Run tests on sqlite
run: DB=sqlite bundle exec rake
run: DB=sqlite bundle exec rspec

- name: Run tests on postgres
run: DB=postgres bundle exec rake
run: DB=postgres bundle exec rspec

lint:
name: Lint
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ AllCops:
- 'gemfiles/**/*'
- 'vendor/**/*'
- 'Appraisals'
- 'node_modules/**/*'
3 changes: 3 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,6 @@ Style/StringChars:
Style/StringConcatenation:
Exclude:
- 'lib/cancan/rule.rb'

Lint/SafeNavigationChain:
Enabled: false
63 changes: 23 additions & 40 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
appraise 'activerecord_5.0.2' do
gem 'activerecord', '~> 5.0.2', require: 'active_record'
gem 'activesupport', '~> 5.0.2', require: 'active_support/all'
gem 'actionpack', '~> 5.0.2', require: 'action_pack'

gemfile.platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jdbc-sqlite3'
gem 'jdbc-postgres'
end

gemfile.platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.3.0'
end
end

appraise 'activerecord_5.1.0' do
gem 'activerecord', '~> 5.1.0', require: 'active_record'
gem 'activesupport', '~> 5.1.0', require: 'active_support/all'
gem 'actionpack', '~> 5.1.0', require: 'action_pack'

gemfile.platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jdbc-sqlite3'
gem 'jdbc-postgres'
end

gemfile.platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.4.2'
end
end

appraise 'activerecord_5.2.2' do
gem 'activerecord', '~> 5.2.2', require: 'active_record'
gem 'activesupport', '~> 5.2.2', require: 'active_support/all'
Expand All @@ -45,7 +11,7 @@ appraise 'activerecord_5.2.2' do

gemfile.platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.4.2'
gem 'sqlite3', '~> 1.7.3'
end
end

Expand All @@ -62,7 +28,7 @@ appraise 'activerecord_6.0.0' do

platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.4.2'
gem 'sqlite3', '~> 1.7.3'
end
end

Expand All @@ -79,7 +45,7 @@ appraise 'activerecord_6.1.0' do

platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.4.2'
gem 'sqlite3', '~> 1.7.3'
end
end

Expand All @@ -96,7 +62,24 @@ appraise 'activerecord_7.0.0' do

platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.4.2'
gem 'sqlite3', '~> 1.7.3'
end
end

appraise 'activerecord_7.1.0' do
gem 'actionpack', '~> 7.1.0', require: 'action_pack'
gem 'activerecord', '~> 7.1.0', require: 'active_record'
gem 'activesupport', '~> 7.1.0', require: 'active_support/all'

platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jdbc-sqlite3'
gem 'jdbc-postgres'
end

platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.5.6'
gem 'sqlite3', '~> 1.7.3'
end
end

Expand All @@ -114,7 +97,7 @@ appraise 'activerecord_main' do
end

platforms :ruby, :mswin, :mingw do
gem 'pg', '~> 1.3.4'
gem 'sqlite3', '~> 1.4.2'
gem 'pg', '~> 1.5.6'
gem 'sqlite3', '~> 1.7.3'
end
end
20 changes: 0 additions & 20 deletions gemfiles/activerecord_5.1.0.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/activerecord_5.2.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

platforms :ruby, :mswin, :mingw do
gem "pg", "~> 1.3.4"
gem "sqlite3", "~> 1.4.2"
gem "sqlite3", "~> 1.7.3"
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/activerecord_6.0.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

platforms :ruby, :mswin, :mingw do
gem "pg", "~> 1.3.4"
gem "sqlite3", "~> 1.4.2"
gem "sqlite3", "~> 1.7.3"
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/activerecord_6.1.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

platforms :ruby, :mswin, :mingw do
gem "pg", "~> 1.3.4"
gem "sqlite3", "~> 1.4.2"
gem "sqlite3", "~> 1.7.3"
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/activerecord_7.0.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

platforms :ruby, :mswin, :mingw do
gem "pg", "~> 1.3.4"
gem "sqlite3", "~> 1.4.2"
gem "sqlite3", "~> 1.7.3"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

source "https://rubygems.org"

gem "activerecord", "~> 5.0.2", require: "active_record"
gem "activesupport", "~> 5.0.2", require: "active_support/all"
gem "actionpack", "~> 5.0.2", require: "action_pack"
gem "actionpack", "~> 7.1.0", require: "action_pack"
gem "activerecord", "~> 7.1.0", require: "active_record"
gem "activesupport", "~> 7.1.0", require: "active_support/all"

platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter"
Expand All @@ -13,8 +13,8 @@ platforms :jruby do
end

platforms :ruby, :mswin, :mingw do
gem "pg", "~> 1.3.4"
gem "sqlite3", "~> 1.3.0"
gem "pg", "~> 1.5.6"
gem "sqlite3", "~> 1.7.3"
end

gemspec path: "../"
4 changes: 2 additions & 2 deletions gemfiles/activerecord_main.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ platforms :jruby do
end

platforms :ruby, :mswin, :mingw do
gem "pg", "~> 1.3.4"
gem "sqlite3", "~> 1.4.2"
gem "pg", "~> 1.5.6"
gem "sqlite3", "~> 1.7.3"
end

gemspec path: "../"
16 changes: 11 additions & 5 deletions lib/cancan/model_adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
module CanCan
module ModelAdapters
class ActiveRecordAdapter < AbstractAdapter
Expand Down Expand Up @@ -52,7 +55,7 @@ def parent_child_conditions(parent, child, all_conditions)
# Search again in case of polymorphic associations, this time matching on the :has_many side
# via the :as option, as well as klass
foreign_key ||= parent_class.reflect_on_all_associations(:has_many).find do |has_many_assoc|
!matching_parent_child_polymorphic_association(has_many_assoc, child_class).nil?
matching_parent_child_polymorphic_association(has_many_assoc, child_class)
end&.foreign_key&.to_sym

foreign_key.nil? ? nil : all_conditions[foreign_key]
Expand All @@ -61,7 +64,7 @@ def parent_child_conditions(parent, child, all_conditions)
def matching_parent_child_polymorphic_association(parent_assoc, child_class)
return nil unless parent_assoc.klass == child_class
return nil if parent_assoc&.options[:as].nil?

child_class.reflect_on_all_associations(:belongs_to).find do |child_assoc|
# Only match this way for polymorphic associations
child_assoc.polymorphic? && child_assoc.name == parent_assoc.options[:as]
Expand All @@ -72,12 +75,12 @@ def child_association_to_parent(parent, child)
child_class = child.is_a?(Class) ? child : child.class
parent_class = parent.is_a?(Class) ? parent : parent.class

association = child_class.reflect_on_all_associations(:belongs_to).find do |association|
association = child_class.reflect_on_all_associations(:belongs_to).find do |belongs_to_assoc|
# Do not match on polymorphic associations or it will throw an error (klass cannot be determined)
!association.polymorphic? && association.klass == parent.class
!belongs_to_assoc.polymorphic? && belongs_to_assoc.klass == parent.class
end

return association unless association.nil?
return association if association

parent_class.reflect_on_all_associations(:has_many).each do |has_many_assoc|
association ||= matching_parent_child_polymorphic_association(has_many_assoc, child_class)
Expand Down Expand Up @@ -217,6 +220,9 @@ def sanitize_sql(conditions)
end
end
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/AbcSize

ActiveSupport.on_load(:active_record) do
send :include, CanCan::ModelAdditions
Expand Down

0 comments on commit d4ef85a

Please sign in to comment.