Permalink
Browse files

added .viewNames property to constructor

  • Loading branch information...
1 parent 8221766 commit 93927b7903c438a146ec33be967a6edadc6c2d86 Scott Burch committed Aug 7, 2011
Showing with 24 additions and 43 deletions.
  1. +3 −30 README.md
  2. +11 −13 couch-ar.js
  3. +10 −0 test/spec/TestUserSpec.js
View
@@ -166,6 +166,9 @@ dateCreated = the date the object was first saved to the DB
lastUpdated = the date the object was last updated
+## constructor properties
+
+viewNames = the list of view names
## custom views
@@ -198,33 +201,3 @@ This code will also add static finders:
Provided under the MIT license. In other words, do what you want with it.
-
-## Versions
-
-Feb 2, 2011 - released V0.1.1
-
- new method list()
- properties dateCreated and lastUpdated
- create now allows undefined properties to be added to an object
-
-Feb 22, 2011 - released v0.1.2
-
- added custom views to domain constructors
-
-Feb 22, 2011 - release v0.1.3
-
- fix bug introduced in v0.1.2 - domain constructors without custom views throw errors
-
-Mar 17, 2011 - release v0.1.4
-
- added ability to do a findAllBy() with a start and end key
- moved dateCreated and lastUpdated to be created earlier so that finders work with them
-
-Mar 18, 2011 - release v0.1.5
-
- removed requirement for filename to match the passed name of the constructor or to return the name of the constructor in the js file it is defined in
-
-May 23, 2011 - release v0.1.6
-
- Changed layout to match new npm and node module layout - This was causing tests not to work and the example files not to work
- Changed package.json file to add cradle as a dependency
View
@@ -66,38 +66,35 @@ exports.create = function(name, config, constr) {
factory.addView = function() {
addView.apply(factory, arguments);
}
+ factory.viewNames = [];
return exports[name] = factory;
function addFinders(callback) {
for (prop in config.properties) {
- addFindAllBy(prop);
- addFindBy(prop);
+ addFinders(prop);
}
for (view in config.views) {
- addFindAllBy(view);
- addFindBy(view);
+ addFinders(view);
}
- addFindAllBy('id');
- addFindBy('id');
+ addFinders('id');
addList();
callback();
- function addFindAllBy(prop) {
- factory['findAllBy' + toUpper(prop)] = function(value, callback) {
- executeView(prop, value, callback);
- }
- }
+ function addFinders(finderName) {
+ var upperName = toUpper(finderName);
+ factory['findAllBy' + upperName] = function(value, callback) {
+ executeView(finderName, value, callback);
+ }
- function addFindBy(prop) {
- var upperName = toUpper(prop);
factory['findBy' + upperName] = function(value, callback) {
factory['findAllBy' + upperName](value, function(results) {
callback(results[0]);
});
}
+ factory.viewNames.push(finderName);
}
function addList() {
@@ -158,6 +155,7 @@ exports.create = function(name, config, constr) {
callback();
});
}
+ factory.viewNames.push(viewName);
}
View
@@ -230,6 +230,16 @@ describe('TestUser', function() {
});
+ describe('.viewNames', function() {
+ it('should have viewNames', function() {
+ var viewNames = domain.TestUser.viewNames;
+ expect(viewNames).toContain('username');
+ expect(viewNames).toContain('id');
+ expect(viewNames).toContain('firstOrLastName');
+ expect(viewNames).toContain('lastAndFirstName');
+ });
+ });
+
describe('remove() method', function() {
it('should remove a record from couchDb', function() {
domain.TestUser.findAllByUsername(['tester','testerZ'], function(users) {

0 comments on commit 93927b7

Please sign in to comment.