Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Applying patch from 'rynop'. Fixing FixtureTask so it includes the da…

…tasource if its not the default one.

Updating tests.
Fixes #1419
  • Loading branch information...
commit a7061510c13cbccf3a02e7a331d66d697d98af8a 1 parent 5092013
@markstory markstory authored
View
17 cake/console/libs/tasks/fixture.php
@@ -161,7 +161,9 @@ function bake($model, $useTable = false, $importOptions = array()) {
if (!class_exists('CakeSchema')) {
App::import('Model', 'CakeSchema', false);
}
- $table = $schema = $records = $import = $modelImport = $recordImport = null;
+ $table = $schema = $records = $import = $modelImport = null;
+ $importBits = array();
+
if (!$useTable) {
$useTable = Inflector::tableize($model);
} elseif ($useTable != Inflector::tableize($model)) {
@@ -170,16 +172,17 @@ function bake($model, $useTable = false, $importOptions = array()) {
if (!empty($importOptions)) {
if (isset($importOptions['schema'])) {
- $modelImport = "'model' => '{$importOptions['schema']}'";
+ $modelImport = true;
+ $importBits[] = "'model' => '{$importOptions['schema']}'";
}
if (isset($importOptions['records'])) {
- $recordImport = "'records' => true";
+ $importBits[] = "'records' => true";
}
- if ($modelImport && $recordImport) {
- $modelImport .= ', ';
+ if ($this->connection != 'default') {
+ $importBits[] .= "'connection' => '{$this->connection}'";
}
- if (!empty($modelImport) || !empty($recordImport)) {
- $import = sprintf("array(%s%s)", $modelImport, $recordImport);
+ if (!empty($importBits)) {
+ $import = sprintf("array(%s)", implode(', ', $importBits));
}
}
View
26 cake/tests/cases/console/libs/tasks/fixture.test.php
@@ -136,6 +136,17 @@ function testImportOptions() {
}
/**
+ * test that connection gets set to the import options when a different connection is used.
+ *
+ * @return void
+ */
+ function testImportOptionsAlternateConnection() {
+ $this->Task->connection = 'test';
+ $result = $this->Task->bake('Article', false, array('schema' => 'Article'));
+ $this->assertPattern("/'connection' => 'test'/", $result);
+ }
+
+/**
* test generating a fixture with database conditions.
*
* @return void
@@ -287,15 +298,24 @@ function testBake() {
$this->assertPattern('/var \$fields = array\(/', $result);
$result = $this->Task->bake('Article', 'comments', array('records' => true));
- $this->assertPattern("/var \\\$import \= array\('records' \=\> true\);/", $result);
+ $this->assertPattern(
+ "/var \\\$import \= array\('records' \=\> true, 'connection' => 'test_suite'\);/",
+ $result
+ );
$this->assertNoPattern('/var \$records/', $result);
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article'));
- $this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\);/", $result);
+ $this->assertPattern(
+ "/var \\\$import \= array\('model' \=\> 'Article', 'connection' => 'test_suite'\);/",
+ $result
+ );
$this->assertNoPattern('/var \$fields/', $result);
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article', 'records' => true));
- $this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true\);/", $result);
+ $this->assertPattern(
+ "/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true, 'connection' => 'test_suite'\);/",
+ $result
+ );
$this->assertNoPattern('/var \$fields/', $result);
$this->assertNoPattern('/var \$records/', $result);
}
Please sign in to comment.
Something went wrong with that request. Please try again.