@@ -3,23 +3,29 @@ module ActiveModel
33 class Serializer
44 module Adapter
55 class DeprecationTest < ActiveSupport ::TestCase
6- class DeprecatedPostSerializer < ActiveModel ::Serializer
6+ class PostSerializer < ActiveModel ::Serializer
77 attribute :body
88 end
99 setup do
1010 post = Post . new ( id : 1 , body : 'Hello' )
11- @serializer = DeprecatedPostSerializer . new ( post )
11+ @serializer = PostSerializer . new ( post )
1212 end
1313
14- def test_null_adapter_serialization
15- assert_equal ( { } , Null . new ( @serializer ) . as_json )
14+ def test_null_adapter_serialization_deprecation
15+ expected = { }
16+ assert_deprecated do
17+ assert_equal ( expected , Null . new ( @serializer ) . as_json )
18+ end
1619 end
1720
18- def test_json_adapter_serialization
19- assert_equal ( { post : { body : 'Hello' } } , Json . new ( @serializer ) . as_json )
21+ def test_json_adapter_serialization_deprecation
22+ expected = { post : { body : 'Hello' } }
23+ assert_deprecated do
24+ assert_equal ( expected , Json . new ( @serializer ) . as_json )
25+ end
2026 end
2127
22- def test_jsonapi_adapter_serialization
28+ def test_jsonapi_adapter_serialization_deprecation
2329 expected = {
2430 data : {
2531 id : '1' ,
@@ -29,27 +35,16 @@ def test_jsonapi_adapter_serialization
2935 }
3036 }
3137 }
32- assert_equal ( expected , JsonApi . new ( @serializer ) . as_json )
33- end
34-
35- def test_attributes_adapter_serialization
36- assert_equal ( { body : 'Hello' } , Attributes . new ( @serializer ) . as_json )
37- end
38-
39- def test_null_adapter_deprecation
40- assert_deprecated_adapter ( Null )
41- end
42-
43- def test_json_adapter_deprecation
44- assert_deprecated_adapter ( Json )
45- end
46-
47- def test_json_api_adapter_deprecation
48- assert_deprecated_adapter ( JsonApi )
38+ assert_deprecated do
39+ assert_equal ( expected , JsonApi . new ( @serializer ) . as_json )
40+ end
4941 end
5042
51- def test_attributes_adapter_deprecation
52- assert_deprecated_adapter ( Attributes )
43+ def test_attributes_adapter_serialization_deprecation
44+ expected = { body : 'Hello' }
45+ assert_deprecated do
46+ assert_equal ( expected , Attributes . new ( @serializer ) . as_json )
47+ end
5348 end
5449
5550 def test_adapter_create_deprecation
@@ -78,8 +73,11 @@ def test_adapter_adapter_class_deprecation
7873
7974 def test_adapter_register_deprecation
8075 assert_deprecated do
81- Adapter . register ( :test , Class . new )
82- Adapter . adapter_map . delete ( 'test' )
76+ begin
77+ Adapter . register ( :test , Class . new )
78+ ensure
79+ Adapter . adapter_map . delete ( 'test' )
80+ end
8381 end
8482 end
8583
@@ -91,15 +89,8 @@ def test_adapter_lookup_deprecation
9189
9290 private
9391
94- def assert_deprecated_adapter ( adapter )
95- assert_deprecated do
96- adapter . new ( @serializer )
97- end
98- end
99-
10092 def assert_deprecated
101- message = /deprecated/
102- assert_output ( nil , message ) do
93+ assert_output ( nil , /deprecated/ ) do
10394 yield
10495 end
10596 end
0 commit comments