Sha256: 0e252c0901b8d6fc9e9b94319a62ba806917122915f3996a225ed8fcfa4dde64

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require_relative '../test_helper'

require 'csv_query/database'

describe CsvQuery::Database do

  def csv_data
    @csv_data ||= CSV.parse("Bar", :headers => ["Foo"])
  end

  def build_database
    CsvQuery::Database.new(csv_data)
  end

  describe ".new" do
    it "creates SQLite database" do
      database = build_database
      database.database.class.must_equal(SQLite3::Database)
    end

    it "creates a database table" do
      database = build_database

      columns = database.database.table_info("csv")
      columns.collect { |column| column["name"] }.must_equal(["Foo"])
    end
  end

  describe "#import_csv" do
    it "imports data from csv" do
      database = build_database
      database.import_data_from_csv(csv_data)

      results = database.database.query("SELECT * FROM csv")
      results.to_a.must_equal([["Bar"]])
    end
  end

  describe "#query" do
    it "returns headers and results as arrays" do
      database = build_database
      database.import_data_from_csv(csv_data)

      results = database.query("SELECT * FROM csv")
      results.to_a.must_equal([["Foo"], ["Bar"]])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_query-1.0.4 test/csv_query/database_test.rb