jsonapi-serializable icon indicating copy to clipboard operation
jsonapi-serializable copied to clipboard

Conditional relationship should not be included

Open dush opened this issue 8 years ago • 1 comments

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

dush avatar Nov 08 '17 12:11 dush

Thanks for bringing this up @dush.

beauby avatar Nov 16 '17 11:11 beauby