Created
September 28, 2015 19:55
-
-
Save tareko/7d68a06c4a6f512f0384 to your computer and use it in GitHub Desktop.
Failure to properly load model inside model as a fixture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function lastUpdated($id) { | |
//Set up new Shift model only if not already set (fixes problems with testing) | |
if(!$this->Shift) { | |
App::uses('Shift', 'Model'); | |
$this->Shift = new Shift(); | |
} | |
$calendar = $this->findById($id, array( | |
'start_date', 'end_date')); | |
$lastUpdated = $this->Shift->find('all', array( | |
'fields' => array('Shift.updated', 'Shift.date'), | |
'conditions' => array( | |
'Shift.date >=' => $calendar['Calendar']['start_date'], | |
'Shift.date <=' => $calendar['Calendar']['end_date'], | |
), | |
'order' => array( | |
'Shift.updated' => 'DESC', | |
) | |
)); | |
return $lastUpdated['Shift']['updated']; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testLastUpdated () { | |
App::uses('Shift', 'Model'); | |
$this->Shift = ClassRegistry::init('Shift'); | |
$result = $this->Calendar->lastUpdated('1'); | |
debug($result); | |
$expected = array( | |
'start_date' => '2011-12-01', | |
'end_date' => '2011-12-22' | |
); | |
//TODO: EXPECTED FAIL DUE TO nested model call. | |
$this->assertEquals($expected, $result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment