{"action":"created","comment":{"url":"https://api.github.com/repos/neumino/thinky/pulls/comments/37942880","id":37942880,"diff_hunk":"@@ -0,0 +1,893 @@\n+'use strict';\n+\n+var Promise = require('bluebird'),\n+    TestFixture = require('./test-fixture'),\n+    expect = require('chai').expect,\n+    errors = require('../lib/errors'),\n+    util = require('./util');\n+\n+var test = new TestFixture(),\n+    thinky, type;\n+\n+before(function() {\n+  return test.initializeDatabase()\n+    .then(function() {\n+      thinky = test.thinky;\n+      type = thinky.type;\n+    });\n+});\n+after(function() { return test.dropDatabase(); });\n+\n+describe('createModel', function() {\n+  afterEach(function() { return test.dropTables(); });\n+\n+  it('should create a new model', function() {\n+    var model = thinky.createModel(util.s8(), {\n+      id: String, name: String\n+    });\n+\n+    return model.ready()\n+      .then(function() { expect(model).to.exist; });\n+  });\n+\n+  it('should check if the table was created', function() {\n+    var modelName = util.s8();\n+    var model = thinky.createModel(modelName, {\n+      id: String, name: String\n+    });\n+\n+    return model.ready()\n+      .then(function() {\n+        return test.r.tableList().run();\n+      })\n+      .then(function(result) {\n+        expect(result).to.contain(modelName);\n+      });\n+  });\n+\n+  it('should create multiple models', function() {\n+    var model1 = thinky.createModel(util.s8(), {\n+      id: String, name: String\n+    });\n+\n+    var model2 = thinky.createModel(util.s8(), {\n+      id: String, name: String\n+    });\n+\n+    return Promise.all([ model1.ready(), model2.ready() ])\n+      .then(function() {\n+        expect(model1).to.not.eql(model2);\n+      });\n+  });\n+\n+  it('should throw error for non existent table access', function() {\n+    var model = thinky.createModel(\"nonExistentTable\", {\n+      id: String, name: String\n+    }, {\n+      init: false\n+    });\n+\n+    return expect(model.get(1).run())\n+      .to.eventually.be.rejectedWith(/^Table `.*` does not exist in/);\n+  });\n+});\n+\n+describe('[_]getModel', function() {\n+  it('_getModel', function() {\n+    var name = util.s8();\n+    var model = thinky.createModel(util.s8(), {\n+      id: String, name: String\n+    }, {\n+      init: false\n+    });\n+\n+    expect(model._getModel()).to.have.property('_name');\n+  });\n+\n+  it('getTableName', function() {\n+    var modelName = util.s8();\n+    var model = thinky.createModel(modelName, {\n+      id: String, name: String\n+    }, {\n+      init: false\n+    });\n+\n+    expect(model).to.have.property('getTableName');\n+    expect(model.getTableName()).to.equal(modelName);\n+  });\n+});\n+\n+describe('Model', function() {\n+  before(function() {\n+    test.models.Model = thinky.createModel(util.s8(), { str: String });\n+    return test.models.Model.ready();\n+  });\n+  after(function() { return test.dropTables(); });\n+  afterEach(function() { return test.clearTables(); });\n+\n+  it('should create a new instance of a model', function() {\n+    var str = util.s8();\n+    var doc = new test.models.Model({ str: str });\n+\n+    expect(util.isPlainObject(doc)).to.be.true;\n+    expect(doc.str).to.eql(str);\n+  });\n+\n+  it('should create multiple instances from the same document', function() {\n+    var str = util.s8();\n+    var num = util.random();\n+\n+    var values = { str: str, num: num };\n+    var doc = new test.models.Model(values);\n+    var otherDoc = new test.models.Model(values);\n+\n+    expect(doc).to.eql(values);\n+    expect(doc).to.not.eql(otherDoc);\n+\n+    doc.str = doc.str + util.s8();\n+    expect(doc.str).to.not.eql(otherDoc.str);\n+\n+    var anotherDoc = new test.models.Model(values);\n+    expect(anotherDoc).to.not.eql(otherDoc);\n+    expect(anotherDoc).to.not.eql(doc);\n+  });\n+\n+  it('should create two distinct instances with the same options', function() {\n+    var options = { str: util.s8() };\n+    var doc1 = new test.models.Model(options);\n+    var doc2 = new test.models.Model(options);\n+\n+    expect(doc1).to.not.eql(doc2);\n+  });\n+\n+  it('should ensure two instances are different', function() {\n+    var str1 = util.s8(), str2 = util.s8();\n+    var doc1 = new test.models.Model({ str: str1 });\n+    expect(doc1.str).to.equal(str1);\n+\n+    var doc2 = new test.models.Model({ str: str2 });\n+    expect(doc2.str).to.equal(str2);\n+    expect(doc1.str).to.equal(str1);\n+    expect(doc1).to.not.eql(doc2);\n+  });\n+\n+  it('two instances should have different prototypes', function() {\n+    var doc1 = new test.models.Model({ str: util.s8() });\n+    var doc2 = new test.models.Model({ str: util.s8() });\n+\n+    expect(Object.getPrototypeOf(doc1)).to.not.eql(Object.getPrototypeOf(doc2));\n+  });\n+\n+  it('two instances should have the same model', function() {\n+    var doc1 = new test.models.Model({ str: util.s8() });\n+    var doc2 = new test.models.Model({ str: util.s8() });\n+\n+    expect(doc1.getModel()).to.eql(doc2.getModel());\n+  });\n+\n+  it('docs from different models should not interfere', function() {\n+    var str = util.s8();\n+    var doc = new test.models.Model({str: str});\n+\n+    var otherName = util.s8();\n+    test.models.OtherModel = thinky.createModel(otherName, {\n+      str: String\n+    });\n+\n+    return test.models.OtherModel.ready()\n+      .then(function() {\n+        var otherStr = util.s8();\n+        var otherDoc = new test.models.OtherModel({ str: otherStr });\n+\n+        expect(doc.str).to.eql(str);\n+        expect(otherDoc.str).to.eql(otherStr);\n+\n+        expect(otherDoc.getModel()).to.not.eql(doc.getModel());\n+\n+        // TODO: better way to access schema data, maybe Model.getSchema()\n+        expect(doc.getModel().getTableName()).to.eql(test.models.Model._schema._model._name);\n+        expect(otherDoc.getModel().getTableName(), otherName);\n+      });\n+  });\n+\n+});\n+\n+describe(\"Batch insert\", function() {\n+  afterEach(function() { return test.dropTables(); });\n+\n+  it('should insert a single document', function() {\n+    var Model = thinky.createModel(util.s8(), {\n+      id: String,\n+      num: Number\n+    });\n+\n+    return Model.ready()","path":"test/model.test.js","position":204,"original_position":204,"commit_id":"8e754920696b114bcb47d33c50e304cb013234e5","original_commit_id":"8e754920696b114bcb47d33c50e304cb013234e5","user":{"login":"marshall007","id":877936,"avatar_url":"https://avatars.githubusercontent.com/u/877936?v=3","gravatar_id":"","url":"https://api.github.com/users/marshall007","html_url":"https://github.com/marshall007","followers_url":"https://api.github.com/users/marshall007/followers","following_url":"https://api.github.com/users/marshall007/following{/other_user}","gists_url":"https://api.github.com/users/marshall007/gists{/gist_id}","starred_url":"https://api.github.com/users/marshall007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marshall007/subscriptions","organizations_url":"https://api.github.com/users/marshall007/orgs","repos_url":"https://api.github.com/users/marshall007/repos","events_url":"https://api.github.com/users/marshall007/events{/privacy}","received_events_url":"https://api.github.com/users/marshall007/received_events","type":"User","site_admin":false},"body":"@mbroadst in production, do you wait for all your models to be ready before starting the server? I've found that the way `thinky` does things significantly reduces application startup time. You can start the server and immediately start accepting requests. If some of those requests hit the database, `thinky` just waits until the relevant table(s) are ready before executing your queries. This is particularly important if you're deploying code changes that create new indices on a large table.\r\n\r\nI imagine this is how most people use `thinky`, so to mirror what @neumino said, I think it's important that the tests reflect that.","created_at":"2015-08-26T03:08:50Z","updated_at":"2015-08-26T03:08:50Z","html_url":"https://github.com/neumino/thinky/pull/329#discussion_r37942880","pull_request_url":"https://api.github.com/repos/neumino/thinky/pulls/329","_links":{"self":{"href":"https://api.github.com/repos/neumino/thinky/pulls/comments/37942880"},"html":{"href":"https://github.com/neumino/thinky/pull/329#discussion_r37942880"},"pull_request":{"href":"https://api.github.com/repos/neumino/thinky/pulls/329"}}},"pull_request":{"url":"https://api.github.com/repos/neumino/thinky/pulls/329","id":43227198,"html_url":"https://github.com/neumino/thinky/pull/329","diff_url":"https://github.com/neumino/thinky/pull/329.diff","patch_url":"https://github.com/neumino/thinky/pull/329.patch","issue_url":"https://api.github.com/repos/neumino/thinky/issues/329","number":329,"state":"open","locked":false,"title":"test(Model): reworked model.js test","user":{"login":"mbroadst","id":312966,"avatar_url":"https://avatars.githubusercontent.com/u/312966?v=3","gravatar_id":"","url":"https://api.github.com/users/mbroadst","html_url":"https://github.com/mbroadst","followers_url":"https://api.github.com/users/mbroadst/followers","following_url":"https://api.github.com/users/mbroadst/following{/other_user}","gists_url":"https://api.github.com/users/mbroadst/gists{/gist_id}","starred_url":"https://api.github.com/users/mbroadst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbroadst/subscriptions","organizations_url":"https://api.github.com/users/mbroadst/orgs","repos_url":"https://api.github.com/users/mbroadst/repos","events_url":"https://api.github.com/users/mbroadst/events{/privacy}","received_events_url":"https://api.github.com/users/mbroadst/received_events","type":"User","site_admin":false},"body":" * cleaned up test code to be as asynchronous as possible\r\n * used chai/chai-as-expected to make tests more readable\r\n * introduced test-fixture to properly track/clean/drop tables\r\n   throughout all test runs\r\n * made sure to wait for all table creation before operating on\r\n   those tables\r\n\r\nYou'll notice these tests take far longer to run. That's because previously thinky's tests did not actually wait for table creation (and frankly did not do any cleanup after test runs). This issue should track the progress of table creation speed (the bottleneck): https://github.com/rethinkdb/rethinkdb/issues/4746","created_at":"2015-08-24T21:59:27Z","updated_at":"2015-08-26T03:08:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"959e48fd27d51b9586ba2bff222c2f2d0fe69435","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/neumino/thinky/pulls/329/commits","review_comments_url":"https://api.github.com/repos/neumino/thinky/pulls/329/comments","review_comment_url":"https://api.github.com/repos/neumino/thinky/pulls/comments{/number}","comments_url":"https://api.github.com/repos/neumino/thinky/issues/329/comments","statuses_url":"https://api.github.com/repos/neumino/thinky/statuses/8e754920696b114bcb47d33c50e304cb013234e5","head":{"label":"mbroadst:new-model-tests","ref":"new-model-tests","sha":"8e754920696b114bcb47d33c50e304cb013234e5","user":{"login":"mbroadst","id":312966,"avatar_url":"https://avatars.githubusercontent.com/u/312966?v=3","gravatar_id":"","url":"https://api.github.com/users/mbroadst","html_url":"https://github.com/mbroadst","followers_url":"https://api.github.com/users/mbroadst/followers","following_url":"https://api.github.com/users/mbroadst/following{/other_user}","gists_url":"https://api.github.com/users/mbroadst/gists{/gist_id}","starred_url":"https://api.github.com/users/mbroadst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbroadst/subscriptions","organizations_url":"https://api.github.com/users/mbroadst/orgs","repos_url":"https://api.github.com/users/mbroadst/repos","events_url":"https://api.github.com/users/mbroadst/events{/privacy}","received_events_url":"https://api.github.com/users/mbroadst/received_events","type":"User","site_admin":false},"repo":{"id":41153084,"name":"thinky","full_name":"mbroadst/thinky","owner":{"login":"mbroadst","id":312966,"avatar_url":"https://avatars.githubusercontent.com/u/312966?v=3","gravatar_id":"","url":"https://api.github.com/users/mbroadst","html_url":"https://github.com/mbroadst","followers_url":"https://api.github.com/users/mbroadst/followers","following_url":"https://api.github.com/users/mbroadst/following{/other_user}","gists_url":"https://api.github.com/users/mbroadst/gists{/gist_id}","starred_url":"https://api.github.com/users/mbroadst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbroadst/subscriptions","organizations_url":"https://api.github.com/users/mbroadst/orgs","repos_url":"https://api.github.com/users/mbroadst/repos","events_url":"https://api.github.com/users/mbroadst/events{/privacy}","received_events_url":"https://api.github.com/users/mbroadst/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mbroadst/thinky","description":"JavaScript ORM for RethinkDB","fork":true,"url":"https://api.github.com/repos/mbroadst/thinky","forks_url":"https://api.github.com/repos/mbroadst/thinky/forks","keys_url":"https://api.github.com/repos/mbroadst/thinky/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mbroadst/thinky/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mbroadst/thinky/teams","hooks_url":"https://api.github.com/repos/mbroadst/thinky/hooks","issue_events_url":"https://api.github.com/repos/mbroadst/thinky/issues/events{/number}","events_url":"https://api.github.com/repos/mbroadst/thinky/events","assignees_url":"https://api.github.com/repos/mbroadst/thinky/assignees{/user}","branches_url":"https://api.github.com/repos/mbroadst/thinky/branches{/branch}","tags_url":"https://api.github.com/repos/mbroadst/thinky/tags","blobs_url":"https://api.github.com/repos/mbroadst/thinky/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mbroadst/thinky/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mbroadst/thinky/git/refs{/sha}","trees_url":"https://api.github.com/repos/mbroadst/thinky/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mbroadst/thinky/statuses/{sha}","languages_url":"https://api.github.com/repos/mbroadst/thinky/languages","stargazers_url":"https://api.github.com/repos/mbroadst/thinky/stargazers","contributors_url":"https://api.github.com/repos/mbroadst/thinky/contributors","subscribers_url":"https://api.github.com/repos/mbroadst/thinky/subscribers","subscription_url":"https://api.github.com/repos/mbroadst/thinky/subscription","commits_url":"https://api.github.com/repos/mbroadst/thinky/commits{/sha}","git_commits_url":"https://api.github.com/repos/mbroadst/thinky/git/commits{/sha}","comments_url":"https://api.github.com/repos/mbroadst/thinky/comments{/number}","issue_comment_url":"https://api.github.com/repos/mbroadst/thinky/issues/comments{/number}","contents_url":"https://api.github.com/repos/mbroadst/thinky/contents/{+path}","compare_url":"https://api.github.com/repos/mbroadst/thinky/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mbroadst/thinky/merges","archive_url":"https://api.github.com/repos/mbroadst/thinky/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mbroadst/thinky/downloads","issues_url":"https://api.github.com/repos/mbroadst/thinky/issues{/number}","pulls_url":"https://api.github.com/repos/mbroadst/thinky/pulls{/number}","milestones_url":"https://api.github.com/repos/mbroadst/thinky/milestones{/number}","notifications_url":"https://api.github.com/repos/mbroadst/thinky/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mbroadst/thinky/labels{/name}","releases_url":"https://api.github.com/repos/mbroadst/thinky/releases{/id}","created_at":"2015-08-21T11:48:49Z","updated_at":"2015-08-21T11:48:50Z","pushed_at":"2015-08-24T23:22:44Z","git_url":"git://github.com/mbroadst/thinky.git","ssh_url":"git@github.com:mbroadst/thinky.git","clone_url":"https://github.com/mbroadst/thinky.git","svn_url":"https://github.com/mbroadst/thinky","homepage":null,"size":2390,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"neumino:master","ref":"master","sha":"be833eb4bc5ba7750a41c71da4610b3fa9695165","user":{"login":"neumino","id":1461947,"avatar_url":"https://avatars.githubusercontent.com/u/1461947?v=3","gravatar_id":"","url":"https://api.github.com/users/neumino","html_url":"https://github.com/neumino","followers_url":"https://api.github.com/users/neumino/followers","following_url":"https://api.github.com/users/neumino/following{/other_user}","gists_url":"https://api.github.com/users/neumino/gists{/gist_id}","starred_url":"https://api.github.com/users/neumino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neumino/subscriptions","organizations_url":"https://api.github.com/users/neumino/orgs","repos_url":"https://api.github.com/users/neumino/repos","events_url":"https://api.github.com/users/neumino/events{/privacy}","received_events_url":"https://api.github.com/users/neumino/received_events","type":"User","site_admin":false},"repo":{"id":10870999,"name":"thinky","full_name":"neumino/thinky","owner":{"login":"neumino","id":1461947,"avatar_url":"https://avatars.githubusercontent.com/u/1461947?v=3","gravatar_id":"","url":"https://api.github.com/users/neumino","html_url":"https://github.com/neumino","followers_url":"https://api.github.com/users/neumino/followers","following_url":"https://api.github.com/users/neumino/following{/other_user}","gists_url":"https://api.github.com/users/neumino/gists{/gist_id}","starred_url":"https://api.github.com/users/neumino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neumino/subscriptions","organizations_url":"https://api.github.com/users/neumino/orgs","repos_url":"https://api.github.com/users/neumino/repos","events_url":"https://api.github.com/users/neumino/events{/privacy}","received_events_url":"https://api.github.com/users/neumino/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neumino/thinky","description":"JavaScript ORM for RethinkDB","fork":false,"url":"https://api.github.com/repos/neumino/thinky","forks_url":"https://api.github.com/repos/neumino/thinky/forks","keys_url":"https://api.github.com/repos/neumino/thinky/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neumino/thinky/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neumino/thinky/teams","hooks_url":"https://api.github.com/repos/neumino/thinky/hooks","issue_events_url":"https://api.github.com/repos/neumino/thinky/issues/events{/number}","events_url":"https://api.github.com/repos/neumino/thinky/events","assignees_url":"https://api.github.com/repos/neumino/thinky/assignees{/user}","branches_url":"https://api.github.com/repos/neumino/thinky/branches{/branch}","tags_url":"https://api.github.com/repos/neumino/thinky/tags","blobs_url":"https://api.github.com/repos/neumino/thinky/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neumino/thinky/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neumino/thinky/git/refs{/sha}","trees_url":"https://api.github.com/repos/neumino/thinky/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neumino/thinky/statuses/{sha}","languages_url":"https://api.github.com/repos/neumino/thinky/languages","stargazers_url":"https://api.github.com/repos/neumino/thinky/stargazers","contributors_url":"https://api.github.com/repos/neumino/thinky/contributors","subscribers_url":"https://api.github.com/repos/neumino/thinky/subscribers","subscription_url":"https://api.github.com/repos/neumino/thinky/subscription","commits_url":"https://api.github.com/repos/neumino/thinky/commits{/sha}","git_commits_url":"https://api.github.com/repos/neumino/thinky/git/commits{/sha}","comments_url":"https://api.github.com/repos/neumino/thinky/comments{/number}","issue_comment_url":"https://api.github.com/repos/neumino/thinky/issues/comments{/number}","contents_url":"https://api.github.com/repos/neumino/thinky/contents/{+path}","compare_url":"https://api.github.com/repos/neumino/thinky/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neumino/thinky/merges","archive_url":"https://api.github.com/repos/neumino/thinky/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neumino/thinky/downloads","issues_url":"https://api.github.com/repos/neumino/thinky/issues{/number}","pulls_url":"https://api.github.com/repos/neumino/thinky/pulls{/number}","milestones_url":"https://api.github.com/repos/neumino/thinky/milestones{/number}","notifications_url":"https://api.github.com/repos/neumino/thinky/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neumino/thinky/labels{/name}","releases_url":"https://api.github.com/repos/neumino/thinky/releases{/id}","created_at":"2013-06-22T19:11:04Z","updated_at":"2015-08-25T01:26:25Z","pushed_at":"2015-08-24T23:22:44Z","git_url":"git://github.com/neumino/thinky.git","ssh_url":"git@github.com:neumino/thinky.git","clone_url":"https://github.com/neumino/thinky.git","svn_url":"https://github.com/neumino/thinky","homepage":null,"size":4795,"stargazers_count":443,"watchers_count":443,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":59,"mirror_url":null,"open_issues_count":39,"forks":59,"open_issues":39,"watchers":443,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/neumino/thinky/pulls/329"},"html":{"href":"https://github.com/neumino/thinky/pull/329"},"issue":{"href":"https://api.github.com/repos/neumino/thinky/issues/329"},"comments":{"href":"https://api.github.com/repos/neumino/thinky/issues/329/comments"},"review_comments":{"href":"https://api.github.com/repos/neumino/thinky/pulls/329/comments"},"review_comment":{"href":"https://api.github.com/repos/neumino/thinky/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/neumino/thinky/pulls/329/commits"},"statuses":{"href":"https://api.github.com/repos/neumino/thinky/statuses/8e754920696b114bcb47d33c50e304cb013234e5"}}}}