Sha256: 02177a5ce3f2e62eae6dbb802907ea44c76dd1a96c232bfb8a0dfb9ab419fcf1

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

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

describe "pg_upsert from file with binary data" do
  before(:each) do
    ActiveRecord::Base.connection.execute %{
      TRUNCATE TABLE test_models;
      SELECT setval('test_models_id_seq', 1, false);
    }
  end

  before do
    DateTime.stub(:now).and_return (DateTime.parse("2012-01-01").utc)
  end

  def timestamp
    DateTime.now.utc.to_s
  end

  it "imports from file if path is passed without field_map" do
    TestModel.pg_upsert File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary, columns: [:id, :data]

    expect(
      TestModel.first.attributes
    ).to include('data' => 'text', 'created_at' => timestamp, 'updated_at' => timestamp)
  end

  it "throws an error when importing binary file without columns list" do
    # Since binary data never has a header row, we'll require explicit columns list
    expect{
      TestModel.pg_upsert File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary
    }.to raise_error "Either the :columns option or :header => true are required"
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
postgres_upsert-3.1.0-java spec/pg_upsert_binary_spec.rb
postgres_upsert-3.0.0 spec/pg_upsert_binary_spec.rb
postgres_upsert-2.0.0 spec/pg_upsert_binary_spec.rb
postgres_upsert-1.1.0 spec/pg_upsert_binary_spec.rb
postgres_upsert-1.0.0 spec/pg_upsert_binary_spec.rb