Sha256: 6b52c87c7968558297360b00cb6fb7cc8095e4b08196e55bc50da3dbbac0e6de
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
require_relative 'helper' describe 'Adapter' do supported_by Swift::DB::Postgres, Swift::DB::Mysql, Swift::DB::DB2 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 attribute :name, Swift::Type::String attribute :image, Swift::Type::IO end Swift.db.migrate! user end it 'stores and retrieves an image' 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 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
swift-0.7.2 | test/test_io.rb |
swift-0.7.1 | test/test_io.rb |
swift-0.7.0 | test/test_io.rb |