mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Make it possible to supply default serializer
options in a controller.
This commit is contained in:
@@ -22,6 +22,7 @@ class RenderJsonTest < ActionController::TestCase
|
||||
def as_json(*)
|
||||
hash = { :object => serializable_hash, :scope => @options[:scope].as_json }
|
||||
hash.merge!(:options => true) if @options[:options]
|
||||
hash.merge!(:check_defaults => true) if @options[:check_defaults]
|
||||
hash
|
||||
end
|
||||
|
||||
@@ -109,6 +110,13 @@ class RenderJsonTest < ActionController::TestCase
|
||||
@current_user = Struct.new(:as_json).new(:current_user => true)
|
||||
render :json => JsonSerializable.new(true)
|
||||
end
|
||||
|
||||
private
|
||||
def default_serializer_options
|
||||
if params[:check_defaults]
|
||||
{ :check_defaults => true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests TestController
|
||||
@@ -133,7 +141,6 @@ class RenderJsonTest < ActionController::TestCase
|
||||
assert_equal '[]', @response.body
|
||||
end
|
||||
|
||||
|
||||
def test_render_json
|
||||
get :render_json_hello_world
|
||||
assert_equal '{"hello":"world"}', @response.body
|
||||
@@ -181,6 +188,13 @@ class RenderJsonTest < ActionController::TestCase
|
||||
assert_match '"object":{"serializable_object":true}', @response.body
|
||||
end
|
||||
|
||||
def test_render_json_with_serializer
|
||||
get :render_json_with_serializer, :check_defaults => true
|
||||
assert_match '"scope":{"current_user":true}', @response.body
|
||||
assert_match '"object":{"serializable_object":true}', @response.body
|
||||
assert_match '"check_defaults":true', @response.body
|
||||
end
|
||||
|
||||
def test_render_json_with_serializer_and_implicit_root
|
||||
get :render_json_with_serializer_and_implicit_root
|
||||
assert_match '"test":[{"serializable_object":true}]', @response.body
|
||||
|
||||
Reference in New Issue
Block a user