Rename FlattenJson to Attributes (allow plural adapter names)

This commit is contained in:
Benjamin Fleischer
2015-09-04 04:22:10 -05:00
parent ceef214f1e
commit c6f8d0f5f2
15 changed files with 36 additions and 35 deletions

View File

@@ -21,7 +21,7 @@ module ActiveModel
def test_create_adapter
adapter = ActiveModel::Serializer::Adapter.create(@serializer)
assert_equal ActiveModel::Serializer::Adapter::FlattenJson, adapter.class
assert_equal ActiveModel::Serializer::Adapter::Attributes, adapter.class
end
def test_create_adapter_with_override

View File

@@ -7,7 +7,7 @@ module ActiveModel
@previous_adapter = ActiveModel::Serializer.config.adapter
# Eager load adapters
ActiveModel::Serializer::Adapter.eager_load!
[:json_api, :flatten_json, :null, :json].each do |adapter_name|
[:json_api, :attributes, :null, :json].each do |adapter_name|
ActiveModel::Serializer::Adapter.lookup(adapter_name)
end
end
@@ -18,7 +18,7 @@ module ActiveModel
def test_returns_default_adapter
adapter = ActiveModel::Serializer.adapter
assert_equal ActiveModel::Serializer::Adapter::FlattenJson, adapter
assert_equal ActiveModel::Serializer::Adapter::Attributes, adapter
end
def test_overwrite_adapter_with_symbol
@@ -68,15 +68,15 @@ module ActiveModel
expected_adapter_map = {
'json'.freeze => ActiveModel::Serializer::Adapter::Json,
'json_api'.freeze => ActiveModel::Serializer::Adapter::JsonApi,
'flatten_json'.freeze => ActiveModel::Serializer::Adapter::FlattenJson,
'null'.freeze => ActiveModel::Serializer::Adapter::Null
'attributes'.freeze => ActiveModel::Serializer::Adapter::Attributes,
'null'.freeze => ActiveModel::Serializer::Adapter::Null
}
assert_equal ActiveModel::Serializer::Adapter.adapter_map, expected_adapter_map
end
def test_adapters
assert_equal ActiveModel::Serializer::Adapter.adapters.sort, [
'flatten_json'.freeze,
'attributes'.freeze,
'json'.freeze,
'json_api'.freeze,
'null'.freeze
@@ -114,8 +114,8 @@ module ActiveModel
end
def test_adapter
assert_equal ActiveModel::Serializer.config.adapter, :flatten_json
assert_equal ActiveModel::Serializer.adapter, ActiveModel::Serializer::Adapter::FlattenJson
assert_equal ActiveModel::Serializer.config.adapter, :attributes
assert_equal ActiveModel::Serializer.adapter, ActiveModel::Serializer::Adapter::Attributes
end
def test_register_adapter

View File

@@ -21,7 +21,7 @@ module ActiveModel
def test_attribute_inheritance_with_key
inherited_klass = Class.new(AlternateBlogSerializer)
blog_serializer = inherited_klass.new(@blog)
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(blog_serializer)
adapter = ActiveModel::Serializer::Adapter::Attributes.new(blog_serializer)
assert_equal({ :id => 1, :title => 'AMS Hints' }, adapter.serializable_hash)
end

View File

@@ -8,7 +8,7 @@ module ActiveModel
end
def test_default_adapter
assert_equal :flatten_json, ActiveModel::Serializer.config.adapter
assert_equal :attributes, ActiveModel::Serializer.config.adapter
end
end
end

View File

@@ -27,7 +27,7 @@ module ActiveModel
end
def test_meta_is_not_included_when_root_is_missing
# load_adapter uses FlattenJson Adapter
# load_adapter uses Attributes Adapter
adapter = load_adapter(meta: { total: 10 })
expected = {
id: 1,
@@ -67,8 +67,8 @@ module ActiveModel
def test_meta_is_not_present_on_arrays_without_root
serializer = ArraySerializer.new([@blog], meta: { total: 10 })
# FlattenJSON doesn't have support to root
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer)
# Attributes doesn't have support to root
adapter = ActiveModel::Serializer::Adapter::Attributes.new(serializer)
expected = [{
id: 1,
name: 'AMS Hints',
@@ -113,7 +113,7 @@ module ActiveModel
private
def load_adapter(options)
options = options.merge(adapter: :flatten_json, serializer: AlternateBlogSerializer)
options = options.merge(adapter: :attributes, serializer: AlternateBlogSerializer)
ActiveModel::SerializableResource.new(@blog, options)
end
end