Sha256: d5ad6df8c7058e2cc056d607d754eafdb7e6726e9ac5fa6cb0432617953c4cd0

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

# require 'spec_helper'
class DummyClass
end
describe '#form_query_for_datatype' do
  before(:each) do
    @dummy_class = DummyClass.new
    @dummy_class.extend(CsvImportAnalyzer::PgQueryHelper)
  end
  context 'expected arguments are not set' do
    let(:args) {Hash[:header => :test]}
    let(:args1) {Hash[:datatype, :test]}
    it ' returns missing arguments error' do
      expect(@dummy_class.form_query_for_datatype(args)).to be_instance_of(MissingRequiredArguments)
    end
    it 'returns invalid if set to nil' do
      expect(@dummy_class.form_query_for_datatype(args1)).to be_instance_of(MissingRequiredArguments)
    end
  end

  context 'expected arguments are set' do
    let(:args) {Hash[:header => :test, :datatype => :string]}
    let(:args1) {Hash[:header => :test, :datatype => :integer]}
    it 'returns expected sql query for string' do
      expect(@dummy_class.form_query_for_datatype(args)).to eq("test varchar(255)")
    end
    it 'returns expected sql query for numeric' do
      expect(@dummy_class.form_query_for_datatype(args1)).to eq("test integer")
    end
  end

end
describe '#import_csv' do
  before(:each) do
    @dummy_class = DummyClass.new
    @dummy_class.extend(CsvImportAnalyzer::PgQueryHelper)
  end
  context 'expected arguments are not set' do
    let(:args) {Hash[:tablename => "test", :delimiter => ","]}
    let(:args1) {Hash[:filename => "test"]}
    it ' return SqlQueryErrror' do
      expect(@dummy_class.import_csv(args)).to be_instance_of(MissingRequiredArguments)
    end
    it 'should return SqlQueryErrror' do
      expect(@dummy_class.import_csv(args1)).to be_instance_of(MissingRequiredArguments)
    end
  end

  context 'expected arguments are set' do
    let(:args) {Hash[:tablename => "test", :delimiter => ",", :filename => "filename"]}
    it 'returns expected import query' do
      expect(@dummy_class.import_csv(args)).to eq("COPY test FROM 'filename' HEADER DELIMITER ',' CSV NULL AS 'NULL';")
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csv-import-analyzer-0.0.3 spec/csv-import-analyzer/query_builder/pg_query_helper_spec.rb
csv-import-analyzer-0.0.2 spec/csv-import-analyzer/query_builder/pg_query_helper_spec.rb
csv-import-analyzer-0.0.1 spec/csv-import-analyzer/query_builder/pg_query_helper_spec.rb