Sha256: 3e4a31da3b9a0abf24029add84f8634cf2d667a0e2c32b30bf497991dace4cc6
Contents?: true
Size: 1.29 KB
Versions: 6
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true require "cases/helper" class TypeTest < ActiveRecord::TestCase setup do @old_registry = ActiveRecord::Type.registry ActiveRecord::Type.registry = ActiveRecord::Type::AdapterSpecificRegistry.new end teardown do ActiveRecord::Type.registry = @old_registry end test "registering a new type" do type = Struct.new(:args) ActiveRecord::Type.register(:foo, type) assert_equal type.new(:arg), ActiveRecord::Type.lookup(:foo, :arg) end test "looking up a type for a specific adapter" do type = Struct.new(:args) pgtype = Struct.new(:args) ActiveRecord::Type.register(:foo, type, override: false) ActiveRecord::Type.register(:foo, pgtype, adapter: :postgresql) assert_equal type.new, ActiveRecord::Type.lookup(:foo, adapter: :sqlite) assert_equal pgtype.new, ActiveRecord::Type.lookup(:foo, adapter: :postgresql) end test "lookup defaults to the current adapter" do current_adapter = ActiveRecord::Base.connection.adapter_name.downcase.to_sym type = Struct.new(:args) adapter_type = Struct.new(:args) ActiveRecord::Type.register(:foo, type, override: false) ActiveRecord::Type.register(:foo, adapter_type, adapter: current_adapter) assert_equal adapter_type.new, ActiveRecord::Type.lookup(:foo) end end
Version data entries
6 entries across 6 versions & 2 rubygems