Sha256: 357e057cd09e9c1ea5cf4626d8515b2d19f11f473e58ff0afc2773887590b4bf

Contents?: true

Size: 1.31 KB

Versions: 11

Compression:

Stored size: 1.31 KB

Contents

require 'test_helper'

module ActiveModelSerializers
  module Adapter
    class JsonApi
      class HasManyEmbedIdsTest < ActiveSupport::TestCase
        def setup
          @author = Author.new(name: 'Steve K.')
          @author.bio = nil
          @author.roles = nil
          @first_post = Post.new(id: 1, title: 'Hello!!', body: 'Hello, world!!')
          @second_post = Post.new(id: 2, title: 'New Post', body: 'Body')
          @author.posts = [@first_post, @second_post]
          @first_post.author = @author
          @second_post.author = @author
          @first_post.comments = []
          @second_post.comments = []
          @blog = Blog.new(id: 23, name: 'AMS Blog')
          @first_post.blog = @blog
          @second_post.blog = nil

          @serializer = AuthorSerializer.new(@author)
          @adapter = ActiveModelSerializers::Adapter::JsonApi.new(@serializer)
        end

        def test_includes_comment_ids
          expected = {
            data: [
              { type: 'posts', id: '1' },
              { type: 'posts', id: '2' }
            ]
          }

          assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:posts])
        end

        def test_no_includes_linked_comments
          assert_nil @adapter.serializable_hash[:linked]
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
active_model_serializers-0.10.6 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.5 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.4 test/adapter/json_api/has_many_embed_ids_test.rb
agi_active_model_serializers-0.10.9 test/adapter/json_api/has_many_embed_ids_test.rb
agi_active_model_serializers-0.10.8 test/adapter/json_api/has_many_embed_ids_test.rb
agi_active_model_serializers-0.10.7 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.3 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.2 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.1 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.0 test/adapter/json_api/has_many_embed_ids_test.rb
active_model_serializers-0.10.0.rc5 test/adapter/json_api/has_many_embed_ids_test.rb