diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 4d0c1a4178f4e6e9ff30683f9a8d6f55e477e38c..879c4a87cf801a3d53cccce428bd72bb0e7c8cb1 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -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* diff --git a/activerecord/lib/active_record/attribute_methods/query.rb b/activerecord/lib/active_record/attribute_methods/query.rb index 10498f43226a55b08b3788eefaca9359539dd5ea..05f0e974b6bda0291cddabdcb3cb0611f93c132d 100644 --- a/activerecord/lib/active_record/attribute_methods/query.rb +++ b/activerecord/lib/active_record/attribute_methods/query.rb @@ -19,7 +19,7 @@ def query_attribute(attr_name) 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?) diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 0b48d2186aa27b27d273893b6d2d19bfd79ec8b9..84373dddf26a70893248c273c55dc7a1450963a4 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -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 @@ def current_adapter_name end end - Helpers = ActiveModel::Type::Helpers BigInteger = ActiveModel::Type::BigInteger Binary = ActiveModel::Type::Binary Boolean = ActiveModel::Type::Boolean @@ -59,7 +60,6 @@ def current_adapter_name 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) diff --git a/activerecord/lib/active_record/type/helpers.rb b/activerecord/lib/active_record/type/helpers.rb new file mode 100644 index 0000000000000000000000000000000000000000..a32ccd4bc328ca641f8c8a3656df2fc161a7a823 --- /dev/null +++ b/activerecord/lib/active_record/type/helpers.rb @@ -0,0 +1,5 @@ +module ActiveRecord + module Type + Helpers = ActiveModel::Type::Helpers + end +end diff --git a/activerecord/lib/active_record/type/internal/abstract_json.rb b/activerecord/lib/active_record/type/internal/abstract_json.rb index e19c5a14da8ea86eaac3aec4e97de0417b75fbeb..67028546e4258c305b775d9afd9f81d9f09a011f 100644 --- a/activerecord/lib/active_record/type/internal/abstract_json.rb +++ b/activerecord/lib/active_record/type/internal/abstract_json.rb @@ -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 diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index ac9134bfcb89c90d0cd6f7c8ebcde055cc44d9f3..ca12c83b1aa681914545206cf25082e9a3321dc3 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -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 diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb new file mode 100644 index 0000000000000000000000000000000000000000..89ef29106b968bce4cb43c917621d8f47b5eae42 --- /dev/null +++ b/activerecord/lib/active_record/type/value.rb @@ -0,0 +1,5 @@ +module ActiveRecord + module Type + class Value < ActiveModel::Type::Value; end + end +end diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index bebd856faf5f6ef11dca561d60bd2224d915cd2e..8e9514de7c7bb11be66d8f86c6ba97d57a07048d 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -313,8 +313,8 @@ def coder.load(value) 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?