[Groonga-commit] groonga/gcs [ember] Throw error for createDomain on existing domain and deleteDomain on not-existing domain

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Oct 4 15:02:00 JST 2012


YUKI Hiroshi	2012-10-04 15:02:00 +0900 (Thu, 04 Oct 2012)

  New Revision: 184ba88e006827cbf79b785da2fd35acb33a9343
  https://github.com/groonga/gcs/commit/184ba88e006827cbf79b785da2fd35acb33a9343

  Log:
    Throw error for createDomain on existing domain and deleteDomain on not-existing domain

  Modified files:
    lib/database/domain.js
    test/database-domain.test.js

  Modified: lib/database/domain.js (+29 -9)
===================================================================
--- lib/database/domain.js    2012-10-01 17:47:29 +0900 (b3afced)
+++ lib/database/domain.js    2012-10-04 15:02:00 +0900 (7b95655)
@@ -27,6 +27,20 @@ var SYNONYMS_COLUMN =
       exports.SYNONYMS_COLUMN =
       Domain.SYNONYMS_COKUMN = 'synonyms';
 
+
+var NO_CONTEXT =
+      exports.NO_CONTEXT =
+      Domain.NO_CONTEXT = 'no context';
+
+var DOMAIN_ALREADY_EXISTS =
+      exports.DOMAIN_ALREADY_EXISTS =
+      Domain.DOMAIN_ALREADY_EXISTS = 'domain already exists';
+
+var DOMAIN_DOES_NOT_EXIST =
+      exports.DOMAIN_DOES_NOT_EXIST =
+      Domain.DOMAIN_DOES_NOT_EXIST = 'domain does not exist';
+
+
 function assertValidDomainName(domain) {
   if (typeof domain != 'string')
     throw new Error('domain name must be a string');
@@ -179,7 +193,7 @@ Domain.prototype = {
   },
   get indexFields() {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
     var columns = this.context.ordinalColumnsSync(this.tableName);
     columns = columns.sort(function(a, b) { return a.name - b.name; });
     var fields = columns.map(function(column) {
@@ -272,7 +286,10 @@ Domain.prototype = {
 
   createSync: function() {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
+
+    if (this.exists())
+      throw new Error(DOMAIN_ALREADY_EXISTS);
 
     this.context.commandSync('table_create', {
       name: this.tableName,
@@ -304,7 +321,10 @@ Domain.prototype = {
 
   deleteSync: function() {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
+
+    if (!this.exists())
+      throw new Error(DOMAIN_DOES_NOT_EXIST);
 
     this.context.commandSync('table_remove', {
       name: this.tableName
@@ -328,7 +348,7 @@ Domain.prototype = {
 
   getSynonymSync: function(key) {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
 
     if (!this.hasSynonymsTableSync())
       return null;
@@ -355,7 +375,7 @@ Domain.prototype = {
 
   getSynonymsSync: function() {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
 
     if (!this.hasSynonymsTableSync())
       return {};
@@ -379,7 +399,7 @@ Domain.prototype = {
 
   updateSynonymsSync: function(synonyms) {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
 
     this.setupBlankSynonymsTable();
 
@@ -489,7 +509,7 @@ Domain.prototype = {
 
   setConfiguration: function(key, value) {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
 
     this.context.commandSync('load', {
       table: this.configurationsTableName,
@@ -503,7 +523,7 @@ Domain.prototype = {
   },
   getConfiguration: function(key) {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
 
     var options = {
           table: this.configurationsTableName,
@@ -521,7 +541,7 @@ Domain.prototype = {
   },
   deleteConfiguration: function(key) {
     if (!this.context)
-      throw new Error('no context');
+      throw new Error(NO_CONTEXT);
 
     this.context.commandSync('delete', {
       table: this.configurationsTableName,

  Modified: test/database-domain.test.js (+17 -0)
===================================================================
--- test/database-domain.test.js    2012-10-01 17:47:29 +0900 (56fed49)
+++ test/database-domain.test.js    2012-10-04 15:02:00 +0900 (f81b3b5)
@@ -494,6 +494,14 @@ suite('database', function() {
         assert.equal(dump, expectedDump);
       });
 
+      test('createSync again', function() {
+        var domain = new Domain('companies', context);
+        domain.createSync();
+        assert.throw(function() {
+          domain.createSync();
+        }, new RegExp(Domain.DOMAIN_ALREADY_EXISTS));
+      });
+
       test('deleteSync', function() {
         var domain = new Domain('companies', context);
         domain.createSync();
@@ -507,6 +515,15 @@ suite('database', function() {
         assert.equal(dump, expectedDump);
       });
 
+      test('deleteSync again', function() {
+        var domain = new Domain('companies', context);
+        domain.createSync();
+        domain.deleteSync();
+        assert.throw(function() {
+          domain.deleteSync();
+        }, new RegExp(Domain.DOMAIN_DOES_NOT_EXIST));
+      });
+
       test('updateSynonymsSync, initialize', function() {
         var domain = new Domain('companies', context);
         assert.isFalse(domain.hasSynonymsTableSync());
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index