1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #26693 from iainbeeston/consistently-use-activerecord-attributes

Made ActiveRecord consistently use ActiveRecord::Type (not ActiveModel::Type)
This commit is contained in:
Andrew White 2016-10-04 10:02:34 +01:00 committed by GitHub
commit 0fc115724b
8 changed files with 23 additions and 9 deletions

View file

@ -1,3 +1,7 @@
* Made ActiveRecord consistently use `ActiveRecord::Type` (not `ActiveModel::Type`)
*Iain Beeston*
* Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
*Trung Duc Tran*

View file

@ -19,7 +19,7 @@ module ActiveRecord
if Numeric === value || value !~ /[^0-9]/
!value.to_i.zero?
else
return false if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
return false if ActiveRecord::Type::Boolean::FALSE_VALUES.include?(value)
!value.blank?
end
elsif value.respond_to?(:zero?)

View file

@ -1,4 +1,6 @@
require "active_model/type"
require "active_record/type/helpers"
require "active_record/type/value"
require "active_record/type/internal/abstract_json"
require "active_record/type/internal/timezone"
@ -48,7 +50,6 @@ module ActiveRecord
end
end
Helpers = ActiveModel::Type::Helpers
BigInteger = ActiveModel::Type::BigInteger
Binary = ActiveModel::Type::Binary
Boolean = ActiveModel::Type::Boolean
@ -59,7 +60,6 @@ module ActiveRecord
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)

View file

@ -0,0 +1,5 @@
module ActiveRecord
module Type
Helpers = ActiveModel::Type::Helpers
end
end

View file

@ -1,8 +1,8 @@
module ActiveRecord
module Type
module Internal # :nodoc:
class AbstractJson < ActiveModel::Type::Value # :nodoc:
include ActiveModel::Type::Helpers::Mutable
class AbstractJson < Type::Value # :nodoc:
include Type::Helpers::Mutable
def type
:json

View file

@ -1,7 +1,7 @@
module ActiveRecord
module Type
class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc:
include ActiveModel::Type::Helpers::Mutable
class Serialized < DelegateClass(Type::Value) # :nodoc:
include Type::Helpers::Mutable
attr_reader :subtype, :coder

View file

@ -0,0 +1,5 @@
module ActiveRecord
module Type
class Value < ActiveModel::Type::Value; end
end
end

View file

@ -313,8 +313,8 @@ class SerializedAttributeTest < ActiveRecord::TestCase
return if value.nil?
value.gsub(" encoded", "")
end
type = Class.new(ActiveModel::Type::Value) do
include ActiveModel::Type::Helpers::Mutable
type = Class.new(ActiveRecord::Type::Value) do
include ActiveRecord::Type::Helpers::Mutable
def serialize(value)
return if value.nil?