Add DatastoreDB.replace({defaultPartition})

R=sgjesse@google.com

Review URL: https://codereview.chromium.org//937133002
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d90dff0..ecf38ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## 0.1.4
+
+* Added optional `defaultPartition` parameter to the constructor of
+  `DatastoreDB`.
+
+## 0.1.3+2
+
+* Widened googleapis/googleapis_beta constraints in pubspec.yaml.
+
 ## 0.1.3+1
 
 * Change the service scope keys keys to non-private symbols.
diff --git a/lib/src/db/db.dart b/lib/src/db/db.dart
index 07c5efb..8d17c1f 100644
--- a/lib/src/db/db.dart
+++ b/lib/src/db/db.dart
@@ -247,9 +247,10 @@
   final ModelDB _modelDB;
   Partition _defaultPartition;
 
-  DatastoreDB(this.datastore, {ModelDB modelDB})
-      : _modelDB = modelDB != null ? modelDB : new ModelDBImpl() {
-    _defaultPartition = new Partition(null);
+  DatastoreDB(this.datastore, {ModelDB modelDB, Partition defaultPartition}) :
+      _modelDB = modelDB != null ? modelDB : new ModelDBImpl() {
+      _defaultPartition =
+          defaultPartition != null ? defaultPartition : new Partition(null);
   }
 
   /**
diff --git a/pubspec.yaml b/pubspec.yaml
index 0fc9453..660572a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: gcloud
-version: 0.1.3+2
+version: 0.1.4
 author: Dart Team <misc@dartlang.org>
 description: Dart gcloud APIs
 homepage: https://github.com/dart-lang/gcloud
diff --git a/test/db/db_test.dart b/test/db/db_test.dart
new file mode 100644
index 0000000..70320d7
--- /dev/null
+++ b/test/db/db_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library gcloud.db_test;
+
+import 'package:gcloud/db.dart';
+import 'package:unittest/unittest.dart';
+
+@Kind()
+class Foobar extends Model {}
+
+main() {
+  group('db', () {
+    test('default-partition', () {
+      var db = new DatastoreDB(null);
+
+      // Test defaultPartition
+      expect(db.defaultPartition.namespace, isNull);
+
+      // Test emptyKey
+      expect(db.emptyKey.partition.namespace, isNull);
+
+      // Test emptyKey.append()
+      var key = db.emptyKey.append(Foobar, id: 42);
+      expect(key.parent, db.emptyKey);
+      expect(key.partition.namespace, isNull);
+      expect(key.id, 42);
+      expect(key.type, equals(Foobar));
+    });
+
+    test('non-default-partition', () {
+      var nsDb = new DatastoreDB(
+          null, defaultPartition: new Partition('foobar-namespace'));
+
+      // Test defaultPartition
+      expect(nsDb.defaultPartition.namespace, 'foobar-namespace');
+
+      // Test emptyKey
+      expect(nsDb.emptyKey.partition.namespace, 'foobar-namespace');
+
+      // Test emptyKey.append()
+      var key = nsDb.emptyKey.append(Foobar, id: 42);
+      expect(key.parent, nsDb.emptyKey);
+      expect(key.partition.namespace, 'foobar-namespace');
+      expect(key.id, 42);
+      expect(key.type, equals(Foobar));
+    });
+  });
+}