Sort OC report orders by completed_at

This is then consistent with the ordering we use to list orders in
/admin, which is more useful. As a result, the test is also more robust.
This commit is contained in:
Pau Perez
2021-02-16 13:25:21 +01:00
parent cbfea1ba97
commit 36ce39a217
2 changed files with 4 additions and 5 deletions

View File

@@ -65,7 +65,7 @@ module OpenFoodNetwork
def orders
if FeatureToggle.enabled?(:customer_balance, @user)
search_result = search.result.order(:id)
search_result = search.result.order(:completed_at)
orders_with_balance = OutstandingBalance.new(search_result).
query.
select('spree_orders.*')

View File

@@ -43,11 +43,10 @@ module OpenFoodNetwork
end
it 'orders them by id' do
result = instance_double(ActiveRecord::Relation)
allow_any_instance_of(Ransack::Search).to receive(:result).and_return(result)
expect(result).to receive(:order).with(:id) { Spree::Order.none }
order1 = create(:order, completed_at: 1.day.ago, state: 'complete')
order2 = create(:order, completed_at: 2.days.ago, state: 'complete')
subject.orders
expect(subject.orders.pluck(:id)).to eq([order2.id, order1.id])
end
end