diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-28 18:17:33 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-28 18:48:01 +0900 |
commit | 893c647da37189543b2c2d55b07d414b1ba8b0d0 (patch) | |
tree | 6342078c64e0ad4db69d4ccb77405bdf3ed89d73 /activerecord | |
parent | 50226c8fe0498713c89679713a407777ece16205 (diff) | |
download | rails-893c647da37189543b2c2d55b07d414b1ba8b0d0.tar.gz rails-893c647da37189543b2c2d55b07d414b1ba8b0d0.tar.bz2 rails-893c647da37189543b2c2d55b07d414b1ba8b0d0.zip |
Use dedicated `Topic` model for `SerializedAttributeTest`
This fixes both #34555 and #34738.
Revert "Merge pull request #34900 from gmcgibbon/fix_test_find_only_some_columns"
This reverts commit ff807f823b869d3491935a096183ee2bebd58e7b, reversing
changes made to 9f1a07af0499080c9fd8815705a03a4c7e8fb506.
Revert "Merge pull request #34560 from gmcgibbon/fix_decorate_leak_on_serial_attr_test"
This reverts commit bd62389307e138ee0f274a9d62697567a3334ea0, reversing
changes made to ec66c6a2fa4ee200259341a18ecd96310f388ba3.
Revert "Fix unstable `test_serialized_attribute_works_under_concurrent_initial_access` test"
This reverts commit 65c4b1b50df3fa59198de2d45d1f54b61ecc7864.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/serialized_attribute_test.rb | 34 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 4 |
2 files changed, 14 insertions, 24 deletions
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index fa136fe8da..edcca59ccc 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -2,27 +2,30 @@ require "cases/helper" 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 :posts MyObject = Struct.new :attribute1, :attribute2 - # NOTE: Use a duplicate of Topic so attribute - # changes don't bleed into other tests - Topic = ::Topic.dup + class Topic < ActiveRecord::Base + serialize :content + end + + class ImportantTopic < Topic + serialize :important, Hash + end teardown do Topic.serialize("content") end def test_serialize_does_not_eagerly_load_columns - reset_column_information_of(Topic) + Topic.reset_column_information assert_no_queries do Topic.serialize(:content) end @@ -53,10 +56,10 @@ class SerializedAttributeTest < ActiveRecord::TestCase def test_serialized_attributes_from_database_on_subclass Topic.serialize :content, Hash - t = Reply.new(content: { foo: :bar }) + t = ImportantTopic.new(content: { foo: :bar }) assert_equal({ foo: :bar }, t.content) t.save! - t = Reply.last + t = ImportantTopic.last assert_equal({ foo: :bar }, t.content) end @@ -371,14 +374,13 @@ class SerializedAttributeTest < ActiveRecord::TestCase end def test_serialized_attribute_works_under_concurrent_initial_access - model = ::Topic.dup + model = Topic.dup - topic = model.last + topic = model.create! topic.update group: "1" model.serialize :group, JSON - - reset_column_information_of(model) + model.reset_column_information # This isn't strictly necessary for the test, but a little bit of # knowledge of internals allows us to make failures far more likely. @@ -398,12 +400,4 @@ class SerializedAttributeTest < ActiveRecord::TestCase # raw string ("1"), or raise an exception. assert_equal [1] * threads.size, threads.map(&:value) end - - private - - def reset_column_information_of(topic_class) - topic_class.reset_column_information - # reset original topic to undefine attribute methods - ::Topic.reset_column_information - end end diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 0c8880a20e..77101090f2 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -119,10 +119,6 @@ class Topic < ActiveRecord::Base end end -class ImportantTopic < Topic - serialize :important, Hash -end - class DefaultRejectedTopic < Topic default_scope -> { where(approved: false) } end |