Return empty set early if no can rules are present.

Thanks dkubb!
This commit is contained in:
Emmanuel Gomez 2011-04-29 12:03:13 -07:00
parent d6851debd4
commit 16bdb8d42e

View File

@ -17,6 +17,7 @@ module CanCan
def database_records
scope = @model_class.all(:conditions => ["0 = 1"])
cans, cannots = @rules.partition { |r| r.base_behavior }
return scope if cans.empty?
# apply unions first, then differences. this mean cannot overrides can
cans.each { |r| scope += @model_class.all(:conditions => r.conditions) }
cannots.each { |r| scope -= @model_class.all(:conditions => r.conditions) }