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
55 class ImplicitSerializerTest < ActionController ::TestCase
66 include ActiveSupport ::Testing ::Stream
77 class ImplicitSerializationTestController < ActionController ::Base
8+ include SerializationTesting
89 def render_using_implicit_serializer
910 @profile = Profile . new ( name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' )
1011 render json : @profile
@@ -123,21 +124,6 @@ def render_fragment_changed_object_with_relationship
123124
124125 render json : like
125126 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
141127 end
142128
143129 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
46 end
57
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)
613 def with_adapter ( adapter )
714 old_adapter = ActiveModel ::Serializer . config . adapter
815 ActiveModel ::Serializer . config . adapter = adapter
916 yield
1017 ensure
1118 ActiveModel ::Serializer . config . adapter = old_adapter
1219 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
1329end
You can’t perform that action at this time.
0 commit comments