Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'optional-associations' of https://github.com/socialcast…

…/cancan into socialcast-optional-associations
  • Loading branch information...
commit b1424dfa493202db3726565022bc09d381d89727 2 parents a10243a + 6aaab9e
@ryanb authored
Showing with 8 additions and 1 deletion.
  1. +1 −1  lib/cancan/rule.rb
  2. +7 −0 spec/cancan/ability_spec.rb
View
2  lib/cancan/rule.rb
@@ -109,7 +109,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
if attribute.kind_of? Array
attribute.any? { |element| matches_conditions_hash? element, value }
else
- matches_conditions_hash? attribute, value
+ !attribute.nil? && matches_conditions_hash?(attribute, value)
end
elsif value.kind_of?(Array) || value.kind_of?(Range)
value.include? attribute
View
7 spec/cancan/ability_spec.rb
@@ -249,6 +249,13 @@
@ability.can?(:read, 1..5).should be_true
@ability.can?(:read, 4..6).should be_false
end
+
+ it "should not match subjects return nil for methods that must match nested a nested conditions hash" do
+ mock(object_with_foo = Object.new).foo { :bar }
+ @ability.can :read, Array, :first => { :foo => :bar }
+ @ability.can?(:read, [object_with_foo]).should be_true
+ @ability.can?(:read, []).should be_false
+ end
it "should not stop at cannot definition when comparing class" do
@ability.can :read, Range
Please sign in to comment.
Something went wrong with that request. Please try again.