mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
re: RuboCop - replace rocket style hashes
This commit is contained in:
parent
004f1437d8
commit
024b2d51d3
@ -45,14 +45,6 @@ Style/ClassAndModuleChildren:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Offense count: 58
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
|
||||||
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
|
|
||||||
Style/HashSyntax:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
|
|
||||||
# Offense count: 3
|
# Offense count: 3
|
||||||
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
||||||
# NamePrefix: is_, has_, have_
|
# NamePrefix: is_, has_, have_
|
||||||
|
|||||||
2
Rakefile
2
Rakefile
@ -100,4 +100,4 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc 'CI test task'
|
desc 'CI test task'
|
||||||
task :ci => [:default]
|
task ci: [:default]
|
||||||
|
|||||||
@ -23,7 +23,7 @@ module ActiveModelSerializers
|
|||||||
# This hook is run after the action_controller railtie has set the configuration
|
# This hook is run after the action_controller railtie has set the configuration
|
||||||
# based on the *environment* configuration and before any config/initializers are run
|
# based on the *environment* configuration and before any config/initializers are run
|
||||||
# and also before eager_loading (if enabled).
|
# and also before eager_loading (if enabled).
|
||||||
initializer 'active_model_serializers.set_configs', :after => 'action_controller.set_configs' do
|
initializer 'active_model_serializers.set_configs', after: 'action_controller.set_configs' do
|
||||||
ActiveModelSerializers.logger = Rails.configuration.action_controller.logger
|
ActiveModelSerializers.logger = Rails.configuration.action_controller.logger
|
||||||
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
|
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
|
||||||
# We want this hook to run after the config has been set, even if ActionController has already loaded.
|
# We want this hook to run after the config has been set, even if ActionController has already loaded.
|
||||||
|
|||||||
@ -53,7 +53,7 @@ module ActiveModelSerializers::Jsonapi
|
|||||||
def self.parser
|
def self.parser
|
||||||
lambda do |body|
|
lambda do |body|
|
||||||
data = JSON.parse(body)
|
data = JSON.parse(body)
|
||||||
data = { :_json => data } unless data.is_a?(Hash)
|
data = { _json: data } unless data.is_a?(Hash)
|
||||||
data.with_indifferent_access
|
data.with_indifferent_access
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,11 +2,11 @@ module Rails
|
|||||||
module Generators
|
module Generators
|
||||||
class SerializerGenerator < NamedBase
|
class SerializerGenerator < NamedBase
|
||||||
source_root File.expand_path('../templates', __FILE__)
|
source_root File.expand_path('../templates', __FILE__)
|
||||||
check_class_collision :suffix => 'Serializer'
|
check_class_collision suffix: 'Serializer'
|
||||||
|
|
||||||
argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
|
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
||||||
|
|
||||||
class_option :parent, :type => :string, :desc => 'The parent class for the generated serializer'
|
class_option :parent, type: :string, desc: 'The parent class for the generated serializer'
|
||||||
|
|
||||||
def create_serializer_file
|
def create_serializer_file
|
||||||
template 'serializer.rb.erb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
|
template 'serializer.rb.erb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
|
||||||
|
|||||||
@ -8,11 +8,10 @@ module ActionController
|
|||||||
get :render_resource_with_errors
|
get :render_resource_with_errors
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors =>
|
errors: [
|
||||||
[
|
{ source: { pointer: '/data/attributes/name' }, detail: 'cannot be nil' },
|
||||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
|
{ source: { pointer: '/data/attributes/name' }, detail: 'must be longer' },
|
||||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
|
{ source: { pointer: '/data/attributes/id' }, detail: 'must be a uuid' }
|
||||||
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
|
|
||||||
]
|
]
|
||||||
}.to_json
|
}.to_json
|
||||||
assert_equal json_reponse_body.to_json, expected_errors_object
|
assert_equal json_reponse_body.to_json, expected_errors_object
|
||||||
|
|||||||
@ -87,7 +87,7 @@ module ActionController
|
|||||||
setup do
|
setup do
|
||||||
@routes = Rails.application.routes.draw do
|
@routes = Rails.application.routes.draw do
|
||||||
ActiveSupport::Deprecation.silence do
|
ActiveSupport::Deprecation.silence do
|
||||||
match ':action', :to => LinkedTestController, via: [:get, :post]
|
match ':action', to: LinkedTestController, via: [:get, :post]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,16 +5,16 @@ class ActiveModelSerializers::KeyTransformTest < ActiveSupport::TestCase
|
|||||||
obj = Object.new
|
obj = Object.new
|
||||||
scenarios = [
|
scenarios = [
|
||||||
{
|
{
|
||||||
value: { :"some-key" => 'value' },
|
value: { "some-key": 'value' },
|
||||||
expected: { :SomeKey => 'value' }
|
expected: { SomeKey: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :someKey => 'value' },
|
value: { someKey: 'value' },
|
||||||
expected: { :SomeKey => 'value' }
|
expected: { SomeKey: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :some_key => 'value' },
|
value: { some_key: 'value' },
|
||||||
expected: { :SomeKey => 'value' }
|
expected: { SomeKey: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'some-key' => 'value' },
|
value: { 'some-key' => 'value' },
|
||||||
@ -71,16 +71,16 @@ class ActiveModelSerializers::KeyTransformTest < ActiveSupport::TestCase
|
|||||||
obj = Object.new
|
obj = Object.new
|
||||||
scenarios = [
|
scenarios = [
|
||||||
{
|
{
|
||||||
value: { :"some-key" => 'value' },
|
value: { "some-key": 'value' },
|
||||||
expected: { :someKey => 'value' }
|
expected: { someKey: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :SomeKey => 'value' },
|
value: { SomeKey: 'value' },
|
||||||
expected: { :someKey => 'value' }
|
expected: { someKey: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :some_key => 'value' },
|
value: { some_key: 'value' },
|
||||||
expected: { :someKey => 'value' }
|
expected: { someKey: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'some-key' => 'value' },
|
value: { 'some-key' => 'value' },
|
||||||
@ -137,24 +137,24 @@ class ActiveModelSerializers::KeyTransformTest < ActiveSupport::TestCase
|
|||||||
obj = Object.new
|
obj = Object.new
|
||||||
scenarios = [
|
scenarios = [
|
||||||
{
|
{
|
||||||
value: { :some_key => 'value' },
|
value: { some_key: 'value' },
|
||||||
expected: { :"some-key" => 'value' }
|
expected: { "some-key": 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'some_key' => 'value' },
|
value: { 'some_key' => 'value' },
|
||||||
expected: { 'some-key' => 'value' }
|
expected: { 'some-key' => 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :SomeKey => 'value' },
|
value: { SomeKey: 'value' },
|
||||||
expected: { :"some-key" => 'value' }
|
expected: { "some-key": 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'SomeKey' => 'value' },
|
value: { 'SomeKey' => 'value' },
|
||||||
expected: { 'some-key' => 'value' }
|
expected: { 'some-key' => 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :someKey => 'value' },
|
value: { someKey: 'value' },
|
||||||
expected: { :"some-key" => 'value' }
|
expected: { "some-key": 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'someKey' => 'value' },
|
value: { 'someKey' => 'value' },
|
||||||
@ -199,24 +199,24 @@ class ActiveModelSerializers::KeyTransformTest < ActiveSupport::TestCase
|
|||||||
obj = Object.new
|
obj = Object.new
|
||||||
scenarios = [
|
scenarios = [
|
||||||
{
|
{
|
||||||
value: { :"some-key" => 'value' },
|
value: { "some-key": 'value' },
|
||||||
expected: { :some_key => 'value' }
|
expected: { some_key: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'some-key' => 'value' },
|
value: { 'some-key' => 'value' },
|
||||||
expected: { 'some_key' => 'value' }
|
expected: { 'some_key' => 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :SomeKey => 'value' },
|
value: { SomeKey: 'value' },
|
||||||
expected: { :some_key => 'value' }
|
expected: { some_key: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'SomeKey' => 'value' },
|
value: { 'SomeKey' => 'value' },
|
||||||
expected: { 'some_key' => 'value' }
|
expected: { 'some_key' => 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { :someKey => 'value' },
|
value: { someKey: 'value' },
|
||||||
expected: { :some_key => 'value' }
|
expected: { some_key: 'value' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: { 'someKey' => 'value' },
|
value: { 'someKey' => 'value' },
|
||||||
|
|||||||
@ -44,7 +44,7 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
ActiveSupport::Deprecation.silence do
|
ActiveSupport::Deprecation.silence do
|
||||||
match ':action', :to => TestController, via: [:get, :post]
|
match ':action', to: TestController, via: [:get, :post]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -95,7 +95,7 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
ActiveSupport::Deprecation.silence do
|
ActiveSupport::Deprecation.silence do
|
||||||
match ':action', :to => TestController, via: [:get, :post]
|
match ':action', to: TestController, via: [:get, :post]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -63,7 +63,7 @@ module ActiveModelSerializers
|
|||||||
def test_transform_dash
|
def test_transform_dash
|
||||||
mock_request(:dash)
|
mock_request(:dash)
|
||||||
assert_equal({
|
assert_equal({
|
||||||
blog: { id: 1, :"special-attribute" => 'neat', articles: nil }
|
blog: { id: 1, "special-attribute": 'neat', articles: nil }
|
||||||
}, @adapter.serializable_hash)
|
}, @adapter.serializable_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ module ActiveModelSerializers
|
|||||||
assert_equal serializable_resource.serializer_instance.object, @resource
|
assert_equal serializable_resource.serializer_instance.object, @resource
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors => [
|
errors: [
|
||||||
{
|
{
|
||||||
source: { pointer: '/data/attributes/name' },
|
source: { pointer: '/data/attributes/name' },
|
||||||
detail: 'cannot be nil'
|
detail: 'cannot be nil'
|
||||||
@ -48,10 +48,10 @@ module ActiveModelSerializers
|
|||||||
assert_equal serializable_resource.serializer_instance.object, @resource
|
assert_equal serializable_resource.serializer_instance.object, @resource
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors => [
|
errors: [
|
||||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
|
{ source: { pointer: '/data/attributes/name' }, detail: 'cannot be nil' },
|
||||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
|
{ source: { pointer: '/data/attributes/name' }, detail: 'must be longer' },
|
||||||
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
|
{ source: { pointer: '/data/attributes/id' }, detail: 'must be a uuid' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal serializable_resource.as_json, expected_errors_object
|
assert_equal serializable_resource.as_json, expected_errors_object
|
||||||
|
|||||||
@ -370,7 +370,7 @@ module ActiveModelSerializers
|
|||||||
expected = [
|
expected = [
|
||||||
type: 'nested-posts', id: '2',
|
type: 'nested-posts', id: '2',
|
||||||
relationships: {
|
relationships: {
|
||||||
:"nested-posts" => {
|
"nested-posts": {
|
||||||
data: [
|
data: [
|
||||||
{ type: 'nested-posts', id: '1' },
|
{ type: 'nested-posts', id: '1' },
|
||||||
{ type: 'nested-posts', id: '2' }
|
{ type: 'nested-posts', id: '2' }
|
||||||
|
|||||||
@ -82,10 +82,10 @@ module ActiveModelSerializers
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
author: 'http://example.com/link_authors/1337',
|
author: 'http://example.com/link_authors/1337',
|
||||||
:"link-authors" => 'http://example.com/link_authors',
|
"link-authors": 'http://example.com/link_authors',
|
||||||
resource: 'http://example.com/resource',
|
resource: 'http://example.com/resource',
|
||||||
posts: 'http://example.com/link_authors/1337/posts',
|
posts: 'http://example.com/link_authors/1337/posts',
|
||||||
:"yet-another" => 'http://example.com/resource/1337'
|
"yet-another": 'http://example.com/resource/1337'
|
||||||
}
|
}
|
||||||
assert_equal(expected, hash[:data][:links])
|
assert_equal(expected, hash[:data][:links])
|
||||||
end
|
end
|
||||||
|
|||||||
@ -54,7 +54,7 @@ module ActiveModel
|
|||||||
adapter: :json_api
|
adapter: :json_api
|
||||||
).serializable_hash
|
).serializable_hash
|
||||||
expected = {
|
expected = {
|
||||||
:"comments-count" => @post.comments.count
|
"comments-count": @post.comments.count
|
||||||
}
|
}
|
||||||
assert_equal(expected, hash[:data][:meta])
|
assert_equal(expected, hash[:data][:meta])
|
||||||
end
|
end
|
||||||
@ -68,9 +68,9 @@ module ActiveModel
|
|||||||
adapter: :json_api
|
adapter: :json_api
|
||||||
).serializable_hash
|
).serializable_hash
|
||||||
expected = {
|
expected = {
|
||||||
:data => [
|
data: [
|
||||||
{ :id => '1337', :type => 'posts', :meta => { :"comments-count" => 0 } },
|
{ id: '1337', type: 'posts', meta: { "comments-count": 0 } },
|
||||||
{ :id => '1339', :type => 'posts', :meta => { :"comments-count" => 1 } }
|
{ id: '1339', type: 'posts', meta: { "comments-count": 1 } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal(expected, hash)
|
assert_equal(expected, hash)
|
||||||
|
|||||||
@ -76,7 +76,7 @@ module ActiveModelSerializers
|
|||||||
attributes: {
|
attributes: {
|
||||||
title: 'Title 1',
|
title: 'Title 1',
|
||||||
body: 'Body 1',
|
body: 'Body 1',
|
||||||
:"publish-at" => @publish_at
|
"publish-at": @publish_at
|
||||||
},
|
},
|
||||||
relationships: {
|
relationships: {
|
||||||
author: {
|
author: {
|
||||||
@ -91,10 +91,10 @@ module ActiveModelSerializers
|
|||||||
},
|
},
|
||||||
links: {
|
links: {
|
||||||
self: 'http://example.com/posts/1337',
|
self: 'http://example.com/posts/1337',
|
||||||
:"post-authors" => 'http://example.com/posts/1337/authors',
|
"post-authors": 'http://example.com/posts/1337/authors',
|
||||||
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
"subscriber-comments": 'http://example.com/posts/1337/comments'
|
||||||
},
|
},
|
||||||
meta: { rating: 5, :"favorite-count" => 10 }
|
meta: { rating: 5, "favorite-count": 10 }
|
||||||
}
|
}
|
||||||
}, result)
|
}, result)
|
||||||
end
|
end
|
||||||
@ -185,7 +185,7 @@ module ActiveModelSerializers
|
|||||||
attributes: {
|
attributes: {
|
||||||
title: 'Title 1',
|
title: 'Title 1',
|
||||||
body: 'Body 1',
|
body: 'Body 1',
|
||||||
:"publish-at" => @publish_at
|
"publish-at": @publish_at
|
||||||
},
|
},
|
||||||
relationships: {
|
relationships: {
|
||||||
author: {
|
author: {
|
||||||
@ -200,10 +200,10 @@ module ActiveModelSerializers
|
|||||||
},
|
},
|
||||||
links: {
|
links: {
|
||||||
self: 'http://example.com/posts/1337',
|
self: 'http://example.com/posts/1337',
|
||||||
:"post-authors" => 'http://example.com/posts/1337/authors',
|
"post-authors": 'http://example.com/posts/1337/authors',
|
||||||
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
"subscriber-comments": 'http://example.com/posts/1337/comments'
|
||||||
},
|
},
|
||||||
meta: { rating: 5, :"favorite-count" => 10 }
|
meta: { rating: 5, "favorite-count": 10 }
|
||||||
}
|
}
|
||||||
}, result)
|
}, result)
|
||||||
end
|
end
|
||||||
@ -332,14 +332,14 @@ module ActiveModelSerializers
|
|||||||
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
||||||
result = adapter.serializable_hash
|
result = adapter.serializable_hash
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors => [
|
errors: [
|
||||||
{
|
{
|
||||||
:source => { :pointer => '/data/attributes/published-at' },
|
source: { pointer: '/data/attributes/published-at' },
|
||||||
:detail => 'must be in the future'
|
detail: 'must be in the future'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
:source => { :pointer => '/data/attributes/title' },
|
source: { pointer: '/data/attributes/title' },
|
||||||
:detail => 'must be longer'
|
detail: 'must be longer'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -357,14 +357,14 @@ module ActiveModelSerializers
|
|||||||
adapter.serializable_hash
|
adapter.serializable_hash
|
||||||
end
|
end
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:Errors => [
|
Errors: [
|
||||||
{
|
{
|
||||||
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
Source: { Pointer: '/data/attributes/PublishedAt' },
|
||||||
:Detail => 'must be in the future'
|
Detail: 'must be in the future'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
:Source => { :Pointer => '/data/attributes/Title' },
|
Source: { Pointer: '/data/attributes/Title' },
|
||||||
:Detail => 'must be longer'
|
Detail: 'must be longer'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -382,14 +382,14 @@ module ActiveModelSerializers
|
|||||||
adapter.serializable_hash
|
adapter.serializable_hash
|
||||||
end
|
end
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:Errors => [
|
Errors: [
|
||||||
{
|
{
|
||||||
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
Source: { Pointer: '/data/attributes/PublishedAt' },
|
||||||
:Detail => 'must be in the future'
|
Detail: 'must be in the future'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
:Source => { :Pointer => '/data/attributes/Title' },
|
Source: { Pointer: '/data/attributes/Title' },
|
||||||
:Detail => 'must be longer'
|
Detail: 'must be longer'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -408,14 +408,14 @@ module ActiveModelSerializers
|
|||||||
result = adapter.serializable_hash
|
result = adapter.serializable_hash
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors => [
|
errors: [
|
||||||
{
|
{
|
||||||
:source => { :pointer => '/data/attributes/published-at' },
|
source: { pointer: '/data/attributes/published-at' },
|
||||||
:detail => 'must be in the future'
|
detail: 'must be in the future'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
:source => { :pointer => '/data/attributes/title' },
|
source: { pointer: '/data/attributes/title' },
|
||||||
:detail => 'must be longer'
|
detail: 'must be longer'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -434,9 +434,9 @@ module ActiveModelSerializers
|
|||||||
result = adapter.serializable_hash
|
result = adapter.serializable_hash
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors => [
|
errors: [
|
||||||
{ :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
|
{ source: { pointer: '/data/attributes/published_at' }, detail: 'must be in the future' },
|
||||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
{ source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal expected_errors_object, result
|
assert_equal expected_errors_object, result
|
||||||
@ -470,9 +470,9 @@ module ActiveModelSerializers
|
|||||||
result = adapter.serializable_hash
|
result = adapter.serializable_hash
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:Errors => [
|
Errors: [
|
||||||
{ :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
|
{ Source: { Pointer: '/data/attributes/PublishedAt' }, Detail: 'must be in the future' },
|
||||||
{ :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
|
{ Source: { Pointer: '/data/attributes/Title' }, Detail: 'must be longer' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal expected_errors_object, result
|
assert_equal expected_errors_object, result
|
||||||
@ -490,9 +490,9 @@ module ActiveModelSerializers
|
|||||||
result = adapter.serializable_hash
|
result = adapter.serializable_hash
|
||||||
|
|
||||||
expected_errors_object = {
|
expected_errors_object = {
|
||||||
:errors => [
|
errors: [
|
||||||
{ :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
|
{ source: { pointer: '/data/attributes/publishedAt' }, detail: 'must be in the future' },
|
||||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
{ source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal expected_errors_object, result
|
assert_equal expected_errors_object, result
|
||||||
|
|||||||
@ -51,8 +51,8 @@ module ActiveModelSerializers
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
expected_response_document = {
|
expected_response_document = {
|
||||||
:errors => [
|
errors: [
|
||||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' }
|
{ source: { pointer: '/data/attributes/name' }, detail: 'must be awesome' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal serializable_resource.as_json(options), expected_response_document
|
assert_equal serializable_resource.as_json(options), expected_response_document
|
||||||
@ -72,8 +72,8 @@ module ActiveModelSerializers
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
expected_response_document = {
|
expected_response_document = {
|
||||||
:errors => [
|
errors: [
|
||||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be amazing' }
|
{ source: { pointer: '/data/attributes/title' }, detail: 'must be amazing' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert_equal serializable_resource.as_json(options), expected_response_document
|
assert_equal serializable_resource.as_json(options), expected_response_document
|
||||||
|
|||||||
@ -143,12 +143,12 @@ module ActiveModel
|
|||||||
)
|
)
|
||||||
actual = serializable(post, adapter: :attributes, serializer: InlineAssociationTestPostSerializer).as_json
|
actual = serializable(post, adapter: :attributes, serializer: InlineAssociationTestPostSerializer).as_json
|
||||||
expected = {
|
expected = {
|
||||||
:comments => [
|
comments: [
|
||||||
{ :id => 1, :contents => 'first comment' },
|
{ id: 1, contents: 'first comment' },
|
||||||
{ :id => 2, :contents => 'last comment' }
|
{ id: 2, contents: 'last comment' }
|
||||||
],
|
],
|
||||||
:last_comments => [
|
last_comments: [
|
||||||
{ :id => 2, :contents => 'last comment' }
|
{ id: 2, contents: 'last comment' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ module ActiveModel
|
|||||||
inherited_klass = Class.new(AlternateBlogSerializer)
|
inherited_klass = Class.new(AlternateBlogSerializer)
|
||||||
blog_serializer = inherited_klass.new(@blog)
|
blog_serializer = inherited_klass.new(@blog)
|
||||||
adapter = ActiveModelSerializers::Adapter::Attributes.new(blog_serializer)
|
adapter = ActiveModelSerializers::Adapter::Attributes.new(blog_serializer)
|
||||||
assert_equal({ :id => 1, :title => 'AMS Hints' }, adapter.serializable_hash)
|
assert_equal({ id: 1, title: 'AMS Hints' }, adapter.serializable_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiple_calls_with_the_same_attribute
|
def test_multiple_calls_with_the_same_attribute
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module ActiveModel
|
|||||||
class FieldsetTest < ActiveSupport::TestCase
|
class FieldsetTest < ActiveSupport::TestCase
|
||||||
def test_fieldset_with_hash
|
def test_fieldset_with_hash
|
||||||
fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
|
fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
|
||||||
expected = { :post => [:id, :title], :comment => [:body] }
|
expected = { post: [:id, :title], comment: [:body] }
|
||||||
|
|
||||||
assert_equal(expected, fieldset.fields)
|
assert_equal(expected, fieldset.fields)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user