Skip to content

Commit 662b6c1

Browse files
authored
Merge pull request #674 from ghiculescu/dont-rely-on-ar
`config.accessible_by_strategy` only impacts the AR adapter
2 parents abfa504 + 40bc8a4 commit 662b6c1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ matrix:
3030
exclude:
3131
- rvm: 2.4.2
3232
gemfile: gemfiles/activerecord_6.0.0.gemfile
33+
- rvm: 2.2.6
34+
gemfile: gemfiles/activerecord_6.1.0.gemfile
35+
- rvm: 2.3.5
36+
gemfile: gemfiles/activerecord_6.1.0.gemfile
37+
- rvm: 2.4.2
38+
gemfile: gemfiles/activerecord_6.1.0.gemfile
3339
- rvm: 2.2.6
3440
gemfile: gemfiles/activerecord_master.gemfile
3541
- rvm: 2.3.5

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.2.1
2+
3+
* [#674](https://github.com/CanCanCommunity/cancancan/pull/674): Fix accidental dependency on ActiveRecord in 3.2.0. ([@ghiculescu][])
4+
15
## 3.2.0
26

37
* [#649](https://github.com/CanCanCommunity/cancancan/pull/649): Add support for Single Table Inheritance. ([@Liberatys][])

lib/cancan/config.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module CanCan
44
def self.valid_accessible_by_strategies
55
strategies = [:left_join]
6-
strategies << :subquery unless CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
6+
strategies << :subquery unless does_not_support_subquery_strategy?
77
strategies
88
end
99

@@ -25,7 +25,7 @@ def self.accessible_by_strategy
2525
end
2626

2727
def self.default_accessible_by_strategy
28-
if CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
28+
if does_not_support_subquery_strategy?
2929
# see https://github.com/CanCanCommunity/cancancan/pull/655 for where this was added
3030
# the `subquery` strategy (from https://github.com/CanCanCommunity/cancancan/pull/619
3131
# only works in Rails 5 and higher
@@ -40,10 +40,15 @@ def self.accessible_by_strategy=(value)
4040
raise ArgumentError, "accessible_by_strategy must be one of #{valid_accessible_by_strategies.join(', ')}"
4141
end
4242

43-
if value == :subquery && CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
43+
if value == :subquery && does_not_support_subquery_strategy?
4444
raise ArgumentError, 'accessible_by_strategy = :subquery requires ActiveRecord 5 or newer'
4545
end
4646

4747
@accessible_by_strategy = value
4848
end
49+
50+
def self.does_not_support_subquery_strategy?
51+
!defined?(CanCan::ModelAdapters::ActiveRecordAdapter) ||
52+
CanCan::ModelAdapters::ActiveRecordAdapter.version_lower?('5.0.0')
53+
end
4954
end

0 commit comments

Comments
 (0)