From 779a62864bb19aa26617a732617321c564dc014d Mon Sep 17 00:00:00 2001 From: maggiolo00 Date: Fri, 28 Oct 2016 17:22:37 +0200 Subject: [PATCH] Fixes https://github.com/orientechnologies/orientjs/issues/192 --- CHANGELOG.md | 6 +- lib/db/class/index.js | 15 +- test/bugs/175-fetchplan-depth.js | 326 ++++++++++++++++--------------- test/db/class-test.js | 20 ++ 4 files changed, 201 insertions(+), 166 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0213d92f..a9a3b0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,13 @@ ###Bug Fixes +* [#192](https://github.com/orientechnologies/orientjs/issues/192) Fixed class name caching +* [#199](https://github.com/orientechnologies/orientjs/issues/199) Fixed multiple returns +* [#4485](https://github.com/orientechnologies/orientdb/issues/4485) Added More Tests for custom returns + ###New Features -* [#200](https://github.com/orientechnologies/orientjs/issues/200) Added Extra paramenters `input` to the endQuery +* [#200](https://github.com/orientechnologies/orientjs/issues/200) Added Extra parameter `input` to the endQuery ####2.2.2 diff --git a/lib/db/class/index.js b/lib/db/class/index.js index baf27d24..abd91c6d 100644 --- a/lib/db/class/index.js +++ b/lib/db/class/index.js @@ -179,9 +179,9 @@ exports.list = function (refresh) { } return this.send('record-load', { - cluster: 0, - position: 1 - }) + cluster: 0, + position: 1 + }) .bind(this) .then(function (response) { var record = response.records[0]; @@ -286,14 +286,15 @@ exports.drop = function (name) { * @promise {Object} The class object if it exists. */ exports.get = function (name, refresh) { - if (!refresh && this.class.cached && this.class.cached.names[name]) { - return Promise.resolve(this.class.cached.names[name]); + var className = name.toLocaleUpperCase(); + if (!refresh && this.class.cached && this.class.cached.names[className]) { + return Promise.resolve(this.class.cached.names[className]); } else if (!this.class.cached || refresh) { return this.class.list(refresh) .bind(this) .then(function () { - return this.class.cached.names[name] || Promise.reject(new errors.Request('No such class: ' + name)); + return this.class.cached.names[className] || Promise.reject(new errors.Request('No such class: ' + name)); }); } else { @@ -324,7 +325,7 @@ exports.cacheData = function (classes) { for (i = 0; i < total; i++) { item = classes[i]; - this.class.cached.names[item.name] = item; + this.class.cached.names[item.name.toLocaleUpperCase()] = item; } return this; diff --git a/test/bugs/175-fetchplan-depth.js b/test/bugs/175-fetchplan-depth.js index d3a986d6..22be581e 100644 --- a/test/bugs/175-fetchplan-depth.js +++ b/test/bugs/175-fetchplan-depth.js @@ -2,197 +2,207 @@ var Promise = require('bluebird'); describe("Bug #175: Fetchplan depth", function () { var hasProtocolSupport; - function ifSupportedIt (text, fn) { + + function ifSupportedIt(text, fn) { it(text, function () { if (hasProtocolSupport) { return fn.call(this); } }); } + before(function () { return CREATE_TEST_DB(this, 'testdb_bug_175') - .bind(this) - .then(function () { - hasProtocolSupport = this.db.server.transport.connection.protocolVersion >= 28; - return Promise.all([ - this.db.class.create('SomeVertex', 'V'), - this.db.class.create('SomeEdge', 'E'), - this.db.class.create('OtherEdge', 'E') - ]); - }) - .spread(function (vertex, edge1, edge2) { - return Promise.all([ - vertex.property.create([ - { - name: 'owner', - type: 'link', - linkedClass: 'OUser' - }, - { - name: 'val', - type: 'string' - } - ]), - edge1.property.create([ - { - name: 'foo', - type: 'string' - } - ]), - edge2.property.create([ - { - name: 'greeting', - type: 'string' - } - ]) - ]); - }) - .then(function () { - return this.db - .let('thing1', function (s) { - s - .create('VERTEX', 'SomeVertex') - .set({ - owner: new LIB.RID('#5:0'), - val: 'a' - }); + .bind(this) + .then(function () { + hasProtocolSupport = this.db.server.transport.connection.protocolVersion >= 28; + return Promise.all([ + this.db.class.create('SomeVertex', 'V'), + this.db.class.create('SomeEdge', 'E'), + this.db.class.create('OtherEdge', 'E') + ]); }) - .let('thing2', function (s) { - s - .create('VERTEX', 'SomeVertex') - .set({ - owner: new LIB.RID('#5:1'), - val: 'b' - }); - }) - .let('edge1', function (s) { - s - .create('EDGE', 'OtherEdge') - .set({ - greeting: 'Hello World' - }) - .from('$thing2') - .to('$thing1'); - }) - .create('EDGE', 'SomeEdge') - .set({ - foo: 'bar' + .spread(function (vertex, edge1, edge2) { + return Promise.all([ + vertex.property.create([ + { + name: 'owner', + type: 'link', + linkedClass: 'OUser' + }, + { + name: 'val', + type: 'string' + } + ]), + edge1.property.create([ + { + name: 'foo', + type: 'string' + } + ]), + edge2.property.create([ + { + name: 'greeting', + type: 'string' + } + ]) + ]); }) - .from('$thing1') - .to('$thing2') - .commit() - .all(); - }); + .then(function () { + return this.db + .let('thing1', function (s) { + s + .create('VERTEX', 'SomeVertex') + .set({ + owner: new LIB.RID('#5:0'), + val: 'a' + }); + }) + .let('thing2', function (s) { + s + .create('VERTEX', 'SomeVertex') + .set({ + owner: new LIB.RID('#5:1'), + val: 'b' + }); + }) + .let('edge1', function (s) { + s + .create('EDGE', 'OtherEdge') + .set({ + greeting: 'Hello World' + }) + .from('$thing2') + .to('$thing1'); + }) + .create('EDGE', 'SomeEdge') + .set({ + foo: 'bar' + }) + .from('$thing1') + .to('$thing2') + .commit() + .all(); + }); }); after(function () { - return DELETE_TEST_DB('testdb_bug_175'); + // return DELETE_TEST_DB('testdb_bug_175'); }); ifSupportedIt('should return records using a fetchplan', function () { return this.db - .select() - .from('SomeVertex') - .fetch({'*': 1}) - .limit(1) - .one() - .then(function (doc) { - doc.should.have.property('owner'); - doc.owner.should.have.property('name'); - doc.should.have.property('out_SomeEdge'); - doc.should.have.property('in_OtherEdge'); + .select() + .from('SomeVertex') + .fetch({'*': 1}) + .limit(1) + .one() + .then(function (doc) { + doc.should.have.property('owner'); + doc.owner.should.have.property('name'); + doc.should.have.property('out_SomeEdge'); + doc.should.have.property('in_OtherEdge'); - // allow for difference between 1.7 and 2.0 - if (doc.out_SomeEdge instanceof LIB.Bag) { - doc.out_SomeEdge = doc.out_SomeEdge.all(); - } - else if (!Array.isArray(doc.out_SomeEdge)) { - doc.out_SomeEdge = [doc.out_SomeEdge]; - } - if (doc.in_OtherEdge instanceof LIB.Bag) { - doc.in_OtherEdge = doc.in_OtherEdge.all(); - } - else if (!Array.isArray(doc.in_OtherEdge)) { - doc.in_OtherEdge = [doc.in_OtherEdge]; - } + // allow for difference between 1.7 and 2.0 + if (doc.out_SomeEdge instanceof LIB.Bag) { + doc.out_SomeEdge = doc.out_SomeEdge.all(); + } + else if (!Array.isArray(doc.out_SomeEdge)) { + doc.out_SomeEdge = [doc.out_SomeEdge]; + } + if (doc.in_OtherEdge instanceof LIB.Bag) { + doc.in_OtherEdge = doc.in_OtherEdge.all(); + } + else if (!Array.isArray(doc.in_OtherEdge)) { + doc.in_OtherEdge = [doc.in_OtherEdge]; + } - doc.out_SomeEdge.forEach(function (item) { - item.should.not.be.an.instanceOf(LIB.RID); - }); - doc.in_OtherEdge.forEach(function (item) { - item.should.not.be.an.instanceOf(LIB.RID); + doc.out_SomeEdge.forEach(function (item) { + item.should.not.be.an.instanceOf(LIB.RID); + }); + doc.in_OtherEdge.forEach(function (item) { + item.should.not.be.an.instanceOf(LIB.RID); + }); }); - }); }); ifSupportedIt('should return records, excluding edges using a fetchplan', function () { return this.db.query('SELECT FROM SomeVertex LIMIT 1', { fetchPlan: '*:1 in_*:-2 out_*:-2' }) - .spread(function (doc) { - doc.should.have.property('owner'); - doc.owner.should.have.property('name'); - doc.should.have.property('out_SomeEdge'); - doc.should.have.property('in_OtherEdge'); + .spread(function (doc) { + doc.should.have.property('owner'); + doc.owner.should.have.property('name'); + doc.should.have.property('out_SomeEdge'); + doc.should.have.property('in_OtherEdge'); - // allow for difference between 1.7 and 2.0 - if (doc.out_SomeEdge instanceof LIB.Bag) { - doc.out_SomeEdge = doc.out_SomeEdge.all(); - } - else if (!Array.isArray(doc.out_SomeEdge)) { - doc.out_SomeEdge = [doc.out_SomeEdge]; - } - if (doc.in_OtherEdge instanceof LIB.Bag) { - doc.in_OtherEdge = doc.in_OtherEdge.all(); - } - else if (!Array.isArray(doc.in_OtherEdge)) { - doc.in_OtherEdge = [doc.in_OtherEdge]; - } + // allow for difference between 1.7 and 2.0 + if (doc.out_SomeEdge instanceof LIB.Bag) { + doc.out_SomeEdge = doc.out_SomeEdge.all(); + } + else if (!Array.isArray(doc.out_SomeEdge)) { + doc.out_SomeEdge = [doc.out_SomeEdge]; + } + if (doc.in_OtherEdge instanceof LIB.Bag) { + doc.in_OtherEdge = doc.in_OtherEdge.all(); + } + else if (!Array.isArray(doc.in_OtherEdge)) { + doc.in_OtherEdge = [doc.in_OtherEdge]; + } - doc.out_SomeEdge.forEach(function (item) { - item.should.be.an.instanceOf(LIB.RID); - }); - doc.in_OtherEdge.forEach(function (item) { - item.should.be.an.instanceOf(LIB.RID); + doc.out_SomeEdge.forEach(function (item) { + item.should.be.an.instanceOf(LIB.RID); + }); + doc.in_OtherEdge.forEach(function (item) { + item.should.be.an.instanceOf(LIB.RID); + }); }); - }); }); ifSupportedIt('should return records, excluding edges using a fetchplan via the query builder', function () { return this.db - .select() - .from('SomeVertex') - .fetch({ - '*': 1, - 'in_*':-2, - 'out_*':-2 - }) - .limit(1) - .one() - .then(function (doc) { - doc.should.have.property('owner'); - doc.owner.should.have.property('name'); - doc.should.have.property('out_SomeEdge'); - doc.should.have.property('in_OtherEdge'); + .select() + .from('SomeVertex') + .fetch({ + '*': 1, + 'in_*': -2, + 'out_*': -2 + }) + .limit(1) + .one() + .then(function (doc) { + doc.should.have.property('owner'); + doc.owner.should.have.property('name'); + doc.should.have.property('out_SomeEdge'); + doc.should.have.property('in_OtherEdge'); - // allow for difference between 1.7 and 2.0 - if (doc.out_SomeEdge instanceof LIB.Bag) { - doc.out_SomeEdge = doc.out_SomeEdge.all(); - } - else if (!Array.isArray(doc.out_SomeEdge)) { - doc.out_SomeEdge = [doc.out_SomeEdge]; - } - if (doc.in_OtherEdge instanceof LIB.Bag) { - doc.in_OtherEdge = doc.in_OtherEdge.all(); - } - else if (!Array.isArray(doc.in_OtherEdge)) { - doc.in_OtherEdge = [doc.in_OtherEdge]; - } + // allow for difference between 1.7 and 2.0 + if (doc.out_SomeEdge instanceof LIB.Bag) { + doc.out_SomeEdge = doc.out_SomeEdge.all(); + } + else if (!Array.isArray(doc.out_SomeEdge)) { + doc.out_SomeEdge = [doc.out_SomeEdge]; + } + if (doc.in_OtherEdge instanceof LIB.Bag) { + doc.in_OtherEdge = doc.in_OtherEdge.all(); + } + else if (!Array.isArray(doc.in_OtherEdge)) { + doc.in_OtherEdge = [doc.in_OtherEdge]; + } - doc.out_SomeEdge.forEach(function (item) { - item.should.be.an.instanceOf(LIB.RID); - }); - doc.in_OtherEdge.forEach(function (item) { - item.should.be.an.instanceOf(LIB.RID); + doc.out_SomeEdge.forEach(function (item) { + item.should.be.an.instanceOf(LIB.RID); + }); + doc.in_OtherEdge.forEach(function (item) { + item.should.be.an.instanceOf(LIB.RID); + }); }); - }); }); + + // ifSupportedIt('should return records, using a fetchplan -1 ', function () { + // return this.db.query('SELECT FROM SomeVertex', { + // fetchPlan: 'in_*:-1 out_*:-1' + // }).then(function (result) { + // + // }) + // }); }); \ No newline at end of file diff --git a/test/db/class-test.js b/test/db/class-test.js index f482f0c1..f0b8b813 100644 --- a/test/db/class-test.js +++ b/test/db/class-test.js @@ -28,6 +28,26 @@ describe("Database API - Class", function () { }); }); + describe('Db::class.get()', function () { + it('should get the class with the given name toLowerCase', function () { + return this.db.class.get('ouser') + .then(function (item) { + item.should.be.an.instanceOf(Class); + item.name.should.equal('OUser'); + }); + }); + }); + + describe('Db::class.get()', function () { + it('should get the class with the given name toUpperCase', function () { + return this.db.class.get('ouser') + .then(function (item) { + item.should.be.an.instanceOf(Class); + item.name.should.equal('OUser'); + }); + }); + }); + describe('Db::class.create()', function () { it('should create a class with the given name', function () { return this.db.class.create('TestClass')