Permalink
Browse files

added namespaced domain constructors namespaced on the dbname

  • Loading branch information...
1 parent 0369d61 commit 6cfe8bf7402de48561961d10e851f0b530d6881b Scott Burch committed Oct 31, 2011
Showing with 12 additions and 2 deletions.
  1. +1 −1 README.md
  2. +2 −1 couch-ar.js
  3. +9 −0 test/spec/TestUserSpec.js
View
2 README.md
@@ -85,7 +85,7 @@ To understand my code it is best to understand this style.
After running init() the domain constructors are available from the couch-ar object.
var domain = require('couch-ar');
- domain.TestUser.create({})
+ domain.TestUser.create({}) or domain['my-db-name'].TestUser.create({})
## Before Hooks
View
3 couch-ar.js
@@ -76,7 +76,8 @@ exports.create = function(name, config, constr) {
}
factory.viewNames = [];
- return exports[name] = factory;
+ exports[config.dbName] = exports[config.dbName] || {};
+ return exports[name] = exports[config.dbName][name] = factory;
function addFinders(callback) {
for (prop in config.properties) {
View
9 test/spec/TestUserSpec.js
@@ -5,6 +5,15 @@ var domain = require('couch-ar');
runTests({createDbName: 'couch-ar-test', domainDbName: 'couch-ar-test', host: 'localhost', port: 5984, baseDir: 'testDomain'});
runTests({createDbName: 'couch-ar-test2', baseDir: 'testDomain2'});
+describe('duplicate namespaces for domains', function() {
+ it('should have setup the duplicate namespace for the domains', function() {
+ expect(domain['couch-ar-test'].TestUser).toBeDefined();
+ });
+
+ it('should make the domain constructor and the base constructor the same object', function() {
+ expect(domain['couch-ar-test2'].TestUser).toBe(domain.TestUser);
+ });
+});
function runTests(testConfig) {
describe('init() method with host and port options', function() {

0 comments on commit 6cfe8bf

Please sign in to comment.