Skip to content

Commit f766239

Browse files
authored
Merge pull request #91 from sdemjanenko/dont_lookup_policy_when_record_is_self
allowed_to?: don't lookup policy if record is the same as the current policy
2 parents 57c7f2a + 8e8ef71 commit f766239

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/action_policy/policy/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def with_clean_result # :nodoc:
101101
#
102102
# If record is `nil` then we uses the current policy.
103103
def allowed_to?(rule, record = :__undef__, **options)
104-
if record == :__undef__ && options.empty?
104+
if (record == :__undef__ || record == self.record) && options.empty?
105105
__apply__(rule)
106106
else
107107
policy_for(record: record, **options).apply(rule)

lib/action_policy/policy/reasons.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def details
179179

180180
def allowed_to?(rule, record = :__undef__, **options)
181181
res =
182-
if record == :__undef__
182+
if (record == :__undef__ || record == self.record) && options.empty?
183183
policy = self
184184
with_clean_result { apply(rule) }
185185
else

0 commit comments

Comments
 (0)