diff --git a/test/action_controller/serialization_test.rb b/test/action_controller/serialization_test.rb index 79d7c037b..0cffbdfcd 100644 --- a/test/action_controller/serialization_test.rb +++ b/test/action_controller/serialization_test.rb @@ -5,6 +5,7 @@ module Serialization class ImplicitSerializerTest < ActionController::TestCase include ActiveSupport::Testing::Stream class ImplicitSerializationTestController < ActionController::Base + include SerializationTesting def render_using_implicit_serializer @profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1') render json: @profile @@ -123,21 +124,6 @@ def render_fragment_changed_object_with_relationship render json: like end - - private - - def generate_cached_serializer(obj) - ActiveModel::SerializableResource.new(obj).to_json - end - - def with_adapter(adapter) - old_adapter = ActiveModel::Serializer.config.adapter - # JSON-API adapter sets root by default - ActiveModel::Serializer.config.adapter = adapter - yield - ensure - ActiveModel::Serializer.config.adapter = old_adapter - end end tests ImplicitSerializationTestController diff --git a/test/support/serialization_testing.rb b/test/support/serialization_testing.rb index 38fcdf5ef..7ccc37bed 100644 --- a/test/support/serialization_testing.rb +++ b/test/support/serialization_testing.rb @@ -1,13 +1,25 @@ -class Minitest::Test - def before_setup - ActionController::Base.cache_store.clear +module SerializationTesting + private + + def generate_cached_serializer(obj) + ActiveModel::SerializableResource.new(obj).to_json end def with_adapter(adapter) old_adapter = ActiveModel::Serializer.config.adapter + # JSON-API adapter sets root by default ActiveModel::Serializer.config.adapter = adapter yield ensure ActiveModel::Serializer.config.adapter = old_adapter end + alias_method :with_configured_adapter, :with_adapter +end + +class Minitest::Test + def before_setup + ActionController::Base.cache_store.clear + end + + include SerializationTesting end