mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41166 from kamipo/raise_unknown_type_error_on_definition_time
Raise unknown type error on the definition time
This commit is contained in:
commit
ddaceddeab
7 changed files with 18 additions and 12 deletions
|
@ -142,5 +142,11 @@ module ActiveModel
|
|||
data.freeze
|
||||
assert_nothing_raised { data.freeze }
|
||||
end
|
||||
|
||||
test "unknown type error is raised" do
|
||||
assert_raise(ArgumentError) do
|
||||
ModelForAttributesTest.attribute :foo, :unknown
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -214,8 +214,7 @@ module ActiveRecord
|
|||
|
||||
case cast_type
|
||||
when Symbol
|
||||
type = cast_type
|
||||
cast_type = -> _ { Type.lookup(type, **options, adapter: Type.adapter_name_from(self)) }
|
||||
cast_type = Type.lookup(cast_type, **options, adapter: Type.adapter_name_from(self))
|
||||
when nil
|
||||
if (prev_cast_type, prev_default = attributes_to_define_after_schema_loads[name])
|
||||
default = prev_default if default == NO_DEFAULT_PROVIDED
|
||||
|
|
|
@ -7,7 +7,7 @@ class PostgresqlTime < ActiveRecord::Base
|
|||
# Declare attributes to get rid from deprecation warnings on ActiveRecord 6.1
|
||||
attribute :time_interval, :string
|
||||
attribute :scaled_time_interval, :interval
|
||||
end
|
||||
end if current_adapter?(:PostgreSQLAdapter)
|
||||
|
||||
class PostgresqlOid < ActiveRecord::Base
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ class PostgresqlPointTest < ActiveRecord::PostgreSQLTestCase
|
|||
attribute :legacy_x, :legacy_point
|
||||
attribute :legacy_y, :legacy_point
|
||||
attribute :legacy_z, :legacy_point
|
||||
end
|
||||
end if current_adapter?(:PostgreSQLAdapter)
|
||||
|
||||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
|
|
|
@ -12,7 +12,7 @@ class PostgresqlIntervalTest < ActiveRecord::PostgreSQLTestCase
|
|||
attribute :default_term, :interval
|
||||
attribute :all_terms, :interval, array: true
|
||||
attribute :legacy_term, :string
|
||||
end
|
||||
end if current_adapter?(:PostgreSQLAdapter)
|
||||
|
||||
class DeprecatedIntervalDataType < ActiveRecord::Base; end
|
||||
|
||||
|
|
|
@ -348,6 +348,12 @@ module ActiveRecord
|
|||
assert_equal "foo", klass.new(no_type: "foo").no_type
|
||||
end
|
||||
|
||||
test "unknown type error is raised" do
|
||||
assert_raise(ArgumentError) do
|
||||
OverloadedType.attribute :foo, :unknown
|
||||
end
|
||||
end
|
||||
|
||||
test "immutable_strings_by_default changes schema inference for string columns" do
|
||||
with_immutable_strings do
|
||||
OverloadedType.reset_column_information
|
||||
|
|
|
@ -597,17 +597,10 @@ end
|
|||
|
||||
class InheritanceAttributeMappingTest < ActiveRecord::TestCase
|
||||
setup do
|
||||
@old_registry = ActiveRecord::Type.registry
|
||||
ActiveRecord::Type.registry = ActiveRecord::Type.registry.dup
|
||||
ActiveRecord::Type.register :omg_sti, InheritanceAttributeMappingTest::OmgStiType
|
||||
Company.delete_all
|
||||
Sponsor.delete_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
ActiveRecord::Type.registry = @old_registry
|
||||
end
|
||||
|
||||
class OmgStiType < ActiveRecord::Type::String
|
||||
def cast_value(value)
|
||||
if value =~ /\Aomg_(.+)\z/
|
||||
|
@ -624,6 +617,8 @@ class InheritanceAttributeMappingTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Type.register :omg_sti, OmgStiType
|
||||
|
||||
class Company < ActiveRecord::Base
|
||||
self.table_name = "companies"
|
||||
attribute :type, :omg_sti
|
||||
|
|
Loading…
Reference in a new issue