Sha256: 7f891bc429f3cdde2b151f6ac7955f4441a63bb803787fc6db6dafb977bc0849

Contents?: true

Size: 692 Bytes

Versions: 8

Compression:

Stored size: 692 Bytes

Contents

require 'spec_helper'

describe ActiveRecordPgStuff::Relation::TemporaryTable do

  context "pivot" do

    let(:rel) { Payment }

    it "should create pivot table from relation" do
      rs = rel.select(:seller_id, "SUM(amount) AS amount", "DATE_TRUNC('month', created_at) AS created_at")
              .group("seller_id, DATE_TRUNC('month', created_at)").temporary_table do |tmp|
                tmp.pivot :created_at, :seller_id, :amount
              end

      expect(rs.headers).to eq [nil,1,2]
      expect(rs.rows).to eq [
        [ Time.utc(2012, 9,  1), nil, 5  ],
        [ Time.utc(2012, 10, 1), 1,   7  ],
        [ Time.utc(2012, 11, 1), 3,   24 ],
      ]
    end

  end

end

Version data entries

8 entries across 8 versions & 4 rubygems

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