Skip to content

Commit

Permalink
Merge pull request #674 from ghiculescu/dont-rely-on-ar
Browse files Browse the repository at this point in the history
`config.accessible_by_strategy` only impacts the AR adapter
  • Loading branch information
coorasse authored Dec 14, 2020
2 parents abfa504 + 40bc8a4 commit 662b6c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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][])
Expand Down
11 changes: 8 additions & 3 deletions lib/cancan/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

0 comments on commit 662b6c1

Please sign in to comment.