require 'spec_helper'

describe Users::OrderSerializer, 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
    list = List.find(l.id)
    orders = list.orders.include_relation(:product_orders)
    #expect{ object_as_json orders }.not_to exceed_query_limit 0
    result = nil
    expect{ result = described_class.serialize(orders, include: 'product_orders', is_collection: true).deep_symbolize_keys }.not_to perform_any_queries
    result[:included].size.should eq 4
  end

end
