Permalink
Browse files

ensure boolean values are converted to correct value on update, avoid…

…ing issues with posgres boolean type
  • Loading branch information...
ceeram committed Mar 19, 2012
1 parent c38419e commit 091ad53b8009a44ecb58798510d20a0f7f8078e2
Showing with 50 additions and 0 deletions.
  1. +2 −0 lib/Cake/Model/Datasource/DboSource.php
  2. +48 −0 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -1836,6 +1836,8 @@ protected function _prepareUpdateFields(Model $model, $fields, $quoteValues = tr
if ($quoteValues) {
$update .= $this->value($value, $model->getColumnType($field));
+ } elseif ($model->getColumnType($field) == 'boolean') {
+ $update .= $this->boolean($value, true);
} elseif (!$alias) {
$update .= str_replace($quotedAlias . '.', '', str_replace(
$model->alias . '.', '', $value
@@ -6605,4 +6605,52 @@ public function testSaveAllDeepHasManyBelongsTo() {
$this->assertEquals($expected, $result);
}
+/**
+ * testUpdateAllBoolean
+ *
+ * return @void
+ */
+ public function testUpdateAllBoolean() {
+ $this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio');
+ $TestModel = new Item();
+ $result = $TestModel->updateAll(array('published' => true));
+ $this->assertTrue($result);
+
+ $result = $TestModel->find('first', array('fields' => array('id', 'published')));
+ $this->assertEquals(true, $result['Item']['published']);
+ }
+
+/**
+ * testUpdateAllBooleanConditions
+ *
+ * return @void
+ */
+ public function testUpdateAllBooleanConditions() {
+ $this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio');
+ $TestModel = new Item();
+
+ $result = $TestModel->updateAll(array('published' => true), array('Item.id' => 1));
+ $this->assertTrue($result);
+ $result = $TestModel->find('first', array(
+ 'fields' => array('id', 'published'),
+ 'conditions' => array('Item.id' => 1)));
+ $this->assertEquals(true, $result['Item']['published']);
+ }
+
+/**
+ * testUpdateBoolean
+ *
+ * return @void
+ */
+ public function testUpdateBoolean() {
+ $this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio');
+ $TestModel = new Item();
+
+ $result = $TestModel->save(array('published' => true, 'id' => 1));
+ $this->assertTrue((boolean)$result);
+ $result = $TestModel->find('first', array(
+ 'fields' => array('id', 'published'),
+ 'conditions' => array('Item.id' => 1)));
+ $this->assertEquals(true, $result['Item']['published']);
+ }
}

0 comments on commit 091ad53

Please sign in to comment.