Skip to content

Commit a9d9b52

Browse files
committed
Add lowercase config
1 parent bbf59b1 commit a9d9b52

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

lib/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function SlugsHook(sails) {
4141

4242
model.beforeCreate = ((previousBeforeCreate, from) => function(values, cb) {
4343

44-
let slugName = slug(values[from]);
44+
let slugName = slug(values[from], {lower: sails.config.slugs.lowercase});
4545

4646
let criteria = {};
4747
criteria[name] = slugName;
@@ -75,13 +75,15 @@ function SlugsHook(sails) {
7575

7676
return {
7777

78-
configure: function() {
79-
78+
defaults: {
79+
__configKey__: {
80+
lowercase: true
81+
}
8082
},
8183

8284
initialize: function(next) {
8385

84-
loadModels();
86+
//loadModels();
8587

8688
sails.after(['hook:moduleloader:loaded'], function() {
8789

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"babel": "babel lib --out-dir dist/lib",
88
"pretest": "npm run babel",
9-
"test": "mocha test/bootstrap.test.js test/unit/**/*.test.js --compilers js:babel-core/register",
9+
"test": "mocha test/bootstrap.test.js test/unit/*.test.js test/unit/**/*.test.js --compilers js:babel-core/register",
1010
"prepublish": "npm run babel"
1111
},
1212
"keywords": [

test/unit/models/Post.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ describe('PostModel', function() {
2020

2121
post.should.have.property('slug');
2222
post.slug.should.be.a.String();
23-
post.slug.should.be.eql('This-is-a-new-post');
23+
post.slug.should.be.eql('this-is-a-new-post');
2424

2525
post.should.have.property('slugAuthor');
2626
post.slugAuthor.should.be.a.String();
27-
post.slugAuthor.should.be.eql('Jeremie-Ledentu');
27+
post.slugAuthor.should.be.eql('jeremie-ledentu');
2828
done();
2929
})
3030
.catch(done);
@@ -47,11 +47,11 @@ describe('PostModel', function() {
4747

4848
post.should.have.property('slug');
4949
post.slug.should.be.a.String();
50-
post.slug.should.not.be.eql('This-is-a-new-post');
50+
post.slug.should.not.be.eql('this-is-a-new-post');
5151

5252
post.should.have.property('slugAuthor');
5353
post.slugAuthor.should.be.a.String();
54-
post.slugAuthor.should.not.be.eql('Jeremie-Ledentu');
54+
post.slugAuthor.should.not.be.eql('jeremie-ledentu');
5555
done();
5656
})
5757
.catch(done);
@@ -66,13 +66,13 @@ describe('PostModel', function() {
6666
});
6767

6868
it('should return the entity with given slug', function(done) {
69-
Post.findOneBySlug('This-is-a-new-post')
69+
Post.findOneBySlug('this-is-a-new-post')
7070
.then(function(post) {
7171
post.should.have.property('title');
7272
post.title.should.be.a.String();
7373
post.title.should.be.eql('This is a new post!!!');
7474
post.slug.should.be.a.String();
75-
post.slug.should.be.eql('This-is-a-new-post');
75+
post.slug.should.be.eql('this-is-a-new-post');
7676
done();
7777
})
7878
.catch(done);

test/unit/slugsHook.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
describe('SlugsHook', function() {
2+
3+
it('should add default config', function(done) {
4+
sails.config.should.have.property('slugs');
5+
sails.config.slugs.should.have.property('lowercase');
6+
sails.config.slugs.lowercase.should.be.eql(true);
7+
done();
8+
});
29
});

0 commit comments

Comments
 (0)