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

config.accessible_by_strategy only impacts the AR adapter #674

Merged
merged 2 commits into from
Dec 14, 2020
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
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