spec/join_association_spec.rb in arel-helpers-2.5.0 vs spec/join_association_spec.rb in arel-helpers-2.6.0

- old
+ new

@@ -63,9 +63,25 @@ it 'should be able to handle has_and_belongs_to_many associations' do CollabPost.joins(ArelHelpers.join_association(CollabPost, :authors)).to_sql.should == 'SELECT "collab_posts".* FROM "collab_posts" INNER JOIN "authors_collab_posts" ON "authors_collab_posts"."collab_post_id" = "collab_posts"."id" INNER JOIN "authors" ON "authors"."id" = "authors_collab_posts"."author_id"' end + it "allows adding a custom alias to the joined table" do + Comment.aliased_as(:foo) do |foo| + Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::InnerJoin, aliases: [foo])).to_sql.should == + 'SELECT "posts".* FROM "posts" INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id"' + end + end + + it "allows aliasing multiple associations" do + Comment.aliased_as(:foo) do |foo| + Favorite.aliased_as(:bar) do |bar| + Post.joins(ArelHelpers.join_association(Post, [:comments, :favorites], Arel::Nodes::InnerJoin, aliases: [foo, bar])).to_sql.should == + 'SELECT "posts".* FROM "posts" INNER JOIN "comments" "foo" ON "foo"."post_id" = "posts"."id" INNER JOIN "favorites" "bar" ON "bar"."post_id" = "posts"."id"' + end + end + end + it 'handles polymorphic through associations' do relation = Location.joins( ArelHelpers.join_association(Location, :community_tickets) )