From 331d080a66fe90609f76a5d6b4e9b844186f78cf Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sun, 23 Oct 2016 09:19:54 +0300 Subject: [PATCH] Revert "Made ActiveRecord consistently use ActiveRecord::Type (not" This reverts commit 671eb742eec77b5c8281ac2a2e3976ef32a6e424. This is not a change we would like moving forward. --- activerecord/CHANGELOG.md | 4 ---- activerecord/lib/active_record/attribute_methods/query.rb | 2 +- activerecord/lib/active_record/type.rb | 4 ++-- activerecord/lib/active_record/type/helpers.rb | 5 ----- .../lib/active_record/type/internal/abstract_json.rb | 4 ++-- activerecord/lib/active_record/type/serialized.rb | 4 ++-- activerecord/lib/active_record/type/value.rb | 5 ----- activerecord/test/cases/serialized_attribute_test.rb | 4 ++-- 8 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 activerecord/lib/active_record/type/helpers.rb delete mode 100644 activerecord/lib/active_record/type/value.rb diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index cc7ba49c87..487195a2e0 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -19,10 +19,6 @@ *Edho Arief* -* 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 05f0e974b6..10498f4322 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 ActiveRecord::Type::Boolean::FALSE_VALUES.include?(value) + return false if ActiveModel::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 84373dddf2..0b48d2186a 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -1,6 +1,4 @@ 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" @@ -50,6 +48,7 @@ def current_adapter_name end end + Helpers = ActiveModel::Type::Helpers BigInteger = ActiveModel::Type::BigInteger Binary = ActiveModel::Type::Binary Boolean = ActiveModel::Type::Boolean @@ -60,6 +59,7 @@ 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 deleted file mode 100644 index a32ccd4bc3..0000000000 --- a/activerecord/lib/active_record/type/helpers.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 67028546e4..e19c5a14da 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 < Type::Value # :nodoc: - include Type::Helpers::Mutable + class AbstractJson < ActiveModel::Type::Value # :nodoc: + include ActiveModel::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 ca12c83b1a..ac9134bfcb 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(Type::Value) # :nodoc: - include Type::Helpers::Mutable + class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc: + include ActiveModel::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 deleted file mode 100644 index 89ef29106b..0000000000 --- a/activerecord/lib/active_record/type/value.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 8e9514de7c..bebd856faf 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(ActiveRecord::Type::Value) do - include ActiveRecord::Type::Helpers::Mutable + type = Class.new(ActiveModel::Type::Value) do + include ActiveModel::Type::Helpers::Mutable def serialize(value) return if value.nil? -- GitLab