allow SQL conditions to be used with a block
This commit is contained in:
parent
c6f9abb6ab
commit
63865cc7d8
|
@ -16,7 +16,7 @@ module CanCan
|
||||||
@actions = [action].flatten
|
@actions = [action].flatten
|
||||||
@subjects = [subject].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)
|
@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 || {}
|
@conditions = extra_args.first || {}
|
||||||
@block = block
|
@block = block
|
||||||
end
|
end
|
||||||
|
|
|
@ -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.")
|
}.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
|
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
|
# Attributes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user