Sha256: 3e4a21b2b943b4a3b8474eae9467c687c6a84dba4be2d9bf1e9cbbebdfbc8cb4

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

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

  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

9 entries across 9 versions & 1 rubygems

Version Path
rom-sql-1.3.5 spec/unit/relation/right_join_spec.rb
rom-sql-1.3.4 spec/unit/relation/right_join_spec.rb
rom-sql-2.0.0.beta2 spec/unit/relation/right_join_spec.rb
rom-sql-2.0.0.beta1 spec/unit/relation/right_join_spec.rb
rom-sql-1.3.3 spec/unit/relation/right_join_spec.rb
rom-sql-1.3.2 spec/unit/relation/right_join_spec.rb
rom-sql-1.3.1 spec/unit/relation/right_join_spec.rb
rom-sql-1.3.0 spec/unit/relation/right_join_spec.rb
rom-sql-1.2.2 spec/unit/relation/right_join_spec.rb