Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests for Riak adapter using Jake's new TestTask

  • Loading branch information...
commit f1cf5d5ea0c46121dad1221702eabecebbfb5550 1 parent e6ed1d1
mde authored
Showing with 83 additions and 0 deletions.
  1. +4 −0 Jakefile
  2. +79 −0 lib/model/adapters/riak/test.js
View
4 Jakefile
@@ -252,5 +252,9 @@ var p = new jake.NpmPublishTask('geddy', [
// Don't create the package-tasks when being called as a generator
if (!process.env.generator) {
jake.Task['npm:definePackage'].invoke();
+ var t = jake.TestTask('Geddy model-adapters', function () {
+ this.testName = 'testModelAdapters'
+ this.testFiles.include('lib/model/adapters/**/test.js');
+ });
}
View
79 lib/model/adapters/riak/test.js
@@ -0,0 +1,79 @@
+var path = require('path')
+ , lib = '../../../../lib'
+ , model
+ , assert = require('assert')
+ , tests
+ , Riak
+ , currentId
+ , User
+ , _params;
+
+// Load the basic Geddy toolkit
+require(path.join(lib, 'geddy'));
+
+geddy.config = {
+ i18n: {
+ defaultLocale: 'en-us'
+ }
+, db: {
+ riak: {
+ }
+ }
+};
+
+model = require(path.join(lib, 'model'));
+assert = require('assert');
+Riak = require('./index').Riak;
+
+model.adapter = {};
+geddy.model = model;
+
+User = function () {
+ this.property('login', 'string', {required: true});
+ this.property('password', 'string', {required: true});
+ this.property('confirmPassword', 'string', {required: true});
+ this.property('lastName', 'string');
+ this.property('firstName', 'string');
+
+ this.validatesPresent('login');
+ this.validatesFormat('login', /[a-z]+/, {message: 'Subdivisions!'});
+ this.validatesLength('login', {min: 3});
+ this.validatesConfirmed('password', 'confirmPassword');
+};
+
+User.prototype.someMethod = function () {
+ // Do some stuff on a User instance
+};
+
+User = geddy.model.register('User', User);
+
+geddy.model.adapter.User = new Riak({model: 'User'});
+
+_params = {
+ login: 'zzz',
+ password: 'asdf',
+ confirmPassword: 'asdf',
+ firstName: 'Neil'
+};
+
+tests = {
+ 'test validate and save item': function (next) {
+ var user = User.create(_params);
+ assert.ok(user.isValid());
+ user.save(function (err, data) {
+ assert.ok(data.isValid());
+ currentId = data.id;
+ next();
+ });
+ }
+
+, 'test load item': function (next) {
+ User.load(currentId, function (err, data) {
+ assert.ok(data.isValid());
+ next();
+ });
+ }
+
+};
+
+module.exports = tests;
Please sign in to comment.
Something went wrong with that request. Please try again.