From 7543eedd6aa35ef14e66b5614eb38e015f4b4091 Mon Sep 17 00:00:00 2001 From: John Allison Date: Thu, 20 May 2010 17:06:10 -0700 Subject: [PATCH] fixing issue when using accessible_by with nil can conditions - closes #66 --- CHANGELOG.rdoc | 4 ++++ lib/cancan/can_definition.rb | 2 +- spec/cancan/can_definition_spec.rb | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 6e1738c..65dcf67 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,7 @@ +* Fix issue when using accessible_by with nil can conditions (thanks jrallison) - see issue #66 + +* Pluralize table name for belongs_to associations in can conditions hash (thanks logandk) - see issue #62 + * Support has_many association or arrays in can conditions hash * Adding joins clause to accessible_by when conditions are across associations diff --git a/lib/cancan/can_definition.rb b/lib/cancan/can_definition.rb index c1dce1e..fc1cb0b 100644 --- a/lib/cancan/can_definition.rb +++ b/lib/cancan/can_definition.rb @@ -8,7 +8,7 @@ module CanCan @base_behavior = base_behavior @actions = [action].flatten @subjects = [subject].flatten - @conditions = conditions + @conditions = conditions || {} @block = block end diff --git a/spec/cancan/can_definition_spec.rb b/spec/cancan/can_definition_spec.rb index c9f7633..1b5f534 100644 --- a/spec/cancan/can_definition_spec.rb +++ b/spec/cancan/can_definition_spec.rb @@ -36,4 +36,9 @@ describe CanCan::CanDefinition do @conditions[:test] = 1 @can.conditions(:tableize => true).should == { :foos => { :bar => 1}, :test => 1 } end + + it "should return no association joins if conditions is nil" do + can = CanCan::CanDefinition.new(true, :read, Integer, nil, nil) + can.association_joins.should be_nil + end end