Skip to content

Commit

Permalink
Add tests for #3065
Browse files Browse the repository at this point in the history
When an entity is dirty but contains no actual changes to the row we
should count that as successful update.

Refs #3065
  • Loading branch information
markstory committed Mar 19, 2014
1 parent 449cb55 commit a8672ed
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -1573,10 +1573,12 @@ public function testSaveUpdatePrimaryKeyNotModified() {
->will($this->returnValue($query));

$statement = $this->getMock('\Cake\Database\Statement\StatementDecorator');
$statement->expects($this->once())->method('rowCount')
->will($this->returnValue(1));
$statement->expects($this->once())
->method('errorCode')
->will($this->returnValue('00000'));

$query->expects($this->once())->method('execute')
$query->expects($this->once())
->method('execute')
->will($this->returnValue($statement));

$query->expects($this->once())->method('set')
Expand Down Expand Up @@ -1610,6 +1612,23 @@ public function testUpdateNoChange() {
$this->assertSame($entity, $table->save($entity));
}

/**
* Tests that passing only the primary key to save will not execute any queries
* but still return success
*
* @group save
* @group integration
* @return void
*/
public function testUpdateDirtyNoActualChanges() {
$table = TableRegistry::get('Articles');
$entity = $table->get(1);

$entity->accessible('*', true);
$entity->set($entity->toArray());
$this->assertSame($entity, $table->save($entity));
}

/**
* Tests that failing to pass a primary key to save will result in exception
*
Expand Down

0 comments on commit a8672ed

Please sign in to comment.