Sha256: 8f3a86cdba95f1342d1ab8e8ba5b71228e22f997f4665dbe3886299d7a6265ad
Contents?: true
Size: 1.48 KB
Versions: 11
Compression:
Stored size: 1.48 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "COPY TO" do before(:all) do ActiveRecord::Base.connection.execute %{ TRUNCATE TABLE test_models; SELECT setval('test_models_id_seq', 1, false); } TestModel.create :data => 'test data 1' end describe ".pg_copy_to_string" do context "with no options" do subject{ TestModel.pg_copy_to_string } it{ should == File.open('spec/fixtures/comma_with_header.csv', 'r').read } end context "with tab as delimiter" do subject{ TestModel.pg_copy_to_string :delimiter => "\t" } it{ should == File.open('spec/fixtures/tab_with_header.csv', 'r').read } end end describe ".pg_copy_to" do it "should copy and pass data to block if block is given and no path is passed" do File.open('spec/fixtures/comma_with_header.csv', 'r') do |f| TestModel.pg_copy_to do |row| row.should == f.readline end end end it "should copy to disk if block is not given and a path is passed" do TestModel.pg_copy_to '/tmp/export.csv' File.open('spec/fixtures/comma_with_header.csv', 'r') do |fixture| File.open('/tmp/export.csv', 'r') do |result| result.read.should == fixture.read end end end it "should raise exception if I pass a path and a block simultaneously" do lambda do TestModel.pg_copy_to('/tmp/bogus_path') do |row| end end.should raise_error end end end
Version data entries
11 entries across 11 versions & 1 rubygems