Sha256: 2b8ef535c0ab74dd6c5cb3fae7f60cece15c9b0418e9538c0aee3a6e90136c50

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

describe MyObfuscate::Postgres do

  let(:helper) { MyObfuscate::Postgres.new }

  describe "#rows_to_be_inserted" do
    it 'splits tab seperated values' do
      line = "1	2	3	4"
      helper.rows_to_be_inserted(line).should == [["1","2","3","4"]]
    end

    it 'ignores the newline character at the end of string' do
      line = "1	2	3	4\n"
      helper.rows_to_be_inserted(line).should == [["1","2","3","4"]]
    end

    it "doesn't ignore newline characters in the string" do
      line = "1	2	3\n4	5"
      helper.rows_to_be_inserted(line).should == [["1","2","3\n4","5"]]
    end

    it "replaces \\N with nil" do
      line = "1	2	\\N	4"
      helper.rows_to_be_inserted(line).should == [["1","2",nil,"4"]]
    end
  end

  describe "#parse_copy_statement" do
    it 'parses table name and column names' do
      line = "COPY some_table (id, email, name, something) FROM stdin;"
      hash = helper.parse_copy_statement(line)
      hash[:table_name].should == :some_table
      hash[:column_names].should == [:id, :email, :name, :something]
    end
  end

  describe "#make_insert_statement" do
    it 'creates a string with tab delminted' do
      helper.make_insert_statement(:some_table, [:id, :name], ['1', '2']).should == "1	2"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
my_obfuscate-0.5.1 spec/my_obfuscate/postgres_spec.rb
my_obfuscate-0.5.0 spec/my_obfuscate/postgres_spec.rb