mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge branch 'master' of github.com:josevalim/active_model_serializers
This commit is contained in:
commit
1e777ced0e
@ -33,7 +33,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def serialization_scope
|
||||
send(_serialization_scope) if respond_to?(_serialization_scope)
|
||||
send(_serialization_scope) if _serialization_scope && respond_to?(_serialization_scope)
|
||||
end
|
||||
|
||||
def default_serializer_options
|
||||
|
||||
@ -53,9 +53,7 @@ module ActiveModel
|
||||
@options[:unique_values] = {}
|
||||
|
||||
array = serializable_array.map do |item|
|
||||
if item.is_a?(Hash)
|
||||
item
|
||||
elsif item.respond_to?(:serializable_hash)
|
||||
if item.respond_to?(:serializable_hash)
|
||||
item.serializable_hash
|
||||
else
|
||||
item.as_json
|
||||
|
||||
34
test/no_serialization_scope_test.rb
Normal file
34
test/no_serialization_scope_test.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require "test_helper"
|
||||
|
||||
class NoSerializationScopeTest < ActionController::TestCase
|
||||
class ScopeSerializer
|
||||
def initialize(object, options)
|
||||
@object, @options = object, options
|
||||
end
|
||||
|
||||
def as_json(*)
|
||||
{ :scope => @options[:scope].as_json }
|
||||
end
|
||||
end
|
||||
|
||||
class ScopeSerializable
|
||||
def active_model_serializer
|
||||
ScopeSerializer
|
||||
end
|
||||
end
|
||||
|
||||
class NoSerializationScopeController < ActionController::Base
|
||||
serialization_scope nil
|
||||
|
||||
def index
|
||||
render :json => ScopeSerializable.new
|
||||
end
|
||||
end
|
||||
|
||||
tests NoSerializationScopeController
|
||||
|
||||
def test_disabled_serialization_scope
|
||||
get :index
|
||||
assert_equal '{"scope":null}', @response.body
|
||||
end
|
||||
end
|
||||
@ -408,7 +408,7 @@ class SerializerTest < ActiveModel::TestCase
|
||||
hash = {:value => "something"}
|
||||
array = [hash]
|
||||
serializer = array.active_model_serializer.new(array, :root => :items)
|
||||
assert_equal({ :items => [ hash ]}, serializer.as_json)
|
||||
assert_equal({ :items => [ hash.as_json ]}, serializer.as_json)
|
||||
end
|
||||
|
||||
class CustomBlog < Blog
|
||||
|
||||
Loading…
Reference in New Issue
Block a user