spec/join_association_spec.rb in arel-helpers-2.3.0 vs spec/join_association_spec.rb in arel-helpers-2.4.0
- old
+ new
@@ -27,9 +27,23 @@
.joins(ArelHelpers.join_association(Comment, :author))
.to_sql.should ==
'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"'
end
+ it "should work for a nested hash of association names" do
+ Post
+ .joins(ArelHelpers.join_association(Post, { comments: :author }))
+ .to_sql.should ==
+ 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"'
+ end
+
+ it "should work with outer joins when given a nested hash of association names" do
+ Post
+ .joins(ArelHelpers.join_association(Post, { comments: :author }, Arel::Nodes::OuterJoin))
+ .to_sql.should ==
+ 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "authors" ON "authors"."id" = "comments"."author_id"'
+ end
+
it "should be able to handle multiple associations" do
Post.joins(ArelHelpers.join_association(Post, [:comments, :favorites])).to_sql.should ==
'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" INNER JOIN "favorites" ON "favorites"."post_id" = "posts"."id"'
end