Add NullAdapater

This commit is contained in:
Tema Bolshakov 2014-08-27 08:23:13 +04:00
parent f00fe5595d
commit 56725b45a6
4 changed files with 38 additions and 1 deletions

View File

@ -3,6 +3,7 @@ module ActiveModel
class Adapter
extend ActiveSupport::Autoload
autoload :SimpleAdapter
autoload :NullAdapter
def initialize(serializer)
@attributes = serializer.attributes

View File

@ -0,0 +1,15 @@
module ActiveModel
class Serializer
class Adapter
class NullAdapter < Adapter
def serializable_hash(options = {})
{}
end
def to_json(options = {})
serializable_hash.to_json
end
end
end
end
end

View File

@ -0,0 +1,21 @@
require 'test_helper'
module ActiveModel
class Serializer
class Adapter
class NullAdapterTest < Minitest::Test
def setup
profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
serializer = ProfileSerializer.new(profile)
@adapter = NullAdapter.new(serializer)
end
def test_it_returns_empty_json
assert_equal('{}', @adapter.to_json)
end
end
end
end
end

View File

@ -15,7 +15,7 @@ module ActiveModel
end
end
def test_serializable_hash_is_abstract_method
def test_to_json_is_abstract_method
assert_raises(NotImplementedError) do
@adapter.to_json(only: [:name])
end