Sha256: 7a53f12251ecf5a0239431ff166b9efdbeb97c2cc3cbf659d7ffa1222c208b9f

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

shared_examples 'supporting ByteArray' do
  before :all do
    setup_test_environment
  end

  before do
    @connection = DataObjects::Connection.new(CONFIG.uri)
  end

  after do
    @connection.close
  end

  describe 'reading a ByteArray' do
    describe 'with automatic typecasting' do
      before do
        @reader = @connection.create_command('SELECT cad_drawing FROM widgets WHERE ad_description = ?').execute_reader('Buy this product now!')
        @reader.next!
        @values = @reader.values
      end

      after do
        @reader.close
      end

      it 'returns the correctly typed result' do
        expect(@values.first).to be_kind_of(Extlib::ByteArray)
      end

      it 'returns the correct result' do
        expect(@values.first).to eq "CAD \001 \000 DRAWING"
      end
    end

    describe 'with manual typecasting' do
      before do
        @command = @connection.create_command('SELECT cad_drawing FROM widgets WHERE ad_description = ?')
        @command.set_types(Extlib::ByteArray)
        @reader = @command.execute_reader('Buy this product now!')
        @reader.next!
        @values = @reader.values
      end

      after do
        @reader.close
      end

      it 'returns the correctly typed result' do
        expect(@values.first).to be_kind_of(Extlib::ByteArray)
      end

      it 'returns the correct result' do
        expect(@values.first).to eq "CAD \001 \000 DRAWING"
      end
    end
  end

  describe 'writing a ByteArray' do
    before do
      @reader = @connection.create_command('SELECT ad_description FROM widgets WHERE cad_drawing = ?').execute_reader(
        Extlib::ByteArray.new("CAD \001 \000 DRAWING")
      )
      @reader.next!
      @values = @reader.values
    end

    after do
      @reader.close
    end

    it 'returns the correct entry' do
      # Some of the drivers starts auto-incrementation from 0 not 1
      expect(@values.first).to eq 'Buy this product now!'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sbf-data_objects-0.11.0 lib/data_objects/spec/shared/typecast/byte_array_spec.rb
sbf-data_objects-0.10.17 lib/data_objects/spec/shared/typecast/byte_array_spec.rb