From 1be5bf7a577e6353de966b2a29cd70743c845b97 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 3 Sep 2010 11:05:58 -0700 Subject: [PATCH] don't fail if association conditions aren't specified for nested association check --- lib/cancan/can_definition.rb | 2 +- spec/cancan/ability_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cancan/can_definition.rb b/lib/cancan/can_definition.rb index b81a8bc..dbe56ca 100644 --- a/lib/cancan/can_definition.rb +++ b/lib/cancan/can_definition.rb @@ -104,7 +104,7 @@ module CanCan def nested_subject_matches_conditions?(subject_hash) parent, child = subject_hash.shift - matches_conditions_hash?(parent, @conditions[parent.class.name.downcase.to_sym]) + matches_conditions_hash?(parent, @conditions[parent.class.name.downcase.to_sym] || {}) end def call_block_with_all(action, subject, extra_args) diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 4dac4d6..160b320 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -254,6 +254,7 @@ describe CanCan::Ability do @ability.can :read, Range, :string => {:length => 3} @ability.can?(:read, "foo" => Range).should be_true @ability.can?(:read, "foobar" => Range).should be_false + @ability.can?(:read, 123 => Range).should be_true end describe "unauthorized message" do