Sha256: de38afbaa9f0bea3167bd3f345d615da4a7b3d5e50e166bcdf6336cca36160ec

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "COPY TO BINARY" do
  before(:all) do
    ActiveRecord::Base.connection.execute %{
      TRUNCATE TABLE test_models;
      SELECT setval('test_models_id_seq', 1, false);
}
    TestModel.create :data => 'text'
  end

  describe "should allow binary output to string" do
    context "with only binary option" do
      subject{ TestModel.pg_copy_to_string(:format => :binary) }
      it{ should == File.open('spec/fixtures/2_col_binary_data.dat', 'r:ASCII-8BIT').read }
    end
    context "with custom select" do
      subject{ TestModel.select("id, data").pg_copy_to_string(:format => :binary) }
      it{ should == File.open('spec/fixtures/2_col_binary_data.dat', 'r:ASCII-8BIT').read }
    end
  end

  describe "should allow binary output to file" do
    it "should copy to disk if block is not given and a path is passed" do
      TestModel.pg_copy_to '/tmp/export.dat', :format => :binary
      str = File.open('/tmp/export.dat', 'r:ASCII-8BIT').read

      str.should == File.open('spec/fixtures/2_col_binary_data.dat', 'r:ASCII-8BIT').read
      
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
postgres-copy-0.7.0 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.6.0 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.8 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.7 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.5 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.4 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.3 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.2 spec/pg_copy_to_binary_spec.rb
postgres-copy-0.5.0 spec/pg_copy_to_binary_spec.rb