Sha256: 4bd339ebb7fdeebd4c32f48708720d5aee3f8a1ed85a8f317b74593ef61fd4c4

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

# encoding: UTF-8
require 'cases/helper_sqlserver'

class SQLServerUuidTest < ActiveRecord::TestCase

  let(:acceptable_uuid) { ActiveRecord::ConnectionAdapters::SQLServer::Type::Uuid::ACCEPTABLE_UUID }

  it 'has a uuid primary key' do
    SSTestUuid.columns_hash['id'].type.must_equal :uuid
    assert SSTestUuid.primary_key
  end

  it 'can create with a new pk' do
    skip 'We do not support uuid autogenerated primary keys at this time' if defined? JRUBY_VERSION
    obj = SSTestUuid.create!
    obj.id.must_be :present?
    obj.id.must_match acceptable_uuid
  end

  it 'can create other uuid column on reload' do
    skip 'We do not support uuid autogenerated primary keys at this time' if defined? JRUBY_VERSION
    obj = SSTestUuid.create!
    obj.reload
    obj.other_uuid.must_match acceptable_uuid
  end

  it 'can find uuid pk via connection' do
    connection.primary_key(SSTestUuid.table_name).must_equal 'id'
  end

  it 'changing column default' do
    table_name = SSTestUuid.table_name
    connection.add_column table_name, :thingy, :uuid, null: false, default: "NEWSEQUENTIALID()"
    SSTestUuid.reset_column_information
    column = SSTestUuid.columns_hash['thingy']
    column.default_function.must_equal "newsequentialid()"
    # Now to a different function.
    connection.change_column table_name, :thingy, :uuid, null: false, default: "NEWID()"
    SSTestUuid.reset_column_information
    column = SSTestUuid.columns_hash['thingy']
    column.default_function.must_equal "newid()"
  end

  it 'can insert even when use_output_inserted to false ' do
    obj = with_use_output_inserted_disabled { SSTestUuid.create!(name: "😢") }
    obj.id.must_be :nil?
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-jdbcsqlserver-adapter-51.1.0 test/cases/uuid_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-50.1.0 test/cases/uuid_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.0.1 test/cases/uuid_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-51.0.0 test/cases/uuid_test_sqlserver.rb
activerecord-jdbcsqlserver-adapter-50.0.0 test/cases/uuid_test_sqlserver.rb