mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 06:46: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)
|
def build_json_serializer(resource, options)
|
||||||
options = default_serializer_options.merge(options || {})
|
options = default_serializer_options.merge(options || {})
|
||||||
|
|
||||||
serializer =
|
serializer = options.delete(:serializer)
|
||||||
options.delete(:serializer) ||
|
serializer = ActiveModel::Serializer.serializer_for(resource) if serializer.nil?
|
||||||
ActiveModel::Serializer.serializer_for(resource)
|
|
||||||
|
|
||||||
return unless serializer
|
return unless serializer
|
||||||
|
|
||||||
|
|||||||
@ -146,10 +146,26 @@ module ActionController
|
|||||||
end
|
end
|
||||||
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 RailsSerializerTest < ActionController::TestCase
|
||||||
class MyController < ActionController::Base
|
class MyController < ActionController::Base
|
||||||
def render_using_rails_behavior
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,7 +174,7 @@ module ActionController
|
|||||||
def test_render_using_rails_behavior
|
def test_render_using_rails_behavior
|
||||||
get :render_using_rails_behavior
|
get :render_using_rails_behavior
|
||||||
assert_equal 'application/json', @response.content_type
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user