From 26277ea1f9581d5a6e84ef324afb7718da2750f0 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Wed, 16 Sep 2015 08:49:34 -0500 Subject: [PATCH] Remove duplicate test helper --- test/action_controller/serialization_test.rb | 16 +------------- test/support/serialization_testing.rb | 22 +++++++++++++++++--- 2 files changed, 20 insertions(+), 18 deletions(-) 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..e990ec27b 100644 --- a/test/support/serialization_testing.rb +++ b/test/support/serialization_testing.rb @@ -1,8 +1,15 @@ -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 + # Aliased as :with_configured_adapter to clarify that + # this method tests the configured adapter. + # When not testing configuration, it may be preferable + # to pass in the +adapter+ option to ActiveModel::SerializableResource. + # e.g ActiveModel::SerializableResource.new(resource, adapter: :json_api) def with_adapter(adapter) old_adapter = ActiveModel::Serializer.config.adapter ActiveModel::Serializer.config.adapter = adapter @@ -10,4 +17,13 @@ def with_adapter(adapter) 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