Permalink
Browse files

Included validation to skip AppModel on CakeSchema->readSchema becaus…

…e it tries to find 'app_models' table. Added testSchemaReadWithAppModel test
  • Loading branch information...
1 parent a025cb2 commit e4c1f28d849c6a60c369265a502315260babe80b @ajibarra ajibarra committed Jul 15, 2011
Showing with 44 additions and 3 deletions.
  1. +9 −3 lib/Cake/Model/CakeSchema.php
  2. +35 −0 lib/Cake/Test/Case/Model/CakeSchemaTest.php
@@ -224,19 +224,24 @@ public function read($options = array()) {
$models = App::objects('Model');
}
}
-
+
if (is_array($models)) {
foreach ($models as $model) {
$importModel = $model;
$plugin = null;
+
+ if ($model == 'AppModel') {
+ continue;
+ }
+
if (isset($this->plugin)) {
if ($model == $this->plugin . 'AppModel') {
continue;
}
$importModel = $model;
$plugin = $this->plugin . '.';
}
-
+
App::uses($importModel, $plugin . 'Model');
if (!class_exists($importModel)) {
continue;
@@ -290,7 +295,7 @@ public function read($options = array()) {
}
}
}
-
+
if (!empty($currentTables)) {
foreach ($currentTables as $table) {
if ($prefix) {
@@ -324,6 +329,7 @@ public function read($options = array()) {
ksort($tables);
return compact('name', 'tables');
+
}
/**
@@ -602,6 +602,41 @@ public function testSchemaRead() {
));
$this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing');
}
+
+/**
+* testSchemaReadWithAppModel method
+*
+* @access public
+* @return void
+*/
+ public function testSchemaReadWithAppModel() {
+ $connections = ConnectionManager::enumConnectionObjects();
+ if (!empty($connections['default'])) {
+ $backup = $connections['default'];
+ ConnectionManager::drop('default');
+ }
+ ConnectionManager::create('default', $connections['test']);
+ try {
+ $read = $this->Schema->read(array(
+ 'connection' => 'default',
+ 'name' => 'TestApp',
+ 'models' => array('AppModel')
+ ));
+ unset($read['tables']['missing']);
+ $this->assertTrue(empty($read['tables']));
+ if (!empty($backup)) {
+ ConnectionManager::drop('default');
+ ConnectionManager::create('default', $backup);
+ }
+ } catch(MissingTableException $mte) {
+ if (!empty($backup)) {
+ ConnectionManager::drop('default');
+ ConnectionManager::create('default', $backup);
+ }
+ $this->fail($mte->getMessage());
+ }
+
+ }
/**
* testSchemaReadWithOddTablePrefix method

0 comments on commit e4c1f28

Please sign in to comment.