commit
d20d90d2c2
|
@ -145,8 +145,8 @@ module CanCan
|
||||||
# Takes two hashes and does a deep merge.
|
# Takes two hashes and does a deep merge.
|
||||||
def merge_joins(base, add)
|
def merge_joins(base, add)
|
||||||
add.each do |name, nested|
|
add.each do |name, nested|
|
||||||
if base[name].is_a?(Hash) && !nested.empty?
|
if base[name].is_a?(Hash)
|
||||||
merge_joins(base[name], nested)
|
merge_joins(base[name], nested) unless nested.empty?
|
||||||
else
|
else
|
||||||
base[name] = nested
|
base[name] = nested
|
||||||
end
|
end
|
||||||
|
|
|
@ -227,6 +227,12 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
||||||
@ability.model_adapter(Article, :read).joins.should == [:project]
|
@ability.model_adapter(Article, :read).joins.should == [:project]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should merge nested and non-nested joins" do
|
||||||
|
@ability.can :read, Article, :project => { :blocked => false }
|
||||||
|
@ability.can :read, Article, :project => { :comments => { :spam => true } }
|
||||||
|
@ability.model_adapter(Article, :read).joins.should == [{:project=>[:comments]}]
|
||||||
|
end
|
||||||
|
|
||||||
it "should restrict articles given a MetaWhere condition" do
|
it "should restrict articles given a MetaWhere condition" do
|
||||||
@ability.can :read, Article, :priority.lt => 2
|
@ability.can :read, Article, :priority.lt => 2
|
||||||
article1 = Article.create!(:priority => 1)
|
article1 = Article.create!(:priority => 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user