test/test_io.rb in swift-0.7.2 vs test/test_io.rb in swift-0.8.0
- old
+ new
@@ -1,9 +1,9 @@
require_relative 'helper'
describe 'Adapter' do
- supported_by Swift::DB::Postgres, Swift::DB::Mysql, Swift::DB::DB2 do
+ supported_by Swift::DB::Postgres, Swift::DB::Mysql, Swift::DB::Sqlite3 do
describe 'Storing binary objects' do
before do
user = Class.new(Swift::Scheme) do
store :users
attribute :id, Swift::Type::Integer, serial: true, key: true
@@ -11,13 +11,29 @@
attribute :image, Swift::Type::IO
end
Swift.db.migrate! user
end
- it 'stores and retrieves an image' do
+ it 'stores and retrieves an image via prepared statement' do
Swift.db do |db|
io = File.open(File.dirname(__FILE__) + '/house-explode.jpg')
db.prepare('insert into users (name, image) values(?, ?)').execute('test', io)
+
+ blob = db.prepare('select image from users limit 1').execute.first[:image]
+
+ io.rewind
+ assert_kind_of StringIO, blob
+
+ data = blob.read
+ assert_equal Encoding::ASCII_8BIT, data.encoding
+ assert_equal io.read.force_encoding('ASCII-8BIT'), data
+ end
+ end
+
+ it 'stores and retrieves an image via Adapter#execute' do
+ Swift.db do |db|
+ io = File.open(File.dirname(__FILE__) + '/house-explode.jpg')
+ db.execute('insert into users (name, image) values(?, ?)', 'test', io)
blob = db.prepare('select image from users limit 1').execute.first[:image]
io.rewind
assert_kind_of StringIO, blob