spree/spree — pull request #4943 by jordan-brough (2014-07-09 13:07:05+00:00)
Title: Make best-promotion query more deterministic

Mostly for the benefit of the specs under MySQL.

This query was generating some sporadic spec failures for me when using MySQL as the database. This is because MySQL does not store fractional seconds so the "created_at" was sometimes the same value for two adjustments when running specs. And when created_at is identical the query below would actually pick the earlier adjustment instead of the more recent one. Adding "id" as a fallback ordering fixes this problem and makes the behavior more deterministic.

The issue is reproduceable in postgres as well by using Timecop.