Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simplify blank array result

  • Loading branch information...
commit 5690e6612861c07ef6107cbaa5d03d0cf3b6d3de 1 parent 0c698e2
Matt Vermaak authored
Showing with 13 additions and 18 deletions.
  1. +2 −18 lib/sanction/result/blank_array.rb
  2. +11 −0 test/unit/sanction_test.rb
20 lib/sanction/result/blank_array.rb
View
@@ -6,24 +6,8 @@ def initialize(decoy)
end
def method_missing(m, *args)
- if @decoy.class.respond_to? :is_a_principal? and @decoy.class.is_a_principal?
- if [:has, :over].include? m
- Sanction::Result::BlankArray.new(@decoy)
- elsif [:has?, :over?].include? m
- false
- else
- @decoy.reset_preload_scope
- [].send(m, *args)
- end
- elsif @decoy.class.respond_to? :is_a_permissionable? and @decoy.class.is_a_permissionable?
- if [:with, :for].include? m
- Sanction::Result::BlankArray.new(@decoy)
- elsif [:with?, :for?].include? m
- false
- else
- @decoy.reset_preload_scope
- [].send(m, *args)
- end
+ if [:has, :over, :with, :for, :has?, :over?, :with?, :for?].include? m
+ @decoy.send(m, *args)
else
@decoy.reset_preload_scope
[].send(m, *args)
11 test/unit/sanction_test.rb
View
@@ -613,4 +613,15 @@ def test_preload_roles_with_any
assert person.has(:any).over?(:any)
assert magazine.for(:any).with?(:any)
end
+
+ def test_blank_array_result_with_principal_permissionable
+ Person.last.grant(:tester, Person.first)
+
+ person = Person.first :preload_roles => true
+
+ Person.last.revoke(:tester, Person.first)
+
+ assert !person.with(:non_role).for?(:any)
+ assert person.with(:tester).for?(:any)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.