require 'spec_helper'

describe Users::ListSerializer, type: :serializer do
  it "does not perform extra queries" do
    l = create :list
    o1 = create :order, list: l
    create :product_order, order: o1
    create :product_order, order: o1
    o2 = create :order, list: l
    create :product_order, order: o2
    create :product_order, order: o2
    l.add_user create :user
    l.add_user create :user
    list = List.find(l.id)
    list.users # cache users
    result = nil
    #result = expect{ JSONAPI::Serializer.serialize(list, serializer: described_class) }.not_to perform_any_queries
    expect{ result = described_class.serialize(list, include: %w[supplier users]) }.not_to exceed_query_limit 1 # supplier
  end

end
