Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional relationship should not be included #91

Open
dush opened this issue Nov 8, 2017 · 1 comment
Open

Conditional relationship should not be included #91

dush opened this issue Nov 8, 2017 · 1 comment
Labels

Comments

@dush
Copy link

dush commented Nov 8, 2017

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
@beauby beauby added the bug label Nov 16, 2017
@beauby
Copy link
Member

beauby commented Nov 16, 2017

Thanks for bringing this up @dush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants