Applying patch from 'rynop'. Fixing FixtureTask so it includes the datasource if its not the default one.

Updating tests.
Fixes #1419
This commit is contained in:
mark_story 2010-12-31 13:05:04 -05:00
parent 5092013304
commit a7061510c1
2 changed files with 33 additions and 10 deletions

View file

@ -161,7 +161,9 @@ class FixtureTask extends BakeTask {
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 @@ class FixtureTask extends BakeTask {
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 file

@ -135,6 +135,17 @@ class FixtureTaskTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
/**
* 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.
*
@ -287,15 +298,24 @@ class FixtureTaskTest extends CakeTestCase {
$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);
}