Sha256: 2050fbea6ffb80d36b935dfdf2964d37ba5fd8278a1760b463a155c51631b920

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require_relative 'helper'

describe 'Adapter' do
  supported_by Swift::DB::Postgres, Swift::DB::Mysql, Swift::DB::Sqlite3 do
    describe 'typecasting' do
      before do
        @db = Swift.db
        @db.execute %q{drop table if exists users}
        serial = case @db
          when Swift::DB::Sqlite3 then 'integer primary key'
          else 'serial'
        end
        @db.execute %Q{
          create table users(
            id      #{serial},
            name    text,
            age     integer,
            height  float,
            hacker  bool,
            slacker bool,
            created date,
            updated timestamp
          )
        }
      end

      it 'query result is typecast correctly' do
        dt   = '2010-01-01 23:22:21'
        bind = [ 1, 'jim', 32, 178.71, true, false, '2010-01-02', "#{dt}.012345+11:00" ]
        @db.execute %q{insert into users values(?, ?, ?, ?, ?, ?, ?, ?)}, *bind

        result = @db.prepare(%q{select * from users limit 1}).execute.first
        assert_kind_of Integer,    result[:id]
        assert_kind_of String,     result[:name]
        assert_kind_of Integer,    result[:age]
        assert_kind_of Float,      result[:height]
        assert_kind_of TrueClass,  result[:hacker]
        assert_kind_of FalseClass, result[:slacker]
        assert_kind_of Date,       result[:created]
        assert_kind_of Time,       result[:updated]

        assert_equal   dt,         result[:updated].strftime('%F %T')
        assert_equal   12345,      result[:updated].usec unless @db.kind_of?(Swift::DB::Mysql)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
swift-0.8.1 test/test_types.rb