Skip to content

Conditional relationship should not be included #91

Open

Description

@dush

When rendering document with conditional relationship which is not be rendered it is still rendered in included documents.

require 'spec_helper'

describe JSONAPI::Serializable::Renderer, '#render_relationship' do
  let(:posts) { [Post.new(id: 1), Post.new(id: 2)] }
  let(:user) do
    User.new(id: 'foo', name: 'Lucas', address: '22 Ruby drive', posts: posts)
  end

  it 'does not render included conditional relationship' do
    klass = Class.new(JSONAPI::Serializable::Resource) do
      extend JSONAPI::Serializable::Resource::ConditionalFields
      type 'users'

      has_many :posts, if: -> { false }
    end
    hash = subject.render(user,
                          include: [:posts],
                          class: { User: klass, Post: SerializablePost })

    expect(hash).not_to have_key(:included)
  end
end

Activity

  1. beauby commented on Nov 16, 2017

    @beauby
    Member

    Thanks for bringing this up @dush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions