Permalink
Browse files

Merge pull request #655 from DavidMikeSimon/master

Fix for issue #560
  • Loading branch information...
2 parents 1e89b31 + b162871 commit d20d90d2c2165e44f1155ef315e6feb153139553 @ryanb committed Jul 2, 2012
View
4 lib/cancan/model_adapters/active_record_adapter.rb
@@ -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
View
6 spec/cancan/model_adapters/active_record_adapter_spec.rb
@@ -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)

0 comments on commit d20d90d

Please sign in to comment.