2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2015-06-02 14:48:20 -04:00
|
|
|
|
|
|
|
class ParamsWrapperForApiTest < ActionController::TestCase
|
|
|
|
class UsersController < ActionController::API
|
|
|
|
attr_accessor :last_parameters
|
|
|
|
|
|
|
|
wrap_parameters :person, format: [:json]
|
|
|
|
|
|
|
|
def test
|
2015-07-13 16:43:21 -04:00
|
|
|
self.last_parameters = params.except(:controller, :action).to_unsafe_h
|
2015-06-02 14:48:20 -04:00
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Person; end
|
|
|
|
|
|
|
|
tests UsersController
|
|
|
|
|
|
|
|
def test_specify_wrapper_name
|
2016-08-06 12:54:50 -04:00
|
|
|
@request.env["CONTENT_TYPE"] = "application/json"
|
|
|
|
post :test, params: { "username" => "sikachu" }
|
2015-06-02 14:48:20 -04:00
|
|
|
|
2016-08-16 03:30:11 -04:00
|
|
|
expected = { "username" => "sikachu", "person" => { "username" => "sikachu" } }
|
2015-06-02 14:48:20 -04:00
|
|
|
assert_equal expected, @controller.last_parameters
|
|
|
|
end
|
|
|
|
end
|