mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
re: RuboCop - hash indention corrections
This commit is contained in:
parent
f15f6850de
commit
004f1437d8
@ -28,8 +28,8 @@ module ActiveModelSerializers
|
||||
def test_transform_default
|
||||
mock_request
|
||||
assert_equal({
|
||||
blog: { id: 1, special_attribute: 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
blog: { id: 1, special_attribute: 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_transform_global_config
|
||||
@ -38,8 +38,8 @@ module ActiveModelSerializers
|
||||
@adapter.serializable_hash
|
||||
end
|
||||
assert_equal({
|
||||
blog: { id: 1, specialAttribute: 'neat', articles: nil }
|
||||
}, result)
|
||||
blog: { id: 1, specialAttribute: 'neat', articles: nil }
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_transform_serialization_ctx_overrides_global_config
|
||||
@ -48,8 +48,8 @@ module ActiveModelSerializers
|
||||
@adapter.serializable_hash
|
||||
end
|
||||
assert_equal({
|
||||
Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
|
||||
}, result)
|
||||
Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_transform_undefined
|
||||
@ -63,29 +63,29 @@ module ActiveModelSerializers
|
||||
def test_transform_dash
|
||||
mock_request(:dash)
|
||||
assert_equal({
|
||||
blog: { id: 1, :"special-attribute" => 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
blog: { id: 1, :"special-attribute" => 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_transform_unaltered
|
||||
mock_request(:unaltered)
|
||||
assert_equal({
|
||||
blog: { id: 1, special_attribute: 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
blog: { id: 1, special_attribute: 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_transform_camel
|
||||
mock_request(:camel)
|
||||
assert_equal({
|
||||
Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_transform_camel_lower
|
||||
mock_request(:camel_lower)
|
||||
assert_equal({
|
||||
blog: { id: 1, specialAttribute: 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
blog: { id: 1, specialAttribute: 'neat', articles: nil }
|
||||
}, @adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -12,8 +12,8 @@ module ActiveModelSerializers
|
||||
|
||||
def test_active_model_with_error
|
||||
options = {
|
||||
serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
}
|
||||
|
||||
@resource.errors.add(:name, 'cannot be nil')
|
||||
@ -35,8 +35,8 @@ module ActiveModelSerializers
|
||||
|
||||
def test_active_model_with_multiple_errors
|
||||
options = {
|
||||
serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
serializer: ActiveModel::Serializer::ErrorSerializer,
|
||||
adapter: :json_api
|
||||
}
|
||||
|
||||
@resource.errors.add(:name, 'cannot be nil')
|
||||
|
||||
@ -112,14 +112,14 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'posts',
|
||||
relationships: {
|
||||
tags: { data: [@tag.as_json] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'posts',
|
||||
relationships: {
|
||||
tags: { data: [@tag.as_json] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_has_many_with_virtual_value
|
||||
@ -127,16 +127,16 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'virtual-values',
|
||||
relationships: {
|
||||
maker: { data: { type: 'makers', id: '1' } },
|
||||
reviews: { data: [{ type: 'reviews', id: '1' },
|
||||
{ type: 'reviews', id: '2' }] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'virtual-values',
|
||||
relationships: {
|
||||
maker: { data: { type: 'makers', id: '1' } },
|
||||
reviews: { data: [{ type: 'reviews', id: '1' },
|
||||
{ type: 'reviews', id: '2' }] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -22,11 +22,11 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal({
|
||||
reviews: { data: [{ type: 'comments', id: '1' },
|
||||
{ type: 'comments', id: '2' }] },
|
||||
writer: { data: { type: 'authors', id: '1' } },
|
||||
site: { data: { type: 'blogs', id: '1' } }
|
||||
}, adapter.serializable_hash[:data][:relationships])
|
||||
reviews: { data: [{ type: 'comments', id: '1' },
|
||||
{ type: 'comments', id: '2' }] },
|
||||
writer: { data: { type: 'authors', id: '1' } },
|
||||
site: { data: { type: 'blogs', id: '1' } }
|
||||
}, adapter.serializable_hash[:data][:relationships])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -70,33 +70,33 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
:"publish-at" => @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
:"post-authors" => 'http://example.com/posts/1337/authors',
|
||||
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, :"favorite-count" => 10 }
|
||||
}
|
||||
}, result)
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
:"publish-at" => @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
:"post-authors" => 'http://example.com/posts/1337/authors',
|
||||
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, :"favorite-count" => 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_success_document_transform_global_config
|
||||
@ -107,33 +107,33 @@ module ActiveModelSerializers
|
||||
adapter.serializable_hash
|
||||
end
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
publishAt: @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
postAuthors: 'http://example.com/posts/1337/authors',
|
||||
subscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, favoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
publishAt: @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
postAuthors: 'http://example.com/posts/1337/authors',
|
||||
subscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, favoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_success_doc_transform_serialization_ctx_overrides_global
|
||||
@ -144,33 +144,33 @@ module ActiveModelSerializers
|
||||
adapter.serializable_hash
|
||||
end
|
||||
assert_equal({
|
||||
Data: {
|
||||
Id: '1337',
|
||||
Type: 'Posts',
|
||||
Attributes: {
|
||||
Title: 'Title 1',
|
||||
Body: 'Body 1',
|
||||
PublishAt: @publish_at
|
||||
},
|
||||
Relationships: {
|
||||
Author: {
|
||||
Data: { Id: '1', Type: 'Authors' }
|
||||
},
|
||||
Comments: {
|
||||
Data: [
|
||||
{ Id: '7', Type: 'Comments' },
|
||||
{ Id: '12', Type: 'Comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
Links: {
|
||||
Self: 'http://example.com/posts/1337',
|
||||
PostAuthors: 'http://example.com/posts/1337/authors',
|
||||
SubscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
Meta: { Rating: 5, FavoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
Data: {
|
||||
Id: '1337',
|
||||
Type: 'Posts',
|
||||
Attributes: {
|
||||
Title: 'Title 1',
|
||||
Body: 'Body 1',
|
||||
PublishAt: @publish_at
|
||||
},
|
||||
Relationships: {
|
||||
Author: {
|
||||
Data: { Id: '1', Type: 'Authors' }
|
||||
},
|
||||
Comments: {
|
||||
Data: [
|
||||
{ Id: '7', Type: 'Comments' },
|
||||
{ Id: '12', Type: 'Comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
Links: {
|
||||
Self: 'http://example.com/posts/1337',
|
||||
PostAuthors: 'http://example.com/posts/1337/authors',
|
||||
SubscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
Meta: { Rating: 5, FavoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_success_document_transform_dash
|
||||
@ -179,33 +179,33 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
:"publish-at" => @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
:"post-authors" => 'http://example.com/posts/1337/authors',
|
||||
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, :"favorite-count" => 10 }
|
||||
}
|
||||
}, result)
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
:"publish-at" => @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
:"post-authors" => 'http://example.com/posts/1337/authors',
|
||||
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, :"favorite-count" => 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_success_document_transform_unaltered
|
||||
@ -214,33 +214,33 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
publish_at: @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
post_authors: 'http://example.com/posts/1337/authors',
|
||||
subscriber_comments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, favorite_count: 10 }
|
||||
}
|
||||
}, result)
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
publish_at: @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
post_authors: 'http://example.com/posts/1337/authors',
|
||||
subscriber_comments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, favorite_count: 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_success_document_transform_undefined
|
||||
@ -259,33 +259,33 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
assert_equal({
|
||||
Data: {
|
||||
Id: '1337',
|
||||
Type: 'Posts',
|
||||
Attributes: {
|
||||
Title: 'Title 1',
|
||||
Body: 'Body 1',
|
||||
PublishAt: @publish_at
|
||||
},
|
||||
Relationships: {
|
||||
Author: {
|
||||
Data: { Id: '1', Type: 'Authors' }
|
||||
},
|
||||
Comments: {
|
||||
Data: [
|
||||
{ Id: '7', Type: 'Comments' },
|
||||
{ Id: '12', Type: 'Comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
Links: {
|
||||
Self: 'http://example.com/posts/1337',
|
||||
PostAuthors: 'http://example.com/posts/1337/authors',
|
||||
SubscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
Meta: { Rating: 5, FavoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
Data: {
|
||||
Id: '1337',
|
||||
Type: 'Posts',
|
||||
Attributes: {
|
||||
Title: 'Title 1',
|
||||
Body: 'Body 1',
|
||||
PublishAt: @publish_at
|
||||
},
|
||||
Relationships: {
|
||||
Author: {
|
||||
Data: { Id: '1', Type: 'Authors' }
|
||||
},
|
||||
Comments: {
|
||||
Data: [
|
||||
{ Id: '7', Type: 'Comments' },
|
||||
{ Id: '12', Type: 'Comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
Links: {
|
||||
Self: 'http://example.com/posts/1337',
|
||||
PostAuthors: 'http://example.com/posts/1337/authors',
|
||||
SubscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
Meta: { Rating: 5, FavoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_success_document_transform_camel_lower
|
||||
@ -294,33 +294,33 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||
result = adapter.serializable_hash
|
||||
assert_equal({
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
publishAt: @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
postAuthors: 'http://example.com/posts/1337/authors',
|
||||
subscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, favoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
data: {
|
||||
id: '1337',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
title: 'Title 1',
|
||||
body: 'Body 1',
|
||||
publishAt: @publish_at
|
||||
},
|
||||
relationships: {
|
||||
author: {
|
||||
data: { id: '1', type: 'authors' }
|
||||
},
|
||||
comments: {
|
||||
data: [
|
||||
{ id: '7', type: 'comments' },
|
||||
{ id: '12', type: 'comments' }
|
||||
]
|
||||
}
|
||||
},
|
||||
links: {
|
||||
self: 'http://example.com/posts/1337',
|
||||
postAuthors: 'http://example.com/posts/1337/authors',
|
||||
subscriberComments: 'http://example.com/posts/1337/comments'
|
||||
},
|
||||
meta: { rating: 5, favoriteCount: 10 }
|
||||
}
|
||||
}, result)
|
||||
end
|
||||
|
||||
def test_error_document_transform_default
|
||||
|
||||
@ -32,14 +32,14 @@ module ActiveModelSerializers
|
||||
adapter = ActiveModelSerializers::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({
|
||||
id: 1,
|
||||
reviews: [
|
||||
{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
],
|
||||
writer: { id: 1, name: 'Steve K.' },
|
||||
site: { id: 1, name: 'My Blog!!' }
|
||||
}, adapter.serializable_hash[:post])
|
||||
id: 1,
|
||||
reviews: [
|
||||
{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
],
|
||||
writer: { id: 1, name: 'Steve K.' },
|
||||
site: { id: 1, name: 'My Blog!!' }
|
||||
}, adapter.serializable_hash[:post])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -27,11 +27,11 @@ module ActiveModel
|
||||
id: 1,
|
||||
title: 'headshot-1.jpg',
|
||||
imageable: {
|
||||
type: 'employee',
|
||||
employee: {
|
||||
id: 42,
|
||||
name: 'Zoop Zoopler'
|
||||
}
|
||||
type: 'employee',
|
||||
employee: {
|
||||
id: 42,
|
||||
name: 'Zoop Zoopler'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ class ApiAssertion
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def assert_equal(expected, actual, message)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user