From 63865cc7d8df9ea080e7fb1adf6ca8eeb1719ee9 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Thu, 21 Apr 2011 00:46:06 -0700 Subject: [PATCH] allow SQL conditions to be used with a block --- lib/cancan/rule.rb | 2 +- spec/cancan/ability_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index aa9e640..5008e0e 100644 --- a/lib/cancan/rule.rb +++ b/lib/cancan/rule.rb @@ -16,7 +16,7 @@ module CanCan @actions = [action].flatten @subjects = [subject].flatten @attributes = [extra_args.shift].flatten if extra_args.first.kind_of?(Symbol) || extra_args.first.kind_of?(Array) && extra_args.first.first.kind_of?(Symbol) - raise Error, "You are not able to supply a block with a hash of conditions in #{action} #{subject} ability. Use either one." if extra_args.first && !block.nil? + raise Error, "You are not able to supply a block with a hash of conditions in #{action} #{subject} ability. Use either one." if extra_args.first.kind_of?(Hash) && !block.nil? @conditions = extra_args.first || {} @block = block end diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index eedc49b..daab5d9 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -188,6 +188,14 @@ describe CanCan::Ability do }.should raise_error(CanCan::Error, "You are not able to supply a block with a hash of conditions in read ranges ability. Use either one.") end + it "does not raise an error when attempting to use a block with an array of SQL conditions" do + lambda { + @ability.can :read, :ranges, ["published = ?", true] do + false + end + }.should_not raise_error(CanCan::Error) + end + # Attributes