Sha256: bb53391c045127046f29ec2ba4983abc201f9b3695077a49eae911136d618592

Contents?: true

Size: 1.7 KB

Versions: 14

Compression:

Stored size: 1.7 KB

Contents

RSpec.describe ROM::Relation, '#right_join' do
  subject(:relation) { relations[:tasks] }

  let(:users) { relations[:users] }

  include_context 'users and tasks'

  with_adapters :postgres, :mysql do
    it 'joins relations using left outer join' do
      users.insert id: 3, name: 'Jade'
      relation.insert id: 3, title: 'Unassigned'

      result = relation.
                 right_join(:users, id: :user_id).
                 select(:title, users[:name])

      expect(result.schema.map(&:name)).to eql(%i[title name])

      expect(result.to_a).to match_array([
        { name: 'Joe', title: "Joe's task" },
        { name: 'Jane', title: "Jane's task" },
        { name: 'Jade', title: nil }
      ])
    end

    context 'with associations' do
      before do
        conf.relation(:users) do
          schema(infer: true) do
            associations { has_many :tasks }
          end
        end

        conf.relation(:tasks) do
          schema(infer: true) do
            associations { belongs_to :user }
          end
        end
      end

      it 'joins relation with join keys inferred' do
        users.insert id: 3, name: 'Jade'
        relation.insert id: 3, title: 'Unassigned'

        result = relation.
                   right_join(users).
                   select(:title, users[:name])

        expect(result.schema.map(&:name)).to eql(%i[title name])

        expect(result.to_a).to match_array([
                                             { name: 'Joe', title: "Joe's task" },
                                             { name: 'Jane', title: "Jane's task" },
                                             { name: 'Jade', title: nil }
                                           ])
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rom-sql-1.2.1 spec/unit/relation/right_join_spec.rb
rom-sql-1.2.0 spec/unit/relation/right_join_spec.rb
rom-sql-1.1.2 spec/unit/relation/right_join_spec.rb
rom-sql-1.1.1 spec/unit/relation/right_join_spec.rb
rom-sql-1.1.0 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.3 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.2 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.1 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.0 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.0.rc2 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.0.rc1 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.0.beta3 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.0.beta2 spec/unit/relation/right_join_spec.rb
rom-sql-1.0.0.beta1 spec/unit/relation/right_join_spec.rb