File tree Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ module Serialization
5
5
class ImplicitSerializerTest < ActionController ::TestCase
6
6
include ActiveSupport ::Testing ::Stream
7
7
class ImplicitSerializationTestController < ActionController ::Base
8
+ include SerializationTesting
8
9
def render_using_implicit_serializer
9
10
@profile = Profile . new ( name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' )
10
11
render json : @profile
@@ -123,21 +124,6 @@ def render_fragment_changed_object_with_relationship
123
124
124
125
render json : like
125
126
end
126
-
127
- private
128
-
129
- def generate_cached_serializer ( obj )
130
- ActiveModel ::SerializableResource . new ( obj ) . to_json
131
- end
132
-
133
- def with_adapter ( adapter )
134
- old_adapter = ActiveModel ::Serializer . config . adapter
135
- # JSON-API adapter sets root by default
136
- ActiveModel ::Serializer . config . adapter = adapter
137
- yield
138
- ensure
139
- ActiveModel ::Serializer . config . adapter = old_adapter
140
- end
141
127
end
142
128
143
129
tests ImplicitSerializationTestController
Original file line number Diff line number Diff line change 1
- class Minitest ::Test
2
- def before_setup
3
- ActionController ::Base . cache_store . clear
1
+ module SerializationTesting
2
+ private
3
+
4
+ def generate_cached_serializer ( obj )
5
+ ActiveModel ::SerializableResource . new ( obj ) . to_json
4
6
end
5
7
8
+ # Aliased as :with_configured_adapter to clarify that
9
+ # this method tests the configured adapter.
10
+ # When not testing configuration, it may be preferable
11
+ # to pass in the +adapter+ option to <tt>ActiveModel::SerializableResource</tt>.
12
+ # e.g ActiveModel::SerializableResource.new(resource, adapter: :json_api)
6
13
def with_adapter ( adapter )
7
14
old_adapter = ActiveModel ::Serializer . config . adapter
8
15
ActiveModel ::Serializer . config . adapter = adapter
9
16
yield
10
17
ensure
11
18
ActiveModel ::Serializer . config . adapter = old_adapter
12
19
end
20
+ alias_method :with_configured_adapter , :with_adapter
21
+ end
22
+
23
+ class Minitest ::Test
24
+ def before_setup
25
+ ActionController ::Base . cache_store . clear
26
+ end
27
+
28
+ include SerializationTesting
13
29
end
You can’t perform that action at this time.
0 commit comments