Skip to content

Commit 379fcba

Browse files
committed
Fixes #100
1 parent dfa9ff2 commit 379fcba

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/Jenssegers/Mongodb/Schema/Blueprint.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,21 @@ public function dropIndex($columns = null)
7878
{
7979
$columns = $this->fluent($columns);
8080

81-
foreach ($columns as $column)
81+
// Columns are passed as a default array
82+
if (is_array($columns) && is_int(key($columns)))
8283
{
83-
$this->collection->deleteIndex($column);
84+
// Transform the columns to the required array format
85+
$transform = array();
86+
foreach ($columns as $column)
87+
{
88+
$transform[$column] = 1;
89+
}
90+
91+
$columns = $transform;
8492
}
8593

94+
$this->collection->deleteIndex($columns);
95+
8696
return $this;
8797
}
8898

tests/SchemaTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public function testIndex()
3434

3535
$index = $this->getIndex('newcollection', 'mykey');
3636
$this->assertEquals(1, $index['key']['mykey']);
37+
38+
Schema::collection('newcollection', function($collection)
39+
{
40+
$collection->index(array('mykey'));
41+
});
42+
43+
$index = $this->getIndex('newcollection', 'mykey');
44+
$this->assertEquals(1, $index['key']['mykey']);
3745
}
3846

3947
public function testUnique()
@@ -57,6 +65,15 @@ public function testDropIndex()
5765

5866
$index = $this->getIndex('newcollection', 'uniquekey');
5967
$this->assertEquals(null, $index);
68+
69+
Schema::collection('newcollection', function($collection)
70+
{
71+
$collection->unique('uniquekey');
72+
$collection->dropIndex(array('uniquekey'));
73+
});
74+
75+
$index = $this->getIndex('newcollection', 'uniquekey');
76+
$this->assertEquals(null, $index);
6077
}
6178

6279
public function testBackground()

tests/bootstrap.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
use Illuminate\Database\DatabaseManager;
1010
use Illuminate\Database\Connectors\ConnectionFactory;
1111
use Illuminate\Events\Dispatcher;
12-
use Illuminate\Cache\ArrayStore;
13-
use Illuminate\Cache\Repository;
12+
use Illuminate\Cache\CacheManager;
1413

1514
# Fake app class
1615
class App extends ArrayObject {
@@ -20,19 +19,20 @@ function bound() {}
2019
# Fake app
2120
$app = new App;
2221

23-
# Event dispatcher
24-
$app['events'] = new Dispatcher;
25-
26-
# Cache driver
27-
$app['cache'] = new Repository(new ArrayStore);
28-
2922
# Load database configuration
3023
$config = require 'config/database.php';
3124
foreach ($config as $key => $value)
3225
{
3326
$app['config']["database.$key"] = $value;
3427
}
3528

29+
# Event dispatcher
30+
$app['events'] = new Dispatcher;
31+
32+
# Cache driver
33+
$app['config']['cache.driver'] = 'array';
34+
$app['cache'] = new CacheManager($app);
35+
3636
# Initialize database manager
3737
$app['db.factory'] = new ConnectionFactory(new Container);
3838
$app['db'] = new DatabaseManager($app, $app['db.factory']);

0 commit comments

Comments
 (0)