Potential fix for one of the issues mentioned in #49

Reduces the number of SQL queries used on group_orders/index and
group_orders/archive, but adds extra  complexity to the code
This commit is contained in:
Florian Lentsch 2020-07-12 10:26:36 +02:00 committed by Patrick Gansterer
parent 602f663245
commit 5eb8abf431
7 changed files with 45 additions and 9 deletions

View file

@ -83,4 +83,21 @@ describe Order do
end
describe 'mapped to GroupOrders' do
let!(:user) { create :user, groups: [create(:ordergroup)] }
let!(:order) { create :order }
let!(:order2) { create :order }
let!(:go) { create :group_order, order: order, ordergroup: user.ordergroup }
it 'to map a user\'s GroupOrders to a list of Orders' do
orders = Order.ordergroup_group_orders_map(user.ordergroup)
expect(orders.length).to be 2
expect(orders[0][:order]).to have_attributes(id: order.id)
expect(orders[0][:group_order]).to have_attributes(id: go.id)
expect(orders[1][:order]).to have_attributes(id: order2.id)
expect(orders[1][:group_order]).to be_nil
end
end
end