Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the tests matrix #849

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We stop testing on jruby and truffleruby because tests are failing right now

It seems specs should pass on TruffleRuby now (or actually fail in the same way they are failing on CRuby on the develop branch).

I've enabled truffleruby-head in a fork (andrykonchin#1) and there is only one failing test case that fails on CRuby as well now:

TruffleRuby failures on CI (before it was disabled) were expected and related to cancancan's depending on the old rake gem version (10.5.0) that doesn't support Ruby 3.2 because of a breaking change in Ruby 3.2 - removing Object#=~ method (TruffleRuby's latest releases target Ruby 3.2):

Run DB=sqlite bundle exec rake
rake aborted!
NoMethodError: undefined method `=~' for #<Proc:0x2c08>
<internal:core> core/enumerable.rb:501:in `block in sort_by'
<internal:core> core/enumerable.rb:500:in `map'
<internal:core> core/enumerable.rb:500:in `sort_by'
<internal:core> core/kernel.rb:378:in `load'
<internal:core> core/kernel.rb:378:in `load'
<internal:core> core/kernel.rb:378:in `load'
/home/runner/.rubies/truffleruby-24.0.1/bin/bundle:44:in `<main>'
(See full trace by running task with --trace)

The Rake issue was fixed in some recent release (ruby/rake@81763da). Now specs are run without involving Rake (with bundle exec rspec) so the Rake issue doesn't affect it. Specs weren't failing on CRuby on CI in the same time when were failing on TruffleRuby because they weren't run on Ruby 3.2 and 3.3 that have the breaking change.

cc @eregon

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a PR #853

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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Gemfile.lock
.ruby-version
.ruby-gemset
/tmp
docs/.vitepress/cache
.vitepress/cache
node_modules
docs/.vitepress/dist
.vitepress/dist
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
Loading