Sha256: 7a5aa628d6b93ca076a8a393150fc34ed73428c0ff30594b481d663ed3c10a98

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

require "spec_helper"

describe "Simple::SQL conversions" do
  def expects(expected_result, sql, *args)
    expect(Simple::SQL.ask(sql, *args)).to eq(expected_result)
  end

  describe "data conversions" do
    it "returns arrays when asking for multiple columns" do
      expects ["one", "two", 3.5], "SELECT 'one', 'two', 3.5"
    end

    it "converts text arrays" do
      expects ["foo,bar"], "SELECT ARRAY[$1::varchar]", "foo,bar"
      expects %w(foo bar), "SELECT $1::varchar[]", %w(foo bar)
    end

    it "converts integer arrays" do
      expects [1, 2, 3], "SELECT ARRAY[1,2,3]"
    end

    it "converts weird strings properly" do
      expects "foo,\"bar}", "SELECT $1::varchar", "foo,\"bar}"
      expects ["one", "two", "3.5", "foo,\"bar}"], "SELECT ARRAY['one', 'two', '3.5', 'foo,\"bar}']"
      expects ["foo", "foo,bar}"], "SELECT $1::varchar[]", ["foo", "foo,bar}"]
    end

    it "parses JSON as expected" do
      expects({"a"=>1, "b"=>2}, 'SELECT \'{"a":1,"b":2}\'::json')
      expects({"a"=>1, "b"=>2}, 'SELECT \'{"a":1,"b":2}\'::jsonb')
    end

    xit "fails sometimes w/ malformed array literal, pt. 1" do
      expects  0, 'SELECT $1::varchar[]', [ "foo", 'foo,"bar}' ]
    end

    xit "fails sometimes w/ malformed array literal, pt. 2" do
      expects  0, 'SELECT $1::varchar[]', [ "foo", 'foo,"bar}' ]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
simple-sql-0.2.5 spec/simple/sql_conversion_spec.rb
simple-sql-0.2.4 spec/simple/sql_conversion_spec.rb
simple-sql-0.2.3 spec/simple/sql_conversion_spec.rb
simple-sql-0.2.2 spec/simple/sql_conversion_spec.rb
simple-sql-0.2.1 spec/simple/sql_conversion_spec.rb
simple-sql-0.2.0 spec/simple/sql_conversion_spec.rb
simple-sql-0.1.3 spec/simple/sql_conversion_spec.rb