From 05940ae1ec703a23714ff815e4e2e19cd1c6b5b7 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Tue, 22 Nov 2011 21:50:17 +0100 Subject: [PATCH] adding default order on id to CakeTestModel, to ensure correct order. Postgres can return results in any order it considers appropriate if none specified --- lib/Cake/Test/Case/Model/ModelReadTest.php | 1 + lib/Cake/TestSuite/Fixture/CakeTestModel.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index d45b91085..07e58d88d 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -6082,6 +6082,7 @@ class ModelReadTest extends BaseModelTest { $this->loadFixtures('User'); $TestModel = new User(); $TestModel->cacheQueries = false; + $TestModel->order = null; $expected = array( 'conditions' => array( diff --git a/lib/Cake/TestSuite/Fixture/CakeTestModel.php b/lib/Cake/TestSuite/Fixture/CakeTestModel.php index 8d41262e7..eb3539d80 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestModel.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestModel.php @@ -27,4 +27,21 @@ App::uses('Model', 'Model'); class CakeTestModel extends Model { public $useDbConfig = 'test'; public $cacheSources = false; + +/** + * Constructor, sets default order for the model to avoid failing tests caused by + * incorrect order when no order has been defined in the finds. + * Postgres can return the results in any order it considers appropriate if none is specified + * + * @param mixed $id Set this ID for this model on startup, can also be an array of options, see Model::__construct(). + * @param string $table Name of database table to use. + * @param string $ds DataSource connection name. + */ + function __construct($id = false, $table = null, $ds = null) { + parent::__construct($id, $table, $ds); + if ($this->useTable && $this->primaryKey && $this->schema($this->primaryKey)) { + $this->order = array($this->alias . '.' . $this->primaryKey => 'ASC'); + } + } + }