mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Allow to turn off ams
Closes #378 You can define now ``` def default_serializer_options { serializer: false } end ```
This commit is contained in:
parent
78e13d66ea
commit
df5ef33ae6
@ -64,9 +64,8 @@ module ActionController
|
||||
def build_json_serializer(resource, options)
|
||||
options = default_serializer_options.merge(options || {})
|
||||
|
||||
serializer =
|
||||
options.delete(:serializer) ||
|
||||
ActiveModel::Serializer.serializer_for(resource)
|
||||
serializer = options.delete(:serializer)
|
||||
serializer = ActiveModel::Serializer.serializer_for(resource) if serializer.nil?
|
||||
|
||||
return unless serializer
|
||||
|
||||
|
||||
@ -146,10 +146,26 @@ module ActionController
|
||||
end
|
||||
end
|
||||
|
||||
class JSONDumpSerializerTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
def render_using_json_dump
|
||||
render json: JSON.dump(hello: 'world')
|
||||
end
|
||||
end
|
||||
|
||||
tests MyController
|
||||
|
||||
def test_render_using_json_dump
|
||||
get :render_using_json_dump
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal '{"hello":"world"}', @response.body
|
||||
end
|
||||
end
|
||||
|
||||
class RailsSerializerTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
def render_using_rails_behavior
|
||||
render json: JSON.dump(hello: 'world')
|
||||
render json: [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })], serializer: false
|
||||
end
|
||||
end
|
||||
|
||||
@ -158,7 +174,7 @@ module ActionController
|
||||
def test_render_using_rails_behavior
|
||||
get :render_using_rails_behavior
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal '{"hello":"world"}', @response.body
|
||||
assert_equal '[{"attributes":{"name":"Name 1","description":"Description 1","comments":"Comments 1"}}]', @response.body
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user