mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Serializer should be available wiithing adapter to inspect attributes and assotions
This commit is contained in:
parent
6cc4fa0258
commit
553c470e10
@ -5,8 +5,10 @@ module ActiveModel
|
|||||||
autoload :SimpleAdapter
|
autoload :SimpleAdapter
|
||||||
autoload :NullAdapter
|
autoload :NullAdapter
|
||||||
|
|
||||||
|
attr_reader :serializer
|
||||||
|
|
||||||
def initialize(serializer)
|
def initialize(serializer)
|
||||||
@attributes = serializer.attributes
|
@serializer = serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def serializable_hash(options = {})
|
def serializable_hash(options = {})
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module ActiveModel
|
|||||||
class Adapter
|
class Adapter
|
||||||
class SimpleAdapter < Adapter
|
class SimpleAdapter < Adapter
|
||||||
def to_json(options={})
|
def to_json(options={})
|
||||||
@attributes.each_with_object({}) do |(attr, value), h|
|
serializer.attributes.each_with_object({}) do |(attr, value), h|
|
||||||
h[attr] = value
|
h[attr] = value
|
||||||
end.to_json # FIXME: why does passing options here cause {}?
|
end.to_json # FIXME: why does passing options here cause {}?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,8 +5,8 @@ module ActiveModel
|
|||||||
class AdapterTest < Minitest::Test
|
class AdapterTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
profile = Profile.new
|
profile = Profile.new
|
||||||
serializer = ProfileSerializer.new(profile)
|
@serializer = ProfileSerializer.new(profile)
|
||||||
@adapter = ActiveModel::Serializer::Adapter.new(serializer)
|
@adapter = ActiveModel::Serializer::Adapter.new(@serializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_serializable_hash_is_abstract_method
|
def test_serializable_hash_is_abstract_method
|
||||||
@ -20,6 +20,10 @@ module ActiveModel
|
|||||||
@adapter.to_json(only: [:name])
|
@adapter.to_json(only: [:name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_serializer
|
||||||
|
assert_equal @serializer, @adapter.serializer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class AdapterForTest < Minitest::Test
|
class AdapterForTest < Minitest::Test
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user