File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class Railtie < ::Rails::Railtie
23
23
initializer 'jsonapi-rails.init' do |app |
24
24
register_mime_type
25
25
register_parameter_parser
26
+ register_encoder
26
27
register_renderers
27
28
ActiveSupport . on_load ( :action_controller ) do
28
29
require 'jsonapi/rails/controller'
@@ -42,6 +43,14 @@ def register_parameter_parser
42
43
ActionDispatch ::Request . parameter_parsers [ :jsonapi ] = PARSER
43
44
end
44
45
46
+ def register_encoder
47
+ ActiveSupport . on_load ( :action_dispatch_integration_test ) do
48
+ register_encoder :jsonapi ,
49
+ param_encoder : -> ( params ) { params . to_json } ,
50
+ response_parser : -> ( body ) { JSON . parse ( body ) }
51
+ end
52
+ end
53
+
45
54
# rubocop:disable Metrics/MethodLength
46
55
def register_renderers
47
56
ActiveSupport . on_load ( :action_controller ) do
Original file line number Diff line number Diff line change
1
+ require 'rails_helper'
2
+
3
+ describe ActionController ::Base , type : :controller , if : Rails . version >= '6.0' do
4
+ controller do
5
+ def index
6
+ render jsonapi : nil
7
+ end
8
+ end
9
+
10
+ subject ( :parsed_body ) { response . parsed_body }
11
+
12
+ it 'allows using parsed_body in ActionController::TestCase' do
13
+ get :index
14
+
15
+ expect ( parsed_body ) . to eq ( JSON . parse ( response . body ) )
16
+ end
17
+ end
You can’t perform that action at this time.
0 commit comments