Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
Added test showing that cache is cleared on saveField, refs #16
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed Jun 9, 2015
1 parent 2106f29 commit ac1ba71
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Test/Case/Model/Behavior/CacheBehaviorTest.php
Expand Up @@ -622,6 +622,40 @@ function testSave() {
$this->assertEquals($results['CacheData']['name'], 'Save me');
}

function testClearOnSaveField() {
$this->CacheData->Behaviors->attach('Cacher.Cache', array(
'clearOnSave' => true
));

// create cached values for this model
$results = $this->CacheData->find('all', array(
'conditions' => array(
'CacheData.name LIKE' => '%cache%'
)
));
$results = Set::extract('/CacheData/name', $results);
$expected = array(
'A Cached Thing',
'Cache behavior'
);
$this->assertEquals($results, $expected);

$this->CacheData->id = 1;
$this->CacheData->saveField('name', 'new name');

// test that it's not pulling from cache
$results = $this->CacheData->find('all', array(
'conditions' => array(
'CacheData.name LIKE' => '%cache%'
)
));
$results = Set::extract('/CacheData/name', $results);
$expected = array(
'Cache behavior'
);
$this->assertEquals($results, $expected);
}

function testUpdate() {
$data = $this->CacheData->read(null, 1);
$data['CacheData']['name'] = 'Updated';
Expand Down

0 comments on commit ac1ba71

Please sign in to comment.