diff --git a/.travis.yml b/.travis.yml index 645521b9..bffcb1a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,12 @@ matrix: exclude: - rvm: 2.4.2 gemfile: gemfiles/activerecord_6.0.0.gemfile + - rvm: 2.2.6 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: 2.3.5 + gemfile: gemfiles/activerecord_6.1.0.gemfile + - rvm: 2.4.2 + gemfile: gemfiles/activerecord_6.1.0.gemfile - rvm: 2.2.6 gemfile: gemfiles/activerecord_master.gemfile - rvm: 2.3.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0cef45..d9a42628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.1 + +* [#674](https://github.com/CanCanCommunity/cancancan/pull/674): Fix accidental dependency on ActiveRecord in 3.2.0. ([@ghiculescu][]) + ## 3.2.0 * [#649](https://github.com/CanCanCommunity/cancancan/pull/649): Add support for Single Table Inheritance. ([@Liberatys][]) diff --git a/lib/cancan/config.rb b/lib/cancan/config.rb index 74f7253a..19243395 100644 --- a/lib/cancan/config.rb +++ b/lib/cancan/config.rb @@ -3,7 +3,7 @@ module CanCan def self.valid_accessible_by_strategies strategies = [:left_join] - strategies << :subquery unless CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0') + strategies << :subquery unless does_not_support_subquery_strategy? strategies end @@ -25,7 +25,7 @@ def self.accessible_by_strategy end def self.default_accessible_by_strategy - if CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0') + if does_not_support_subquery_strategy? # see https://github.com/CanCanCommunity/cancancan/pull/655 for where this was added # the `subquery` strategy (from https://github.com/CanCanCommunity/cancancan/pull/619 # only works in Rails 5 and higher @@ -40,10 +40,15 @@ def self.accessible_by_strategy=(value) raise ArgumentError, "accessible_by_strategy must be one of #{valid_accessible_by_strategies.join(', ')}" end - if value == :subquery && CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0') + if value == :subquery && does_not_support_subquery_strategy? raise ArgumentError, 'accessible_by_strategy = :subquery requires ActiveRecord 5 or newer' end @accessible_by_strategy = value end + + def self.does_not_support_subquery_strategy? + !defined?(CanCan::ModelAdapters::ActiveRecordAdapter) || + CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0') + end end