mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Rubocop: Consistent spacing
This commit is contained in:
parent
bdfe13c527
commit
228cc1c92a
@ -1,5 +1,6 @@
|
||||
# This configuration was generated by `rubocop --auto-gen-config`
|
||||
# on 2015-08-30 23:03:50 -0500 using RuboCop version 0.31.0.
|
||||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config`
|
||||
# on 2015-08-31 04:23:33 -0500 using RuboCop version 0.33.0.
|
||||
# The point is for the user to remove these configuration records
|
||||
# one by one as the offenses are removed from the code base.
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
@ -8,67 +9,74 @@
|
||||
# Offense count: 1
|
||||
# Configuration parameters: AllowSafeAssignment.
|
||||
Lint/AssignmentInCondition:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/adapter/json_api.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Lint/EmptyEnsure:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/serializers/adapter_for_test.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Lint/HandleExceptions:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'Rakefile'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Lint/UnusedBlockArgument:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Lint/UnusedMethodArgument:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/adapter.rb'
|
||||
- 'lib/active_model/serializer/adapter/null.rb'
|
||||
- 'lib/active_model/serializer/pass_through_serializer.rb'
|
||||
- 'test/fixtures/poro.rb'
|
||||
- 'test/lint_test.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Lint/UselessAccessModifier:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializable_resource.rb'
|
||||
|
||||
# Offense count: 3
|
||||
Lint/UselessAssignment:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'bench/perf.rb'
|
||||
- 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
|
||||
- 'test/test_helper.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Rails/Date:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/fixtures/poro.rb'
|
||||
|
||||
# Offense count: 8
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Rails/TimeZone:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AccessModifierIndentation:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/action_controller/serialization_test.rb'
|
||||
- 'test/fixtures/poro.rb'
|
||||
- 'test/serializers/cache_test.rb'
|
||||
|
||||
# Offense count: 16
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
||||
Style/AlignHash:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AlignParameters:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/action_controller/json_api/pagination_test.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AndOr:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/lint.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
@ -80,63 +88,51 @@ Style/BlockDelimiters:
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/BracesAroundHashParameters:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/action_controller/adapter_selector_test.rb'
|
||||
- 'test/action_controller/json_api/pagination_test.rb'
|
||||
- 'test/action_controller/serialization_test.rb'
|
||||
- 'test/adapter/json_api/linked_test.rb'
|
||||
- 'test/adapter/json_api/pagination_links_test.rb'
|
||||
- 'test/adapter/null_test.rb'
|
||||
- 'test/adapter_test.rb'
|
||||
- 'test/array_serializer_test.rb'
|
||||
- 'test/serializable_resource_test.rb'
|
||||
- 'test/serializers/associations_test.rb'
|
||||
- 'test/serializers/attribute_test.rb'
|
||||
- 'test/serializers/attributes_test.rb'
|
||||
- 'test/serializers/fieldset_test.rb'
|
||||
- 'test/serializers/root_test.rb'
|
||||
- 'test/serializers/urls_test.rb'
|
||||
|
||||
# Offense count: 167
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/ClassAndModuleChildren:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
Style/CommentIndentation:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'active_model_serializers.gemspec'
|
||||
|
||||
# Offense count: 1
|
||||
Style/DoubleNegation:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializable_resource.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Style/EachWithObject:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLines:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLinesAroundAccessModifier:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/EmptyLinesAroundBlockBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 16
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/EmptyLinesAroundClassBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLinesAroundMethodBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/EmptyLinesAroundModuleBody:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/fieldset.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer.rb'
|
||||
- 'lib/active_model/serializer/adapter/json_api.rb'
|
||||
- 'test/capture_warnings.rb'
|
||||
|
||||
# Offense count: 12
|
||||
# Cop supports --auto-correct.
|
||||
@ -147,7 +143,11 @@ Style/HashSyntax:
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Style/IndentArray:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/adapter/json/has_many_test.rb'
|
||||
- 'test/adapter/json_api/json_api_test.rb'
|
||||
- 'test/adapter/json_api/pagination_links_test.rb'
|
||||
- 'test/adapter/json_test.rb'
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
@ -159,23 +159,29 @@ Style/IndentHash:
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/IndentationConsistency:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/action_controller/serialization_scope_name_test.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Width.
|
||||
Style/IndentationWidth:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializable_resource.rb'
|
||||
- 'lib/active_model/serializer/fieldset.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/Lambda:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/MethodCallParentheses:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/adapter/json.rb'
|
||||
- 'lib/active_model/serializer/adapter/json_api.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
@ -192,12 +198,14 @@ Style/MultilineOperationIndentation:
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/NegatedIf:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/action_controller/serialization.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
|
||||
Style/Next:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/adapter/json_api.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
@ -208,95 +216,56 @@ Style/NumericLiterals:
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: PreferredDelimiters.
|
||||
Style/PercentLiteralDelimiters:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'active_model_serializers.gemspec'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/PerlBackrefs:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/fixtures/poro.rb'
|
||||
- 'test/serializers/associations_test.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
||||
Style/PredicateName:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/adapter.rb'
|
||||
- 'lib/active_model/serializer/adapter/json_api.rb'
|
||||
- 'lib/active_model/serializer/associations.rb'
|
||||
- 'test/action_controller/json_api/linked_test.rb'
|
||||
|
||||
# Offense count: 7
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantSelf:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer.rb'
|
||||
- 'lib/active_model/serializer/associations.rb'
|
||||
- 'test/fixtures/poro.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowAsExpressionSeparator.
|
||||
Style/Semicolon:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/fieldset.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/SignalException:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer.rb'
|
||||
- 'lib/active_model/serializer/adapter.rb'
|
||||
- 'lib/active_model/serializer/fieldset.rb'
|
||||
- 'lib/active_model/serializer/pass_through_serializer.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowIfMethodIsEmpty.
|
||||
Style/SingleLineMethods:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 26
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceAfterColon:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 7
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceAfterComma:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceAfterNot:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/SpaceAroundEqualsInParameterDefault:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 39
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: MultiSpaceAllowedForOperators.
|
||||
Style/SpaceAroundOperators:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/SpaceBeforeBlockBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
||||
Style/SpaceInsideBlockBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 20
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceInsideBrackets:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 179
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
||||
Style/SpaceInsideHashLiteralBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceInsideParens:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/serializers/serializer_for_test.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
@ -306,42 +275,41 @@ Style/StringLiteralsInInterpolation:
|
||||
|
||||
# Offense count: 1
|
||||
Style/StructInheritance:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'bench/perf.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoredMethods.
|
||||
Style/SymbolProc:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/generators/serializer/serializer_generator.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/TrailingBlankLines:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer/pass_through_serializer.rb'
|
||||
- 'lib/generators/serializer/serializer_generator.rb'
|
||||
- 'test/adapter/fragment_cache_test.rb'
|
||||
- 'test/adapter/json_api/json_api_test.rb'
|
||||
- 'test/adapter/null_test.rb'
|
||||
- 'test/serializers/cache_test.rb'
|
||||
- 'test/serializers/fieldset_test.rb'
|
||||
- 'test/support/stream_capture.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
||||
Style/TrailingComma:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/TrailingWhitespace:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'test/action_controller/adapter_selector_test.rb'
|
||||
- 'test/action_controller/serialization_test.rb'
|
||||
- 'test/adapter/json_api/belongs_to_test.rb'
|
||||
- 'test/adapter/json_api/linked_test.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Style/UnlessElse:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/UnneededPercentQ:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: WordRegex.
|
||||
Style/WordArray:
|
||||
MinSize: 2
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer.rb'
|
||||
|
||||
@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
||||
spec.platform = Gem::Platform::RUBY
|
||||
spec.authors = ['Steve Klabnik']
|
||||
spec.email = ['steve@steveklabnik.com']
|
||||
spec.summary = %q{Conventions-based JSON generation for Rails.}
|
||||
spec.description = %q{ActiveModel::Serializers allows you to generate your JSON in an object-oriented and convention-driven manner.}
|
||||
spec.summary = 'Conventions-based JSON generation for Rails.'
|
||||
spec.description = 'ActiveModel::Serializers allows you to generate your JSON in an object-oriented and convention-driven manner.'
|
||||
spec.homepage = 'https://github.com/rails-api/active_model_serializers'
|
||||
spec.license = 'MIT'
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def get_serializer(resource, options = {})
|
||||
if ! use_adapter?
|
||||
if !use_adapter?
|
||||
warn 'ActionController::Serialization#use_adapter? has been removed. '\
|
||||
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource#serialize"
|
||||
options[:adapter] = false
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
require 'set'
|
||||
module ActiveModel
|
||||
class SerializableResource
|
||||
|
||||
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter])
|
||||
|
||||
def initialize(resource, options = {})
|
||||
@ -79,6 +78,5 @@ module ActiveModel
|
||||
ActiveModelSerializers.silence_warnings do
|
||||
attr_reader :resource, :adapter_opts, :serializer_opts
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -13,7 +13,6 @@ module ActiveModel
|
||||
include Configuration
|
||||
include Associations
|
||||
|
||||
|
||||
# Matches
|
||||
# "c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
|
||||
# AND
|
||||
|
||||
@ -2,7 +2,6 @@ module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
class FragmentCache
|
||||
|
||||
attr_reader :serializer
|
||||
|
||||
def initialize(adapter, serializer, options)
|
||||
@ -35,7 +34,7 @@ module ActiveModel
|
||||
|
||||
def cached_attributes(klass, serializers)
|
||||
attributes = serializer.class._attributes
|
||||
cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject {|attr| klass._cache_except.include?(attr) }
|
||||
cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) }
|
||||
non_cached_attributes = attributes - cached_attributes
|
||||
|
||||
cached_attributes.each do |attribute|
|
||||
@ -60,7 +59,7 @@ module ActiveModel
|
||||
Object.const_set cached, Class.new(ActiveModel::Serializer) unless Object.const_defined?(cached)
|
||||
Object.const_set non_cached, Class.new(ActiveModel::Serializer) unless Object.const_defined?(non_cached)
|
||||
|
||||
klass._cache_options ||= {}
|
||||
klass._cache_options ||= {}
|
||||
klass._cache_options[:key] = klass._cache_key if klass._cache_key
|
||||
|
||||
cached.constantize.cache(klass._cache_options)
|
||||
@ -68,7 +67,7 @@ module ActiveModel
|
||||
cached.constantize.fragmented(serializer)
|
||||
non_cached.constantize.fragmented(serializer)
|
||||
|
||||
serializers = {cached: cached, non_cached: non_cached}
|
||||
serializers = { cached: cached, non_cached: non_cached }
|
||||
cached_attributes(klass, serializers)
|
||||
serializers
|
||||
end
|
||||
|
||||
@ -46,7 +46,6 @@ module ActiveModel
|
||||
def fragment_cache(cached_hash, non_cached_hash)
|
||||
Json::FragmentCache.new().fragment_cache(cached_hash, non_cached_hash)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -4,11 +4,9 @@ module ActiveModel
|
||||
class Adapter
|
||||
class Json < Adapter
|
||||
class FragmentCache
|
||||
|
||||
def fragment_cache(cached_hash, non_cached_hash)
|
||||
non_cached_hash.merge cached_hash
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -50,7 +50,7 @@ module ActiveModel
|
||||
resource[:relationships][name][:data] += serializers.map { |serializer| { type: serializer.json_api_type, id: serializer.id.to_s } }
|
||||
end
|
||||
|
||||
def add_relationship(resource, name, serializer, val=nil)
|
||||
def add_relationship(resource, name, serializer, val = nil)
|
||||
resource[:relationships] ||= {}
|
||||
resource[:relationships][name] = { data: val }
|
||||
|
||||
|
||||
@ -4,19 +4,17 @@ module ActiveModel
|
||||
class Adapter
|
||||
class JsonApi < Adapter
|
||||
class FragmentCache
|
||||
|
||||
def fragment_cache(root, cached_hash, non_cached_hash)
|
||||
hash = {}
|
||||
core_cached = cached_hash.first
|
||||
core_non_cached = non_cached_hash.first
|
||||
no_root_cache = cached_hash.delete_if {|key, value| key == core_cached[0] }
|
||||
no_root_non_cache = non_cached_hash.delete_if {|key, value| key == core_non_cached[0] }
|
||||
no_root_cache = cached_hash.delete_if { |key, value| key == core_cached[0] }
|
||||
no_root_non_cache = non_cached_hash.delete_if { |key, value| key == core_non_cached[0] }
|
||||
cached_resource = (core_cached[1]) ? core_cached[1].deep_merge(core_non_cached[1]) : core_non_cached[1]
|
||||
hash = (root) ? { root => cached_resource } : cached_resource
|
||||
|
||||
hash.deep_merge no_root_non_cache.deep_merge no_root_cache
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,7 +10,6 @@ module ActiveModel
|
||||
# Association.new(:comments, CommentSummarySerializer)
|
||||
#
|
||||
Association = Struct.new(:name, :serializer, :options) do
|
||||
|
||||
# @return [Symbol]
|
||||
#
|
||||
def key
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Fieldset
|
||||
|
||||
def initialize(fields, root = nil)
|
||||
@root = root
|
||||
@raw_fields = fields
|
||||
@ -16,7 +15,7 @@ module ActiveModel
|
||||
fields[key.to_sym] || fields[key.pluralize.to_sym]
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
ActiveModelSerializers.silence_warnings do
|
||||
attr_reader :raw_fields, :root
|
||||
@ -24,7 +23,7 @@ module ActiveModel
|
||||
|
||||
def parsed_fields
|
||||
if raw_fields.is_a?(Hash)
|
||||
raw_fields.inject({}) { |h,(k,v)| h[k.to_sym] = v.map(&:to_sym); h}
|
||||
raw_fields.inject({}) { |h, (k, v)| h[k.to_sym] = v.map(&:to_sym); h }
|
||||
elsif raw_fields.is_a?(Array)
|
||||
if root.nil?
|
||||
raise ArgumentError, 'The root argument must be specified if the fileds argument is an array.'
|
||||
@ -36,7 +35,6 @@ module ActiveModel
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -15,7 +15,6 @@ module ActiveModel::Serializer::Lint
|
||||
# always return +{}+, and the tests would pass. It is up to you to ensure
|
||||
# that the values are semantically meaningful.
|
||||
module Tests
|
||||
|
||||
# Passes if the object responds to <tt>serializable_hash</tt> and if it takes
|
||||
# zero or one arguments.
|
||||
# Fails otherwise.
|
||||
@ -126,6 +125,5 @@ module ActiveModel::Serializer::Lint
|
||||
def assert_instance_of(result, name)
|
||||
assert result.instance_of?(name), "#{result} should be an instance of #{name}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,7 +8,6 @@ module ActiveModelSerializers
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
require 'active_model'
|
||||
|
||||
@ -103,7 +103,7 @@ module ActionController
|
||||
{ 'title' => 'New Post',
|
||||
'body' => 'Body',
|
||||
'id' => assigns(:post).id,
|
||||
'comments' => [{'id' => 1}, {'id' => 2}],
|
||||
'comments' => [{ 'id' => 1 }, { 'id' => 2 }],
|
||||
'author' => { 'id' => assigns(:author).id }
|
||||
}
|
||||
]
|
||||
|
||||
@ -75,7 +75,7 @@ module ActionController
|
||||
|
||||
def render_collection_with_include
|
||||
setup_post
|
||||
render json: [@post], include: ['author', 'comments'], adapter: :json_api
|
||||
render json: [@post], include: %w(author comments), adapter: :json_api
|
||||
end
|
||||
end
|
||||
|
||||
@ -107,7 +107,7 @@ module ActionController
|
||||
},
|
||||
'relationships' => {
|
||||
'posts' => { 'data' => [] },
|
||||
'roles' => { 'data' => [{ 'type' =>'roles', 'id' => '1' }, { 'type' =>'roles', 'id' => '2' }] },
|
||||
'roles' => { 'data' => [{ 'type' => 'roles', 'id' => '1' }, { 'type' => 'roles', 'id' => '2' }] },
|
||||
'bio' => { 'data' => nil }
|
||||
}
|
||||
}, {
|
||||
@ -119,7 +119,7 @@ module ActionController
|
||||
'slug' => 'admin-1'
|
||||
},
|
||||
'relationships' => {
|
||||
'author' => { 'data' => { 'type' =>'authors', 'id' => '1' } }
|
||||
'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
|
||||
}
|
||||
}, {
|
||||
'id' => '2',
|
||||
@ -130,7 +130,7 @@ module ActionController
|
||||
'slug' => 'colab-2'
|
||||
},
|
||||
'relationships' => {
|
||||
'author' => { 'data' => { 'type' =>'authors', 'id' => '1' } }
|
||||
'author' => { 'data' => { 'type' => 'authors', 'id' => '1' } }
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -172,7 +172,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def has_type?(collection, value)
|
||||
collection.detect { |i| i['type'] == value}
|
||||
collection.detect { |i| i['type'] == value }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -47,11 +47,11 @@ module ActionController
|
||||
tests PaginationTestController
|
||||
|
||||
def test_render_pagination_links_with_will_paginate
|
||||
expected_links = { 'self'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1"}
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||
|
||||
get :render_pagination_using_will_paginate, page: { number: 2, size: 1 }
|
||||
response = JSON.parse(@response.body)
|
||||
@ -59,47 +59,47 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_only_last_and_next_pagination_links
|
||||
expected_links = { 'self'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||
'next'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
||||
'last'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2"}
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2" }
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_pagination_links_with_kaminari
|
||||
expected_links = { 'self'=>"#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1"}
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||
get :render_pagination_using_kaminari, page: { number: 2, size: 1 }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_prev_and_first_pagination_links
|
||||
expected_links = { 'self'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'first'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev'=>"#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1"}
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1" }
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_last_and_next_pagination_links_with_additional_params
|
||||
expected_links = { 'self'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||
'next'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
||||
'last'=>"#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional"}
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional" }
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }, teste: 'additional'
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_render_only_prev_and_first_pagination_links_with_additional_params
|
||||
expected_links = { 'self'=>"#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
||||
'first'=>"#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
||||
'prev'=>"#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional"}
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional" }
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }, teste: 'additional'
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
|
||||
@ -48,7 +48,6 @@ module ActionController
|
||||
|
||||
def render_array_using_implicit_serializer_and_meta
|
||||
with_adapter ActiveModel::Serializer::Adapter::JsonApi do
|
||||
|
||||
@profiles = [
|
||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
]
|
||||
@ -69,11 +68,11 @@ module ActionController
|
||||
end
|
||||
|
||||
def render_json_object_without_serializer
|
||||
render json: {error: 'Result is Invalid'}
|
||||
render json: { error: 'Result is Invalid' }
|
||||
end
|
||||
|
||||
def render_json_array_object_without_serializer
|
||||
render json: [{error: 'Result is Invalid'}]
|
||||
render json: [{ error: 'Result is Invalid' }]
|
||||
end
|
||||
|
||||
def update_and_render_object_with_cache_enabled
|
||||
@ -138,6 +137,7 @@ module ActionController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_cached_serializer(obj)
|
||||
ActiveModel::SerializableResource.new(obj).to_json
|
||||
end
|
||||
@ -188,7 +188,7 @@ module ActionController
|
||||
def test_render_array_using_custom_root
|
||||
get :render_array_using_custom_root
|
||||
|
||||
expected = {custom_roots: [{name: 'Name 1', description: 'Description 1'}]}
|
||||
expected = { custom_roots: [{ name: 'Name 1', description: 'Description 1' }] }
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@ -196,7 +196,7 @@ module ActionController
|
||||
def test_render_array_that_is_empty_using_custom_root
|
||||
get :render_array_that_is_empty_using_custom_root
|
||||
|
||||
expected = {custom_roots: []}
|
||||
expected = { custom_roots: [] }
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@ -204,7 +204,7 @@ module ActionController
|
||||
def test_render_object_using_custom_root
|
||||
get :render_object_using_custom_root
|
||||
|
||||
expected = {custom_root: {name: 'Name 1', description: 'Description 1'}}
|
||||
expected = { custom_root: { name: 'Name 1', description: 'Description 1' } }
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@ -213,7 +213,7 @@ module ActionController
|
||||
get :render_json_object_without_serializer
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
expected_body = {error: 'Result is Invalid'}
|
||||
expected_body = { error: 'Result is Invalid' }
|
||||
assert_equal expected_body.to_json, @response.body
|
||||
end
|
||||
|
||||
@ -221,7 +221,7 @@ module ActionController
|
||||
get :render_json_array_object_without_serializer
|
||||
|
||||
assert_equal 'application/json', @response.content_type
|
||||
expected_body = [{error: 'Result is Invalid'}]
|
||||
expected_body = [{ error: 'Result is Invalid' }]
|
||||
assert_equal expected_body.to_json, @response.body
|
||||
end
|
||||
|
||||
@ -357,11 +357,11 @@ module ActionController
|
||||
response = JSON.parse(@response.body)
|
||||
|
||||
expected_return = {
|
||||
'id'=>1,
|
||||
'time'=>Time.now.to_s,
|
||||
'id' => 1,
|
||||
'time' => Time.now.to_s,
|
||||
'likeable' => {
|
||||
'id'=>1,
|
||||
'body'=>'ZOMG A COMMENT'
|
||||
'id' => 1,
|
||||
'body' => 'ZOMG A COMMENT'
|
||||
}
|
||||
}
|
||||
|
||||
@ -384,7 +384,7 @@ module ActionController
|
||||
body: 'ZOMG A COMMENT' }
|
||||
],
|
||||
blog: {
|
||||
id:999,
|
||||
id: 999,
|
||||
name: 'Custom blog'
|
||||
},
|
||||
author: {
|
||||
|
||||
@ -6,7 +6,7 @@ module ActiveModel
|
||||
def setup
|
||||
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
||||
@author = Author.new(name: 'Joao M. D. Moura')
|
||||
@role = Role.new(name: 'Great Author', description:nil)
|
||||
@role = Role.new(name: 'Great Author', description: nil)
|
||||
@role.author = [@author]
|
||||
@role_serializer = RoleSerializer.new(@role)
|
||||
@spam_serializer = Spam::UnrelatedLinkSerializer.new(@spam)
|
||||
|
||||
@ -24,21 +24,21 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_includes_post
|
||||
assert_equal({id: 42, title: 'New Post', body: 'Body'}, @adapter.serializable_hash[:comment][:post])
|
||||
assert_equal({ id: 42, title: 'New Post', body: 'Body' }, @adapter.serializable_hash[:comment][:post])
|
||||
end
|
||||
|
||||
def test_include_nil_author
|
||||
serializer = PostSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({post: {title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], blog: {id: 999, name: 'Custom blog'}, author: nil}}, adapter.serializable_hash)
|
||||
assert_equal({ post: { title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], blog: { id: 999, name: 'Custom blog' }, author: nil } }, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_include_nil_author_with_specified_serializer
|
||||
serializer = PostPreviewSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({post: {title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], author: nil}}, adapter.serializable_hash)
|
||||
assert_equal({ post: { title: 'Hello!!', body: 'Hello, world!!', id: 43, comments: [], author: nil } }, adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -26,11 +26,11 @@ module ActiveModel
|
||||
serializer = ArraySerializer.new([@blog], serializer: CustomBlogSerializer)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
expected = {blogs:[{
|
||||
expected = { blogs: [{
|
||||
id: 1,
|
||||
special_attribute: 'Special',
|
||||
articles: [{id: 1,title: 'Hello!!', body: 'Hello, world!!'}, {id: 2, title: 'New Post', body: 'Body'}]
|
||||
}]}
|
||||
articles: [{ id: 1, title: 'Hello!!', body: 'Hello, world!!' }, { id: 2, title: 'New Post', body: 'Body' }]
|
||||
}] }
|
||||
assert_equal expected, adapter.serializable_hash
|
||||
end
|
||||
|
||||
@ -64,7 +64,7 @@ module ActiveModel
|
||||
id: 999,
|
||||
name: 'Custom blog'
|
||||
}
|
||||
}]}
|
||||
}] }
|
||||
assert_equal expected, adapter.serializable_hash
|
||||
end
|
||||
|
||||
|
||||
@ -25,8 +25,8 @@ module ActiveModel
|
||||
serializer = PostSerializer.new(@post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
assert_equal([
|
||||
{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
], adapter.serializable_hash[:post][:comments])
|
||||
end
|
||||
|
||||
@ -36,7 +36,7 @@ module ActiveModel
|
||||
assert_equal({
|
||||
id: 42,
|
||||
tags: [
|
||||
{'attributes'=>{'id'=>1, 'name'=>'#hash_tag'}}
|
||||
{ 'attributes' => { 'id' => 1, 'name' => '#hash_tag' } }
|
||||
]
|
||||
}.to_json, adapter.serializable_hash[:post].to_json)
|
||||
end
|
||||
|
||||
@ -47,7 +47,7 @@ module ActiveModel
|
||||
body: 'Body',
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@ -56,7 +56,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_limiting_linked_post_fields
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'post', fields: {post: [:title]})
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'post', fields: { post: [:title] })
|
||||
expected = [{
|
||||
id: '42',
|
||||
type: 'posts',
|
||||
@ -64,7 +64,7 @@ module ActiveModel
|
||||
title: 'New Post'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@ -76,7 +76,7 @@ module ActiveModel
|
||||
serializer = PostSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
|
||||
assert_equal({comments: { data: [] }, blog: { data: { type: 'blogs', id: '999' } }, author: { data: nil }}, adapter.serializable_hash[:data][:relationships])
|
||||
assert_equal({ comments: { data: [] }, blog: { data: { type: 'blogs', id: '999' } }, author: { data: nil } }, adapter.serializable_hash[:data][:relationships])
|
||||
end
|
||||
|
||||
def test_include_type_for_association_when_different_than_name
|
||||
@ -108,7 +108,7 @@ module ActiveModel
|
||||
|
||||
def test_include_linked_resources_with_type_name
|
||||
serializer = BlogSerializer.new(@blog)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer, include: ['writer', 'articles'])
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer, include: %w(writer articles))
|
||||
linked = adapter.serializable_hash[:included]
|
||||
expected = [
|
||||
{
|
||||
@ -122,7 +122,7 @@ module ActiveModel
|
||||
roles: { data: [] },
|
||||
bio: { data: nil }
|
||||
}
|
||||
},{
|
||||
}, {
|
||||
id: '42',
|
||||
type: 'posts',
|
||||
attributes: {
|
||||
@ -130,7 +130,7 @@ module ActiveModel
|
||||
body: 'Body'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
|
||||
@ -88,7 +88,6 @@ module ActiveModel
|
||||
]
|
||||
assert_equal(expected, @adapter.serializable_hash[:data])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -27,8 +27,8 @@ module ActiveModel
|
||||
def test_includes_comment_ids
|
||||
expected = {
|
||||
data: [
|
||||
{ type: 'posts', id: '1'},
|
||||
{ type: 'posts', id: '2'}
|
||||
{ type: 'posts', id: '1' },
|
||||
{ type: 'posts', id: '2' }
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ module ActiveModel
|
||||
@serializer = PostPreviewSerializer.new(@post)
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(
|
||||
@serializer,
|
||||
include: ['comments', 'author']
|
||||
include: %w(comments author)
|
||||
)
|
||||
end
|
||||
|
||||
@ -60,7 +60,7 @@ module ActiveModel
|
||||
id: @author.id.to_s,
|
||||
type: 'authors',
|
||||
relationships: {
|
||||
posts: { data: [ {type: 'posts', id: @post.id.to_s } ] }
|
||||
posts: { data: [{ type: 'posts', id: @post.id.to_s }] }
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@ -36,7 +36,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_includes_comment_ids
|
||||
expected = { data: [ { type: 'comments', id: '1' }, { type: 'comments', id: '2' } ] }
|
||||
expected = { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] }
|
||||
|
||||
assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:comments])
|
||||
end
|
||||
@ -68,7 +68,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_limit_fields_of_linked_comments
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments', fields: {comment: [:id]})
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments', fields: { comment: [:id] })
|
||||
expected = [{
|
||||
id: '1',
|
||||
type: 'comments',
|
||||
@ -117,7 +117,7 @@ module ActiveModel
|
||||
id: '1',
|
||||
type: 'posts',
|
||||
relationships: {
|
||||
tags: { data: [@tag.as_json]}
|
||||
tags: { data: [@tag.as_json] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
@ -132,8 +132,8 @@ module ActiveModel
|
||||
id: '1',
|
||||
type: 'virtual_values',
|
||||
relationships: {
|
||||
maker: {data: {id: 1}},
|
||||
reviews: {data: [{id: 1}, {id: 2}]}
|
||||
maker: { data: { id: 1 } },
|
||||
reviews: { data: [{ id: 1 }, { id: 2 }] }
|
||||
}
|
||||
}
|
||||
}, adapter.serializable_hash)
|
||||
|
||||
@ -45,7 +45,7 @@ module ActiveModel
|
||||
id: '43',
|
||||
type: 'bios',
|
||||
attributes: {
|
||||
content:'AMS Contributor',
|
||||
content: 'AMS Contributor',
|
||||
rating: nil
|
||||
},
|
||||
relationships: {
|
||||
@ -66,8 +66,8 @@ module ActiveModel
|
||||
id: '1',
|
||||
type: 'virtual_values',
|
||||
relationships: {
|
||||
maker: {data: {id: 1}},
|
||||
reviews: {data: [{id: 1}, {id: 2}]}
|
||||
maker: { data: { id: 1 } },
|
||||
reviews: { data: [{ id: 1 }, { id: 2 }] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ module ActiveModel
|
||||
@post.author = @author
|
||||
@blog = Blog.new(id: 1, name: 'My Blog!!')
|
||||
@post.blog = @blog
|
||||
|
||||
end
|
||||
|
||||
def test_custom_keys
|
||||
@ -25,11 +24,11 @@ module ActiveModel
|
||||
|
||||
assert_equal({
|
||||
reviews: { data: [
|
||||
{type: 'comments', id: '1'},
|
||||
{type: 'comments', id: '2'}
|
||||
]},
|
||||
writer: { data: {type: 'authors', id: '1'} },
|
||||
site: { data: {type: 'blogs', id: '1' } }
|
||||
{ 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
|
||||
|
||||
@ -60,7 +60,7 @@ module ActiveModel
|
||||
body: 'Hello, world!!'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' }, { type: 'comments', id: '2' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@ -107,7 +107,7 @@ module ActiveModel
|
||||
name: 'Steve K.'
|
||||
},
|
||||
relationships: {
|
||||
posts: { data: [ { type: 'posts', id: '10' }, { type: 'posts', id: '30' } ] },
|
||||
posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
|
||||
roles: { data: [] },
|
||||
bio: { data: { type: 'bios', id: '1' } }
|
||||
}
|
||||
@ -128,7 +128,7 @@ module ActiveModel
|
||||
name: 'Tenderlove'
|
||||
},
|
||||
relationships: {
|
||||
posts: { data: [ { type: 'posts', id:'20' } ] },
|
||||
posts: { data: [{ type: 'posts', id: '20' }] },
|
||||
roles: { data: [] },
|
||||
bio: { data: { type: 'bios', id: '2' } }
|
||||
}
|
||||
@ -168,9 +168,9 @@ module ActiveModel
|
||||
name: 'Steve K.'
|
||||
},
|
||||
relationships: {
|
||||
posts: { data: [ { type: 'posts', id: '10'}, { type: 'posts', id: '30' }] },
|
||||
posts: { data: [{ type: 'posts', id: '10' }, { type: 'posts', id: '30' }] },
|
||||
roles: { data: [] },
|
||||
bio: { data: { type: 'bios', id: '1' }}
|
||||
bio: { data: { type: 'bios', id: '1' } }
|
||||
}
|
||||
}, {
|
||||
id: '10',
|
||||
@ -180,7 +180,7 @@ module ActiveModel
|
||||
body: 'Hello, world!!'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1'}, { type: 'comments', id: '2' }] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
||||
blog: { data: { type: 'blogs', id: '999' } },
|
||||
author: { data: { type: 'authors', id: '1' } }
|
||||
}
|
||||
@ -237,13 +237,13 @@ module ActiveModel
|
||||
},
|
||||
relationships: {
|
||||
comments: {
|
||||
data: [{type: 'comments', id: '1'}, {type: 'comments', id: '2'}]
|
||||
data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }]
|
||||
},
|
||||
blog: {
|
||||
data: {type: 'blogs', id: '999'}
|
||||
data: { type: 'blogs', id: '999' }
|
||||
},
|
||||
author: {
|
||||
data: {type: 'authors', id: '1'}
|
||||
data: { type: 'authors', id: '1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -269,7 +269,7 @@ module ActiveModel
|
||||
body: 'Hello, world!!'
|
||||
},
|
||||
relationships: {
|
||||
comments: { data: [ { type: 'comments', id: '1' }, { type: 'comments', id: '2' } ] },
|
||||
comments: { data: [{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
|
||||
author: { data: nil }
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,9 +20,9 @@ module ActiveModel
|
||||
]
|
||||
end
|
||||
|
||||
def mock_request(query_parameters={}, original_url=URI)
|
||||
def mock_request(query_parameters = {}, original_url = URI)
|
||||
context = Minitest::Mock.new
|
||||
context.expect(:original_url, original_url )
|
||||
context.expect(:original_url, original_url)
|
||||
context.expect(:query_parameters, query_parameters)
|
||||
@options = {}
|
||||
@options[:context] = context
|
||||
@ -42,17 +42,17 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def data
|
||||
{ data:[
|
||||
{ id:'1', type:'profiles', attributes:{name:'Name 1', description:'Description 1' } },
|
||||
{ id:'2', type:'profiles', attributes:{name:'Name 2', description:'Description 2' } },
|
||||
{ id:'3', type:'profiles', attributes:{name:'Name 3', description:'Description 3' } }
|
||||
{ data: [
|
||||
{ id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } },
|
||||
{ id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } },
|
||||
{ id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } }
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def links
|
||||
{
|
||||
links:{
|
||||
links: {
|
||||
self: "#{URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||
first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
prev: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
@ -74,7 +74,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def expected_response_with_pagination_links_and_additional_params
|
||||
new_links = links[:links].each_with_object({}) {|(key, value), hash| hash[key] = "#{value}&test=test" }
|
||||
new_links = links[:links].each_with_object({}) { |(key, value), hash| hash[key] = "#{value}&test=test" }
|
||||
{}.tap do |hash|
|
||||
hash[:data] = [data.values.flatten.second]
|
||||
hash.merge! links: new_links
|
||||
|
||||
@ -23,8 +23,8 @@ module ActiveModel
|
||||
|
||||
def test_has_many
|
||||
assert_equal([
|
||||
{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
{ id: 1, body: 'ZOMG A COMMENT' },
|
||||
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
||||
], @adapter.serializable_hash[:post][:comments])
|
||||
end
|
||||
|
||||
@ -34,11 +34,11 @@ module ActiveModel
|
||||
|
||||
assert_equal({
|
||||
id: 1,
|
||||
reviews: [{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
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!!'}
|
||||
writer: { id: 1, name: 'Steve K.' },
|
||||
site: { id: 1, name: 'My Blog!!' }
|
||||
}, adapter.serializable_hash[:post])
|
||||
end
|
||||
end
|
||||
|
||||
@ -35,12 +35,12 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_create_adapter_with_override
|
||||
adapter = ActiveModel::Serializer::Adapter.create(@serializer, { adapter: :json_api})
|
||||
adapter = ActiveModel::Serializer::Adapter.create(@serializer, { adapter: :json_api })
|
||||
assert_equal ActiveModel::Serializer::Adapter::JsonApi, adapter.class
|
||||
end
|
||||
|
||||
def test_inflected_adapter_class_for_known_adapter
|
||||
ActiveSupport::Inflector.inflections(:en){|inflect| inflect.acronym 'API' }
|
||||
ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.acronym 'API' }
|
||||
klass = ActiveModel::Serializer::Adapter.adapter_class(:json_api)
|
||||
|
||||
ActiveSupport::Inflector.inflections.acronyms.clear
|
||||
|
||||
@ -7,11 +7,11 @@ module ActiveModel
|
||||
@comment = Comment.new
|
||||
@post = Post.new
|
||||
@resource = build_named_collection @comment, @post
|
||||
@serializer = ArraySerializer.new(@resource, {some: :options})
|
||||
@serializer = ArraySerializer.new(@resource, { some: :options })
|
||||
end
|
||||
|
||||
def build_named_collection(*resource)
|
||||
resource.define_singleton_method(:name){ 'MeResource' }
|
||||
resource.define_singleton_method(:name) { 'MeResource' }
|
||||
resource
|
||||
end
|
||||
|
||||
@ -36,13 +36,13 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_serializer_option_not_passed_to_each_serializer
|
||||
serializers = ArraySerializer.new([@post], {serializer: PostSerializer}).to_a
|
||||
serializers = ArraySerializer.new([@post], { serializer: PostSerializer }).to_a
|
||||
|
||||
refute serializers.first.custom_options.key?(:serializer)
|
||||
end
|
||||
|
||||
def test_meta_and_meta_key_attr_readers
|
||||
meta_content = {meta: 'the meta', meta_key: 'the meta key'}
|
||||
meta_content = { meta: 'the meta', meta_key: 'the meta key' }
|
||||
@serializer = ArraySerializer.new([@comment, @post], meta_content)
|
||||
|
||||
assert_equal @serializer.meta, 'the meta'
|
||||
@ -77,7 +77,7 @@ module ActiveModel
|
||||
|
||||
def test_json_key_with_resource_with_nil_name_and_no_serializers
|
||||
resource = []
|
||||
resource.define_singleton_method(:name){ nil }
|
||||
resource.define_singleton_method(:name) { nil }
|
||||
serializer = ArraySerializer.new(resource)
|
||||
assert_equal serializer.json_key, nil
|
||||
end
|
||||
|
||||
@ -53,5 +53,6 @@ class CaptureWarnings
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :stderr_file, :app_root, :output_dir, :bundle_dir, :fail_on_warnings
|
||||
end
|
||||
|
||||
10
test/fixtures/poro.rb
vendored
10
test/fixtures/poro.rb
vendored
@ -7,7 +7,7 @@ class Model
|
||||
@_model_name ||= ActiveModel::Name.new(self)
|
||||
end
|
||||
|
||||
def initialize(hash={})
|
||||
def initialize(hash = {})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
@ -94,7 +94,7 @@ module Spam; end
|
||||
Spam::UnrelatedLink = Class.new(Model)
|
||||
|
||||
PostSerializer = Class.new(ActiveModel::Serializer) do
|
||||
cache key:'post', expires_in: 0.1, skip_digest: true
|
||||
cache key: 'post', expires_in: 0.1, skip_digest: true
|
||||
attributes :id, :title, :body
|
||||
|
||||
has_many :comments
|
||||
@ -133,7 +133,7 @@ CommentSerializer = Class.new(ActiveModel::Serializer) do
|
||||
end
|
||||
|
||||
AuthorSerializer = Class.new(ActiveModel::Serializer) do
|
||||
cache key:'writer', skip_digest: true
|
||||
cache key: 'writer', skip_digest: true
|
||||
attribute :id
|
||||
attribute :name
|
||||
|
||||
@ -249,8 +249,8 @@ end
|
||||
VirtualValueSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id
|
||||
|
||||
has_many :reviews, virtual_value: [{id: 1}, {id: 2}]
|
||||
has_one :maker, virtual_value: {id: 1}
|
||||
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
|
||||
has_one :maker, virtual_value: { id: 1 }
|
||||
|
||||
def reviews
|
||||
end
|
||||
|
||||
@ -7,27 +7,21 @@ module ActiveModel
|
||||
|
||||
class CompliantResource
|
||||
def serializable_hash(options = nil)
|
||||
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
|
||||
end
|
||||
|
||||
def as_json(options = nil)
|
||||
|
||||
end
|
||||
|
||||
def to_json(options = nil)
|
||||
|
||||
end
|
||||
|
||||
def cache_key
|
||||
|
||||
end
|
||||
|
||||
def id
|
||||
|
||||
end
|
||||
|
||||
def self.model_name
|
||||
@ -38,7 +32,6 @@ module ActiveModel
|
||||
def setup
|
||||
@resource = CompliantResource.new
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -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' })
|
||||
|
||||
@ -13,7 +13,6 @@ require 'minitest/autorun'
|
||||
# Ensure backward compatibility with Minitest 4
|
||||
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
||||
|
||||
|
||||
require 'capture_warnings'
|
||||
@capture_warnings = CaptureWarnings.new(fail_build = true)
|
||||
@capture_warnings.before_tests
|
||||
|
||||
Loading…
Reference in New Issue
Block a user