Sha256: 58b043455008d0943132e6df9b2df3307f2d5ca00fe3c2efadb189f3197927c8

Contents?: true

Size: 840 Bytes

Versions: 8

Compression:

Stored size: 840 Bytes

Contents

require 'spec_helper'

describe ActiveRecordPgStuff::Relation::TemporaryTable do

  context "temporary_table" do

    let(:rel) { Seller.where(id: [1,2]) }

    it "should create temporary table from relation" do
      rs = rel.temporary_table do |tmp|
        tmp.where(id: [1,2]).load
      end
      expect(rs.map(&:class)).to eq [Seller, Seller]
      expect(rs.map(&:class).map(&:table_name)).to eq %w{ sellers sellers }
      expect(rs.map(&:id)).to eq [1,2]
      expect(rs.map(&:readonly?)).to eq [true, true]
    end

    it "should create nested temporary tables from relation" do
      rs = rel.select("id * 10 AS id").temporary_table do |tmp|
        tmp.where(id: [10]).temporary_table do |nested_tmp|
          nested_tmp.where(id: [10,20]).load
        end
      end
      expect(rs.map(&:id)).to eq [10]
    end

  end

end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
activerecord_pg_stuff-0.2.1 spec/lib/relation_temporary_table_spec.rb
envoy-activerecord_pg_stuff-0.3.0 spec/lib/relation_temporary_table_spec.rb
activerecord_pg_stuff-0.2.0 spec/lib/relation_temporary_table_spec.rb
envoy-activerecord_pg_stuff-0.0.3 spec/lib/relation_temporary_table_spec.rb
envoy_activerecord_pg_stuff-0.0.2 spec/lib/relation_temporary_table_spec.rb
directory_diff-0.4.5 vendor/gems/activerecord_pg_stuff-0.0.1/spec/lib/relation_temporary_table_spec.rb
directory_diff-0.4.4 vendor/gems/activerecord_pg_stuff-0.0.1/spec/lib/relation_temporary_table_spec.rb
activerecord_pg_stuff-0.0.1 spec/lib/relation_temporary_table_spec.rb