embed_in_root is now side_load

This commit is contained in:
Santiago Pastorino 2013-10-24 14:57:41 -02:00
parent d26b7df158
commit 48db253765
7 changed files with 20 additions and 20 deletions

View File

@ -147,7 +147,7 @@ end
included_associations = filter(associations.keys)
associations.each_with_object({}) do |(name, association), hash|
if included_associations.include? name
if association.embed_in_root?
if association.side_load?
hash[association.embedded_key] = serialize association
end
end

View File

@ -8,7 +8,7 @@ module ActiveModel
@name = name.to_s
@options = options
self.embed = options.fetch(:embed) { CONFIG.embed }
@embed_in_root = options.fetch(:include) { CONFIG.include }
@side_load = options.fetch(:include) { CONFIG.include }
@embed_key = options[:embed_key] || :id
@key = options[:key]
@embedded_key = options[:root] || name
@ -17,10 +17,10 @@ module ActiveModel
end
attr_reader :name, :embed_ids, :embed_objects, :serializer_class
attr_accessor :embed_in_root, :embed_key, :key, :embedded_key, :options
attr_accessor :side_load, :embed_key, :key, :embedded_key, :options
alias embed_ids? embed_ids
alias embed_objects? embed_objects
alias embed_in_root? embed_in_root
alias side_load? side_load
def serializer_class=(serializer)
@serializer_class = serializer.is_a?(String) ? serializer.constantize : serializer

View File

@ -63,7 +63,7 @@ module ActiveModel
ARPostSerializer._associations.each_value do |association|
association.embed = options[:embed]
association.embed_in_root = options[:include]
association.side_load = options[:include]
end
yield

View File

@ -75,7 +75,7 @@ module ActiveModel
assert association.embed_ids?
assert !association.embed_objects?
assert association.embed_in_root
assert association.side_load
ensure
PostSerializer._associations[:comments] = old_association
CONFIG.clear

View File

@ -25,7 +25,7 @@ module ActiveModel
@association = PostSerializer._associations[:comments]
@old_association = @association.dup
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
@post = Post.new({ title: 'Title 1', body: 'Body 1', date: '1/1/2000' })
@post_serializer = PostSerializer.new(@post)
@post_serializer.instance_eval do

View File

@ -86,7 +86,7 @@ module ActiveModel
def test_associations_embedding_ids_including_objects_serialization_using_serializable_hash
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
assert_equal({
title: 'Title 1', body: 'Body 1', 'comment_ids' => @post.comments.map { |c| c.object_id }
@ -95,7 +95,7 @@ module ActiveModel
def test_associations_embedding_ids_including_objects_serialization_using_as_json
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
assert_equal({
'post' => { title: 'Title 1', body: 'Body 1', 'comment_ids' => @post.comments.map { |c| c.object_id } },
@ -105,7 +105,7 @@ module ActiveModel
def test_associations_embedding_nothing_including_objects_serialization_using_as_json
@association.embed = nil
@association.embed_in_root = true
@association.side_load = true
assert_equal({
'post' => { title: 'Title 1', body: 'Body 1' },
@ -115,7 +115,7 @@ module ActiveModel
def test_associations_using_a_given_serializer
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
@association.serializer_class = Class.new(ActiveModel::Serializer) do
def content
'fake'

View File

@ -99,7 +99,7 @@ module ActiveModel
def test_associations_embedding_ids_including_objects_serialization_using_serializable_hash
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
assert_equal({
name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id
@ -108,7 +108,7 @@ module ActiveModel
def test_associations_embedding_ids_including_objects_serialization_using_as_json
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
assert_equal({
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id },
@ -118,7 +118,7 @@ module ActiveModel
def test_associations_using_a_given_serializer
@association.embed = :ids
@association.embed_in_root = true
@association.side_load = true
@association.serializer_class = Class.new(ActiveModel::Serializer) do
def name
'fake'