test/test_adapter.rb in swift-0.8.0 vs test/test_adapter.rb in swift-0.8.1
- old
+ new
@@ -18,10 +18,16 @@
Swift.db do |db|
assert_kind_of Swift::Adapter, db
end
end
+ it 'reconnects to db' do
+ Swift.trace true, open('/dev/null', 'w')
+ assert_block { @db.reconnect }
+ Swift.trace false
+ end
+
describe 'execute' do
it 'executes without bind values' do
assert @db.execute %q{select count(*) from users}
end
@@ -54,11 +60,13 @@
it 'has insert_id' do
sql = case @db
when Swift::DB::Postgres then %q{insert into users (name) values (?) returning id}
else %q{insert into users (name) values (?)}
end
- assert_kind_of Fixnum, @db.prepare(sql).execute('Connie Arthurton').insert_id
+ statement = @db.prepare(sql)
+ assert 1, statement.execute('Connie Arthurton').insert_id
+ assert 1, statement.insert_id # caches insert_id, just interface compatibility with dbic++
end
end
describe 'executed prepared statements' do
before do
@@ -114,11 +122,15 @@
data = "Sally Arthurton\tsally@local\nJonas Arthurton\tjonas@local\n"
assert_equal 2, @db.write('users', %w{name email}, data)
end
it 'writes with no columns specified' do
- data = "1\tSally Arthurton\tsally@local\t2010-01-01 00:00:00\n"
- assert_equal 1, @db.write('users', [], data)
+ ts = DateTime.parse('2010-01-01 00:00:00').to_time
+ data = "1\tSally Arthurton\tsally@local\t#{ts}\n"
+ row = {id: 1, name: 'Sally Arthurton', email: 'sally@local', created_at: ts}
+
+ assert_equal 1, @db.write('users', [], data)
+ assert_equal row, @db.execute('select * from users limit 1').first
end
end
end
end
end