File tree 4 files changed +33
-7
lines changed
lib/rails/generators/rails/app/templates/config/initializers 4 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -128,7 +128,11 @@ def self.without_modules(*modules)
128
128
129
129
# Add instrumentations hooks at the bottom, to ensure they instrument
130
130
# all the methods properly.
131
- Instrumentation
131
+ Instrumentation ,
132
+
133
+ # Params wrapper should come before instrumentation so they are
134
+ # properly showed in logs
135
+ ParamsWrapper
132
136
]
133
137
134
138
MODULES . each do |mod |
Original file line number Diff line number Diff line change
1
+ require 'abstract_unit'
2
+
3
+ class ParamsWrapperForApiTest < ActionController ::TestCase
4
+ class UsersController < ActionController ::API
5
+ attr_accessor :last_parameters
6
+
7
+ wrap_parameters :person , format : [ :json ]
8
+
9
+ def test
10
+ self . last_parameters = params . except ( :controller , :action )
11
+ head :ok
12
+ end
13
+ end
14
+
15
+ class Person ; end
16
+
17
+ tests UsersController
18
+
19
+ def test_specify_wrapper_name
20
+ @request . env [ 'CONTENT_TYPE' ] = 'application/json'
21
+ post :test , params : { 'username' => 'sikachu' }
22
+
23
+ expected = { 'username' => 'sikachu' , 'person' => { 'username' => 'sikachu' } }
24
+ assert_equal expected , @controller . last_parameters
25
+ end
26
+ end
Original file line number Diff line number Diff line change 1
1
# Be sure to restart your server when you modify this file.
2
2
3
- <%- unless options[:api] -%>
4
3
# This file contains settings for ActionController::ParamsWrapper which
5
4
# is enabled by default.
6
5
7
6
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
8
7
ActiveSupport.on_load(:action_controller) do
9
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
8
+ wrap_parameters format: [:json]
10
9
end
11
- <%- end -%>
12
10
<%- unless options.skip_active_record? -%>
13
11
14
12
# To enable root element in JSON for ActiveRecord objects.
Original file line number Diff line number Diff line change @@ -47,9 +47,7 @@ def test_api_modified_files
47
47
48
48
assert_file "config/initializers/cors.rb"
49
49
50
- assert_file "config/initializers/wrap_parameters.rb" do |content |
51
- assert_no_match ( /wrap_parameters/ , content )
52
- end
50
+ assert_file "config/initializers/wrap_parameters.rb"
53
51
54
52
assert_file "app/controllers/application_controller.rb" , /ActionController::API/
55
53
end
You can’t perform that action at this time.
0 commit comments