aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md41
-rw-r--r--activerecord/lib/active_record.rb1
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb7
-rw-r--r--activerecord/lib/active_record/coders/json.rb13
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb16
5 files changed, 2 insertions, 76 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index c61407b927..21075d0636 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,44 +1,3 @@
-* Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
-
- With 4.1.x, `serialize` started returning a string when `JSON` was passed as
- the second attribute. It will now return a hash as per previous versions.
-
- Example:
-
- class Post < ActiveRecord::Base
- serialize :comment, JSON
- end
-
- class Comment
- include ActiveModel::Model
- attr_accessor :category, :text
- end
-
- post = Post.create!
- post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
- post.save!
-
- # 4.0
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
-
- # 4.1 before
- post.comment # => "#<Comment:0x007f80ab48ff98>"
-
- # 4.1 after
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
-
- When using `JSON` as the coder in `serialize`, Active Record will use the
- new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
- `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
- correctly using the `#as_json` hook.
-
- To keep the previous behaviour, supply a custom coder instead
- ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
-
- Fixes #15594.
-
- *Jenn Cooper*
-
* Add a `:required` option to singular associations, providing a nicer
API for presence validations on associations.
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 9028970a3d..17b00bbaea 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -97,7 +97,6 @@ module ActiveRecord
module Coders
autoload :YAMLColumn, 'active_record/coders/yaml_column'
- autoload :JSON, 'active_record/coders/json'
end
module AttributeMethods
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index 264ce2bdfa..734d94865a 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -37,12 +37,7 @@ module ActiveRecord
# serialize :preferences, Hash
# end
def serialize(attr_name, class_name_or_coder = Object)
- # When ::JSON is used, force it to go through the Active Support JSON encoder
- # to ensure special objects (e.g. Active Record models) are dumped correctly
- # using the #as_json hook.
- coder = if class_name_or_coder == ::JSON
- Coders::JSON
- elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
+ coder = if [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
class_name_or_coder
else
Coders::YAMLColumn.new(class_name_or_coder)
diff --git a/activerecord/lib/active_record/coders/json.rb b/activerecord/lib/active_record/coders/json.rb
deleted file mode 100644
index 0f60b6dab2..0000000000
--- a/activerecord/lib/active_record/coders/json.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module ActiveRecord
- module Coders # :nodoc:
- class JSON # :nodoc:
- def self.dump(obj)
- ActiveSupport::JSON.encode(obj)
- end
-
- def self.load(json)
- ActiveSupport::JSON.decode(json)
- end
- end
- end
-end
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb
index a8f667c732..186a1a2ade 100644
--- a/activerecord/test/cases/serialized_attribute_test.rb
+++ b/activerecord/test/cases/serialized_attribute_test.rb
@@ -3,11 +3,10 @@ require 'models/topic'
require 'models/reply'
require 'models/person'
require 'models/traffic_light'
-require 'models/post'
require 'bcrypt'
class SerializedAttributeTest < ActiveRecord::TestCase
- fixtures :topics, :posts
+ fixtures :topics
MyObject = Struct.new :attribute1, :attribute2
@@ -68,19 +67,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
assert_equal(orig.content, clone.content)
end
- def test_serialized_json_attribute_returns_unserialized_value
- Topic.serialize :content, JSON
- my_post = posts(:welcome)
-
- t = Topic.new(content: my_post)
- t.save!
- t.reload
-
- assert_instance_of(Hash, t.content)
- assert_equal(my_post.id, t.content["id"])
- assert_equal(my_post.title, t.content["title"])
- end
-
def test_serialized_attribute_declared_in_subclass
hash = { 'important1' => 'value1', 'important2' => 'value2' }
important_topic = ImportantTopic.create("important" => hash)