Ensure report rows are always in the same order

I saw the row were returned not respecting any ordering when refreshing
the page locally. It made it hard to debug whether or not the customer
balance was right.

It's less than ideal to use `allow_any_instance_of` but with this legacy
and very coupled code, it's the best we can do.
This commit is contained in:
Pau Perez
2021-02-08 15:45:07 +01:00
parent ed1c1e5607
commit 412bb24e42
2 changed files with 9 additions and 1 deletions

View File

@@ -48,7 +48,7 @@ module OpenFoodNetwork
end
def orders
filter search.result
filter(search.result.order(:id))
end
def table_items

View File

@@ -26,6 +26,14 @@ module OpenFoodNetwork
expect(subject.orders).to eq([o2])
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 }
subject.orders
end
context "default date range" do
it "fetches orders completed in the past month" do
o1 = create(:order, completed_at: 1.month.ago - 1.day)