mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Clean up test deprecation warnings
This commit is contained in:
parent
5d7a1a4889
commit
6b4c8df6fb
@ -19,6 +19,7 @@ require 'active_model/serializer/type'
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
|
autoload :Adapter
|
||||||
include Configuration
|
include Configuration
|
||||||
include Associations
|
include Associations
|
||||||
include Attributes
|
include Attributes
|
||||||
@ -26,7 +27,6 @@ module ActiveModel
|
|||||||
include Links
|
include Links
|
||||||
include Meta
|
include Meta
|
||||||
include Type
|
include Type
|
||||||
autoload :Adapter
|
|
||||||
|
|
||||||
# @param resource [ActiveRecord::Base, ActiveModelSerializers::Model]
|
# @param resource [ActiveRecord::Base, ActiveModelSerializers::Model]
|
||||||
# @return [ActiveModel::Serializer]
|
# @return [ActiveModel::Serializer]
|
||||||
|
|||||||
@ -3,23 +3,29 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
class DeprecationTest < ActiveSupport::TestCase
|
class DeprecationTest < ActiveSupport::TestCase
|
||||||
class DeprecatedPostSerializer < ActiveModel::Serializer
|
class PostSerializer < ActiveModel::Serializer
|
||||||
attribute :body
|
attribute :body
|
||||||
end
|
end
|
||||||
setup do
|
setup do
|
||||||
post = Post.new(id: 1, body: 'Hello')
|
post = Post.new(id: 1, body: 'Hello')
|
||||||
@serializer = DeprecatedPostSerializer.new(post)
|
@serializer = PostSerializer.new(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_null_adapter_serialization
|
def test_null_adapter_serialization_deprecation
|
||||||
assert_equal({}, Null.new(@serializer).as_json)
|
expected = {}
|
||||||
|
assert_deprecated do
|
||||||
|
assert_equal(expected, Null.new(@serializer).as_json)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_json_adapter_serialization
|
def test_json_adapter_serialization_deprecation
|
||||||
assert_equal({ post: { body: 'Hello' } }, Json.new(@serializer).as_json)
|
expected = { post: { body: 'Hello' } }
|
||||||
|
assert_deprecated do
|
||||||
|
assert_equal(expected, Json.new(@serializer).as_json)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_jsonapi_adapter_serialization
|
def test_jsonapi_adapter_serialization_deprecation
|
||||||
expected = {
|
expected = {
|
||||||
data: {
|
data: {
|
||||||
id: '1',
|
id: '1',
|
||||||
@ -29,27 +35,16 @@ module ActiveModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert_deprecated do
|
||||||
assert_equal(expected, JsonApi.new(@serializer).as_json)
|
assert_equal(expected, JsonApi.new(@serializer).as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_attributes_adapter_serialization
|
|
||||||
assert_equal({ body: 'Hello' }, Attributes.new(@serializer).as_json)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_null_adapter_deprecation
|
def test_attributes_adapter_serialization_deprecation
|
||||||
assert_deprecated_adapter(Null)
|
expected = { body: 'Hello' }
|
||||||
|
assert_deprecated do
|
||||||
|
assert_equal(expected, Attributes.new(@serializer).as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_json_adapter_deprecation
|
|
||||||
assert_deprecated_adapter(Json)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_json_api_adapter_deprecation
|
|
||||||
assert_deprecated_adapter(JsonApi)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_attributes_adapter_deprecation
|
|
||||||
assert_deprecated_adapter(Attributes)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_adapter_create_deprecation
|
def test_adapter_create_deprecation
|
||||||
@ -78,10 +73,13 @@ module ActiveModel
|
|||||||
|
|
||||||
def test_adapter_register_deprecation
|
def test_adapter_register_deprecation
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
|
begin
|
||||||
Adapter.register(:test, Class.new)
|
Adapter.register(:test, Class.new)
|
||||||
|
ensure
|
||||||
Adapter.adapter_map.delete('test')
|
Adapter.adapter_map.delete('test')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_adapter_lookup_deprecation
|
def test_adapter_lookup_deprecation
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
@ -91,15 +89,8 @@ module ActiveModel
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_deprecated_adapter(adapter)
|
|
||||||
assert_deprecated do
|
|
||||||
adapter.new(@serializer)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_deprecated
|
def assert_deprecated
|
||||||
message = /deprecated/
|
assert_output(nil, /deprecated/) do
|
||||||
assert_output(nil, message) do
|
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user