Fix for issue #560 #655

Merged
merged 2 commits into from Jul 2, 2012
Jump to file or symbol
Failed to load files and symbols.
+8 −2
Split
@@ -145,8 +145,8 @@ def sanitize_sql(conditions)
# Takes two hashes and does a deep merge.
def merge_joins(base, add)
add.each do |name, nested|
- if base[name].is_a?(Hash) && !nested.empty?
- merge_joins(base[name], nested)
+ if base[name].is_a?(Hash)
+ merge_joins(base[name], nested) unless nested.empty?
else
base[name] = nested
end
@@ -227,6 +227,12 @@
@ability.model_adapter(Article, :read).joins.should == [:project]
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
@ability.can :read, Article, :priority.lt => 2
article1 = Article.create!(:priority => 1)