Sha256: f2d353b9a2482cbcc66b93242d99b6f65b5cccc1254e0827ab67a809c7d0a403

Contents?: true

Size: 1.4 KB

Versions: 23

Compression:

Stored size: 1.4 KB

Contents

# Copyright 2020 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

# frozen_string_literal: true

require "test_helper"

module ActiveRecord
  module Type
    class BinaryTest < SpannerAdapter::TestCase
      include SpannerAdapter::Types::TestHelper

      def test_convert_to_sql_type
        assert_equal "BYTES(MAX)", connection.type_to_sql(:binary)
        assert_equal "BYTES(1024)", connection.type_to_sql(:binary, limit: 1024)
      end

      def test_set_binary_data_io_in_create
        data = StringIO.new "hello"

        record = TestTypeModel.create(data: data)
        record.reload

        assert_equal "hello", record.data.read
      end

      def test_set_binary_data_byte_string_in_create
        data = StringIO.new "hello1"

        record = TestTypeModel.create(data: data.read)
        record.reload

        assert_equal "hello1", record.data.read
      end

      def test_check_max_limit
        str = "a" * 256

        assert_raise(ActiveRecord::StatementInvalid) {
          TestTypeModel.create(name: str)
        }
      end

      def test_set_binary_data_from_file
        Tempfile.create do |f|
          f << "hello 123"

          record = TestTypeModel.create(file: f)
          record.reload

          assert_equal "hello 123", record.file.read
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
activerecord-spanner-adapter-2.0.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.8.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.6.3 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.6.2 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.6.1 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.6.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.5.1 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.5.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.4.4 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.4.3 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.4.2 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.4.1 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.4.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.3.1 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.2.2 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.2.1 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.2.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.1.0 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.0.1 acceptance/cases/type/binary_test.rb
activerecord-spanner-adapter-1.0.0 acceptance/cases/type/binary_test.rb