mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 06:46:50 +00:00
Merge pull request #1161 from bf4/remove_duplicate_test_helper
Remove duplicate test helper
This commit is contained in:
commit
a60e1ea82e
@ -5,6 +5,7 @@ module ActionController
|
|||||||
class ImplicitSerializerTest < ActionController::TestCase
|
class ImplicitSerializerTest < ActionController::TestCase
|
||||||
include ActiveSupport::Testing::Stream
|
include ActiveSupport::Testing::Stream
|
||||||
class ImplicitSerializationTestController < ActionController::Base
|
class ImplicitSerializationTestController < ActionController::Base
|
||||||
|
include SerializationTesting
|
||||||
def render_using_implicit_serializer
|
def render_using_implicit_serializer
|
||||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
@profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||||
render json: @profile
|
render json: @profile
|
||||||
@ -123,21 +124,6 @@ module ActionController
|
|||||||
|
|
||||||
render json: like
|
render json: like
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
tests ImplicitSerializationTestController
|
tests ImplicitSerializationTestController
|
||||||
|
|||||||
@ -1,8 +1,15 @@
|
|||||||
class Minitest::Test
|
module SerializationTesting
|
||||||
def before_setup
|
private
|
||||||
ActionController::Base.cache_store.clear
|
|
||||||
|
def generate_cached_serializer(obj)
|
||||||
|
ActiveModel::SerializableResource.new(obj).to_json
|
||||||
end
|
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 <tt>ActiveModel::SerializableResource</tt>.
|
||||||
|
# e.g ActiveModel::SerializableResource.new(resource, adapter: :json_api)
|
||||||
def with_adapter(adapter)
|
def with_adapter(adapter)
|
||||||
old_adapter = ActiveModel::Serializer.config.adapter
|
old_adapter = ActiveModel::Serializer.config.adapter
|
||||||
ActiveModel::Serializer.config.adapter = adapter
|
ActiveModel::Serializer.config.adapter = adapter
|
||||||
@ -10,4 +17,13 @@ class Minitest::Test
|
|||||||
ensure
|
ensure
|
||||||
ActiveModel::Serializer.config.adapter = old_adapter
|
ActiveModel::Serializer.config.adapter = old_adapter
|
||||||
end
|
end
|
||||||
|
alias_method :with_configured_adapter, :with_adapter
|
||||||
|
end
|
||||||
|
|
||||||
|
class Minitest::Test
|
||||||
|
def before_setup
|
||||||
|
ActionController::Base.cache_store.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
include SerializationTesting
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user