mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Rubocop: Consistent spacing
This commit is contained in:
@@ -20,7 +20,6 @@ module ActiveModel
|
||||
adapter = ActiveModel::Serializer.adapter
|
||||
assert_equal ActiveModel::Serializer::Adapter::Null, adapter
|
||||
ensure
|
||||
|
||||
end
|
||||
|
||||
def test_overwrite_adapter_with_class
|
||||
|
||||
@@ -4,7 +4,7 @@ module ActiveModel
|
||||
class Serializer
|
||||
class AssociationsTest < Minitest::Test
|
||||
class Model
|
||||
def initialize(hash={})
|
||||
def initialize(hash = {})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module ActiveModel
|
||||
@author.roles = []
|
||||
@blog = Blog.new({ name: 'AMS Blog' })
|
||||
@post = Post.new({ title: 'New Post', body: 'Body' })
|
||||
@tag = Tag.new({name: '#hashtagged'})
|
||||
@tag = Tag.new({ name: '#hashtagged' })
|
||||
@comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
|
||||
@post.comments = [@comment]
|
||||
@post.tags = [@tag]
|
||||
@@ -39,7 +39,7 @@ module ActiveModel
|
||||
@post.author = @author
|
||||
@author.posts = [@post]
|
||||
|
||||
@post_serializer = PostSerializer.new(@post, {custom_options: true})
|
||||
@post_serializer = PostSerializer.new(@post, { custom_options: true })
|
||||
@author_serializer = AuthorSerializer.new(@author)
|
||||
@comment_serializer = CommentSerializer.new(@comment)
|
||||
end
|
||||
@@ -74,7 +74,7 @@ module ActiveModel
|
||||
|
||||
assert_equal key, :tags
|
||||
assert_equal serializer, nil
|
||||
assert_equal [{ attributes: { name: '#hashtagged' }}].to_json, options[:virtual_value].to_json
|
||||
assert_equal [{ attributes: { name: '#hashtagged' } }].to_json, options[:virtual_value].to_json
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,19 +10,19 @@ module ActiveModel
|
||||
|
||||
def test_attributes_definition
|
||||
assert_equal([:id, :title],
|
||||
@blog_serializer.class._attributes)
|
||||
@blog_serializer.class._attributes)
|
||||
end
|
||||
|
||||
def test_json_serializable_hash
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(@blog_serializer)
|
||||
assert_equal({blog: { id:1, title:'AMS Hints'}}, adapter.serializable_hash)
|
||||
assert_equal({ blog: { id: 1, title: 'AMS Hints' } }, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
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)
|
||||
assert_equal({:id=>1, :title=>'AMS Hints'}, adapter.serializable_hash)
|
||||
assert_equal({ :id => 1, :title => 'AMS Hints' }, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_multiple_calls_with_the_same_attribute
|
||||
@@ -52,7 +52,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(attribute_serializer.new(@blog))
|
||||
assert_equal({ blog: { type: 1} }, adapter.serializable_hash)
|
||||
assert_equal({ blog: { type: 1 } }, adapter.serializable_hash)
|
||||
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(attributes_serializer.new(@blog))
|
||||
assert_equal({ blog: { type: 'stuff' } }, adapter.serializable_hash)
|
||||
|
||||
@@ -15,18 +15,17 @@ module ActiveModel
|
||||
|
||||
def test_attributes_definition
|
||||
assert_equal([:name, :description],
|
||||
@profile_serializer.class._attributes)
|
||||
@profile_serializer.class._attributes)
|
||||
end
|
||||
|
||||
def test_attributes_with_fields_option
|
||||
assert_equal({name: 'Name 1'},
|
||||
@profile_serializer.attributes(fields: [:name]))
|
||||
assert_equal({ name: 'Name 1' },
|
||||
@profile_serializer.attributes(fields: [:name]))
|
||||
end
|
||||
|
||||
def test_required_fields
|
||||
assert_equal({name: 'Name 1', description: 'Description 1'},
|
||||
@profile_serializer.attributes(fields: [:name, :description], required_fields: [:name]))
|
||||
|
||||
assert_equal({ name: 'Name 1', description: 'Description 1' },
|
||||
@profile_serializer.attributes(fields: [:name, :description], required_fields: [:name]))
|
||||
end
|
||||
|
||||
def test_attributes_inheritance_definition
|
||||
@@ -35,8 +34,8 @@ module ActiveModel
|
||||
|
||||
def test_attributes_inheritance
|
||||
serializer = @serializer_klass.new(@comment)
|
||||
assert_equal({id: 1, body: 'ZOMG!!'},
|
||||
serializer.attributes)
|
||||
assert_equal({ id: 1, body: 'ZOMG!!' },
|
||||
serializer.attributes)
|
||||
end
|
||||
|
||||
def test_attribute_inheritance_with_new_attribute_definition
|
||||
@@ -46,8 +45,8 @@ module ActiveModel
|
||||
|
||||
def test_attribute_inheritance_with_new_attribute
|
||||
serializer = @serializer_klass_with_new_attributes.new(@comment)
|
||||
assert_equal({id: 1, body: 'ZOMG!!', date: '2015', likes: nil},
|
||||
serializer.attributes)
|
||||
assert_equal({ id: 1, body: 'ZOMG!!', date: '2015', likes: nil },
|
||||
serializer.attributes)
|
||||
end
|
||||
|
||||
def test_multiple_calls_with_the_same_attribute
|
||||
|
||||
@@ -58,9 +58,9 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_cache_options_definition
|
||||
assert_equal({expires_in: 0.1, skip_digest: true}, @post_serializer.class._cache_options)
|
||||
assert_equal({ expires_in: 0.1, skip_digest: true }, @post_serializer.class._cache_options)
|
||||
assert_equal(nil, @blog_serializer.class._cache_options)
|
||||
assert_equal({expires_in: 1.day, skip_digest: true}, @comment_serializer.class._cache_options)
|
||||
assert_equal({ expires_in: 1.day, skip_digest: true }, @comment_serializer.class._cache_options)
|
||||
end
|
||||
|
||||
def test_fragment_cache_definition
|
||||
@@ -118,7 +118,7 @@ module ActiveModel
|
||||
hash = render_object_with_cache(@location)
|
||||
|
||||
assert_equal(hash, expected_result)
|
||||
assert_equal({place: 'Nowhere'}, ActionController::Base.cache_store.fetch(@location.cache_key))
|
||||
assert_equal({ place: 'Nowhere' }, ActionController::Base.cache_store.fetch(@location.cache_key))
|
||||
end
|
||||
|
||||
def test_uses_file_digest_in_cache_key
|
||||
@@ -155,6 +155,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_object_with_cache(obj)
|
||||
ActiveModel::SerializableResource.new(obj).serializable_hash
|
||||
end
|
||||
|
||||
@@ -3,12 +3,11 @@ require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class FieldsetTest < Minitest::Test
|
||||
|
||||
def test_fieldset_with_hash
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new({'post' => ['id', 'title'], 'coment' => ['body']})
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new({ 'post' => %w(id title), 'coment' => ['body'] })
|
||||
|
||||
assert_equal(
|
||||
{:post=>[:id, :title], :coment=>[:body]},
|
||||
{ :post => [:id, :title], :coment => [:body] },
|
||||
fieldset.fields
|
||||
)
|
||||
end
|
||||
@@ -17,7 +16,7 @@ module ActiveModel
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new(['title'], 'post')
|
||||
|
||||
assert_equal(
|
||||
{:post => [:title]},
|
||||
{ :post => [:title] },
|
||||
fieldset.fields
|
||||
)
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_meta_is_present_with_root
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10})
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: { total: 10 })
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
expected = {
|
||||
blog: {
|
||||
@@ -28,7 +28,7 @@ module ActiveModel
|
||||
|
||||
def test_meta_is_not_included_when_root_is_missing
|
||||
# load_adapter uses FlattenJson Adapter
|
||||
adapter = load_adapter(meta: {total: 10})
|
||||
adapter = load_adapter(meta: { total: 10 })
|
||||
expected = {
|
||||
id: 1,
|
||||
title: 'AMS Hints'
|
||||
@@ -37,7 +37,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_meta_key_is_used
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}, meta_key: 'haha_meta')
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: { total: 10 }, meta_key: 'haha_meta')
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
expected = {
|
||||
blog: {
|
||||
@@ -52,7 +52,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_meta_key_is_used_with_json_api
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}, meta_key: 'haha_meta')
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: { total: 10 }, meta_key: 'haha_meta')
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
expected = {
|
||||
data: {
|
||||
@@ -66,7 +66,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_meta_is_not_present_on_arrays_without_root
|
||||
serializer = ArraySerializer.new([@blog], meta: {total: 10})
|
||||
serializer = ArraySerializer.new([@blog], meta: { total: 10 })
|
||||
# FlattenJSON doesn't have support to root
|
||||
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer)
|
||||
expected = [{
|
||||
@@ -86,7 +86,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_meta_is_present_on_arrays_with_root
|
||||
serializer = ArraySerializer.new([@blog], meta: {total: 10}, meta_key: 'haha_meta')
|
||||
serializer = ArraySerializer.new([@blog], meta: { total: 10 }, meta_key: 'haha_meta')
|
||||
# JSON adapter adds root by default
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
expected = {
|
||||
|
||||
@@ -3,13 +3,12 @@ require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class RootTest < Minitest::Test
|
||||
|
||||
def setup
|
||||
@virtual_value = VirtualValue.new(id: 1)
|
||||
end
|
||||
|
||||
def test_overwrite_root
|
||||
serializer = VirtualValueSerializer.new(@virtual_value, {root: 'smth'})
|
||||
serializer = VirtualValueSerializer.new(@virtual_value, { root: 'smth' })
|
||||
assert_equal('smth', serializer.json_key)
|
||||
end
|
||||
|
||||
@@ -17,7 +16,6 @@ module ActiveModel
|
||||
serializer = VirtualValueSerializer.new(@virtual_value)
|
||||
assert_equal('virtual_value', serializer.json_key)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,6 @@ require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class UrlsTest < Minitest::Test
|
||||
|
||||
def setup
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@post = Post.new({ title: 'New Post', body: 'Body' })
|
||||
|
||||
Reference in New Issue
Block a user