mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge branch '0-9-1' into 0-9-stable
This will bring back all features in 0.9.1 minus the problematic Enumerable commit that broke it.
This commit is contained in:
commit
69aff2a2e8
@ -87,7 +87,7 @@ module ActionController
|
|||||||
if serializer = options.fetch(:serializer, default_serializer(resource))
|
if serializer = options.fetch(:serializer, default_serializer(resource))
|
||||||
options[:scope] = serialization_scope unless options.has_key?(:scope)
|
options[:scope] = serialization_scope unless options.has_key?(:scope)
|
||||||
|
|
||||||
if resource.respond_to?(:each)
|
if resource.respond_to?(:to_ary)
|
||||||
options[:resource_name] = controller_name
|
options[:resource_name] = controller_name
|
||||||
options[:namespace] = namespace_for_serializer if namespace_for_serializer
|
options[:namespace] = namespace_for_serializer if namespace_for_serializer
|
||||||
end
|
end
|
||||||
|
|||||||
@ -56,7 +56,7 @@ end
|
|||||||
attr_reader :key_format
|
attr_reader :key_format
|
||||||
|
|
||||||
def serializer_for(resource, options = {})
|
def serializer_for(resource, options = {})
|
||||||
if resource.respond_to?(:each) && !resource.is_a?(Hash)
|
if resource.respond_to?(:to_ary)
|
||||||
if Object.constants.include?(:ArraySerializer)
|
if Object.constants.include?(:ArraySerializer)
|
||||||
::ArraySerializer
|
::ArraySerializer
|
||||||
else
|
else
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
VERSION = '0.9.1'
|
VERSION = '0.9.3'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
4
test/fixtures/poro.rb
vendored
4
test/fixtures/poro.rb
vendored
@ -100,10 +100,6 @@ class ProfileSerializer < ActiveModel::Serializer
|
|||||||
attributes :name, :description
|
attributes :name, :description
|
||||||
end
|
end
|
||||||
|
|
||||||
class DifferentProfileSerializer < ActiveModel::Serializer
|
|
||||||
attributes :name
|
|
||||||
end
|
|
||||||
|
|
||||||
class CategorySerializer < ActiveModel::Serializer
|
class CategorySerializer < ActiveModel::Serializer
|
||||||
attributes :name
|
attributes :name
|
||||||
|
|
||||||
|
|||||||
@ -283,21 +283,5 @@ module ActionController
|
|||||||
assert_equal("{\"my\":[{\"name\":\"Name 1\",\"email\":\"mail@server.com\",\"profile_id\":#{@controller.user.profile.object_id}}],\"profiles\":[{\"name\":\"N1\",\"description\":\"D1\"}]}", @response.body)
|
assert_equal("{\"my\":[{\"name\":\"Name 1\",\"email\":\"mail@server.com\",\"profile_id\":#{@controller.user.profile.object_id}}],\"profiles\":[{\"name\":\"N1\",\"description\":\"D1\"}]}", @response.body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ExplicitEachSerializerWithEnumarableObjectTest < ActionController::TestCase
|
|
||||||
class MyController < ActionController::Base
|
|
||||||
def render_array
|
|
||||||
render json: [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })].to_enum, each_serializer: DifferentProfileSerializer
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tests MyController
|
|
||||||
|
|
||||||
def test_render_array
|
|
||||||
get :render_array
|
|
||||||
assert_equal 'application/json', @response.content_type
|
|
||||||
assert_equal '{"my":[{"name":"Name 1"}]}', @response.body
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user