Skip to content

Commit

Permalink
upgrade to firenze v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fahad19 committed Aug 22, 2015
1 parent 02611bd commit d8c31fd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 64 deletions.
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -23,7 +23,7 @@
"tests"
],
"dependencies": {
"firenze": "^0.1.5",
"firenze": "^0.2.0",
"lodash": "^3.7.0"
}
}
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -43,7 +43,7 @@
"lodash": "~3.7.0"
},
"peerDependencies": {
"firenze": "~0.1.5"
"firenze": "~0.2.0"
},
"devDependencies": {
"babel": "^5.1.10",
Expand All @@ -52,8 +52,8 @@
"doctoc": "^0.13.0",
"docume": "^0.1.4",
"eslint": "^0.20.0",
"firenze": "~0.1.5",
"firenze-adapter-memory": "^0.1.2",
"firenze": "~0.2.0",
"firenze-adapter-memory": "^0.2.0",
"istanbul": "^0.3.15",
"karma": "^0.12.36",
"karma-mocha": "^0.1.10",
Expand Down
17 changes: 9 additions & 8 deletions src/index.js
Expand Up @@ -13,7 +13,8 @@ let P = f.Promise;
// For example, when saving a post with the title `Hello World`:
//
// ```js
// var post = new Post({
// var posts = new Posts();
// var post = posts.model({
// title: 'Hello World'
// });
//
Expand Down Expand Up @@ -41,7 +42,7 @@ let P = f.Promise;
//
// // create your Database instance...
//
// db.createModelClass({
// db.createCollectionClass({
// behaviors: [
// SlugBehavior
// ]
Expand All @@ -51,7 +52,7 @@ let P = f.Promise;
// If you want to pass extra configuration options:
//
// ```js
// db.createModelClass({
// db.createCollectionClass({
// behaviors: [
// {
// 'class': SlugBehavior
Expand Down Expand Up @@ -95,25 +96,25 @@ export default class Slug extends Behavior {
super(...args);

this.options = _.merge({
source: this.model.displayField,
source: this.collection.displayField,
field: 'slug',
separator: '-'
}, this.options);
}

beforeSave() {
if (!this.model.isNew()) {
beforeSave(model) {
if (!model.isNew()) {
return new P.resolve(true);
}

let source = this.model.get(this.options.source);
let source = model.get(this.options.source);
let slug = _.chain(source.toLowerCase())
.deburr()
.words()
.join(this.options.separator)
.value();

this.model.set(this.options.field, slug);
model.set(this.options.field, slug);
return new P.resolve(true);
}
}
17 changes: 5 additions & 12 deletions src/test/cases/Model.js
Expand Up @@ -9,12 +9,12 @@ describe('Model', function () {
before(function (done) {
this.db = new lib.Database(config);

this.Post = require('../models/Post')(this.db);
this.Posts = require('../collections/Posts')(this.db);
this.postsData = require('../fixtures/posts');

this.db.getAdapter().loadAllFixtures([
{
model: new this.Post(),
collection: new this.Posts(),
rows: this.postsData
}
]).then(function () {
Expand All @@ -25,19 +25,12 @@ describe('Model', function () {
});

after(function (done) {
this.db.close(done);
});

it('should have a collection', function () {
var post = new this.Post();
post.should.have.property('collection');

var posts = post.collection();
posts.should.have.property('table').which.is.exactly('posts');
this.db.close().then(done);
});

it('should create a new record, with slug', function (done) {
var post = new this.Post({
var posts = new this.Posts();
var post = posts.model({
title: 'New Post'
});
post.save().then(function (model) {
Expand Down
32 changes: 29 additions & 3 deletions src/test/collections/Posts.js
@@ -1,9 +1,35 @@
var SlugBehavior = require('../../');

module.exports = function (db) {
return db.createCollectionClass({
table: 'posts',

modelClass: function () {
return require('../models/Post')(db);
}
alias: 'Post',

displayField: 'title',

schema: {
id: {
type: 'increments'
},
title: {
type: 'string'
},
slug: {
type: 'text'
}
},

behaviors: [
{
class: SlugBehavior,
options: {
field: 'slug',
source: 'title'
}
}
],

modelClass: require('../models/Post')
});
};
37 changes: 0 additions & 37 deletions src/test/models/Post.js

This file was deleted.

0 comments on commit d8c31fd

Please sign in to comment.