mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Test for SimpleAdapter#serializable_hash
This commit is contained in:
parent
553c470e10
commit
7b7d4d8907
@ -2,10 +2,14 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
class Adapter
|
class Adapter
|
||||||
class SimpleAdapter < Adapter
|
class SimpleAdapter < Adapter
|
||||||
def to_json(options={})
|
def serializable_hash(options = {})
|
||||||
serializer.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
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_json(options={})
|
||||||
|
serializable_hash(options).to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,6 +11,10 @@ module ActiveModel
|
|||||||
@adapter = SimpleAdapter.new(@profile_serializer)
|
@adapter = SimpleAdapter.new(@profile_serializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_serializable_hash
|
||||||
|
assert_equal({name: 'Name 1', description: 'Description 1'}, @adapter.serializable_hash)
|
||||||
|
end
|
||||||
|
|
||||||
def test_simple_adapter
|
def test_simple_adapter
|
||||||
assert_equal('{"name":"Name 1","description":"Description 1"}',
|
assert_equal('{"name":"Name 1","description":"Description 1"}',
|
||||||
@adapter.to_json)
|
@adapter.to_json)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user