提交 ef76f83f 编写于 作者: S Sean Griffin

Merge pull request #26696 from iainbeeston/only-ruby-types-in-activemodel

Moved database-specific ActiveModel types into ActiveRecord
* Moved DecimalWithoutScale, Text, and UnsignedInteger from Active Model to Active Record
*Iain Beeston*
* Allow indifferent access in `ActiveModel::Errors`.
`#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
......
......@@ -7,14 +7,11 @@
require "active_model/type/date"
require "active_model/type/date_time"
require "active_model/type/decimal"
require "active_model/type/decimal_without_scale"
require "active_model/type/float"
require "active_model/type/immutable_string"
require "active_model/type/integer"
require "active_model/type/string"
require "active_model/type/text"
require "active_model/type/time"
require "active_model/type/unsigned_integer"
require "active_model/type/registry"
......@@ -53,7 +50,6 @@ def lookup(*args, **kwargs) # :nodoc:
register(:immutable_string, Type::ImmutableString)
register(:integer, Type::Integer)
register(:string, Type::String)
register(:text, Type::Text)
register(:time, Type::Time)
end
end
* Moved DecimalWithoutScale, Text, and UnsignedInteger from Active Model to Active Record
*Iain Beeston*
* Fix `write_attribute` method to check whether an attribute is aliased or not, and
use the aliased attribute name if needed.
......
......@@ -5,7 +5,10 @@
require "active_record/type/date"
require "active_record/type/date_time"
require "active_record/type/decimal_without_scale"
require "active_record/type/time"
require "active_record/type/text"
require "active_record/type/unsigned_integer"
require "active_record/type/serialized"
require "active_record/type/adapter_specific_registry"
......@@ -53,13 +56,9 @@ def current_adapter_name
Binary = ActiveModel::Type::Binary
Boolean = ActiveModel::Type::Boolean
Decimal = ActiveModel::Type::Decimal
DecimalWithoutScale = ActiveModel::Type::DecimalWithoutScale
Float = ActiveModel::Type::Float
Integer = ActiveModel::Type::Integer
String = ActiveModel::Type::String
Text = ActiveModel::Type::Text
UnsignedInteger = ActiveModel::Type::UnsignedInteger
Value = ActiveModel::Type::Value
register(:big_integer, Type::BigInteger, override: false)
register(:binary, Type::Binary, override: false)
......
require "active_model/type/big_integer"
module ActiveModel
module ActiveRecord
module Type
class DecimalWithoutScale < BigInteger # :nodoc:
class DecimalWithoutScale < ActiveModel::Type::BigInteger # :nodoc:
def type
:decimal
end
......
require "active_model/type/string"
module ActiveModel
module ActiveRecord
module Type
class Text < String # :nodoc:
class Text < ActiveModel::Type::String # :nodoc:
def type
:text
end
......
module ActiveModel
module ActiveRecord
module Type
class UnsignedInteger < Integer # :nodoc:
class UnsignedInteger < ActiveModel::Type::Integer # :nodoc:
private
def max_value
......
require "cases/helper"
require "active_model/type"
module ActiveModel
module ActiveRecord
module Type
class UnsignedIntegerTest < ActiveModel::TestCase
class UnsignedIntegerTest < ActiveRecord::TestCase
test "unsigned int max value is in range" do
assert_equal(4294967295, UnsignedInteger.new.serialize(4294967295))
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册