mirror of
https://github.com/fergalmoran/roboto-promoto.git
synced 2025-12-22 09:37:37 +00:00
Fixed merge conflicts
This commit is contained in:
@@ -13,9 +13,4 @@ var PromotionSchema = new Schema({
|
|||||||
/* Indexes */
|
/* Indexes */
|
||||||
PromotionSchema.index({title: 1, user: 1}, {unique: true});
|
PromotionSchema.index({title: 1, user: 1}, {unique: true});
|
||||||
|
|
||||||
/* Operations */
|
|
||||||
PromotionSchema.statics.findByTitle = function(title, cb){
|
|
||||||
this.findOne({title: title}, cb);
|
|
||||||
};
|
|
||||||
|
|
||||||
mongoose.model('Promotion', PromotionSchema);
|
mongoose.model('Promotion', PromotionSchema);
|
||||||
|
|||||||
@@ -1,83 +1,83 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var should = require('should'),
|
var should = require('should'),
|
||||||
mongoose = require('mongoose'),
|
mongoose = require('mongoose'),
|
||||||
Promotion = mongoose.model('Promotion'),
|
Promotion = mongoose.model('Promotion'),
|
||||||
User = mongoose.model('User');
|
User = mongoose.model('User');
|
||||||
|
|
||||||
var promotion, promotion2;
|
var promotion, promotion2;
|
||||||
var user;
|
var user;
|
||||||
|
|
||||||
describe('Promotion Model', function() {
|
describe('Promotion Model', function () {
|
||||||
before(function(done) {
|
before(function (done) {
|
||||||
user = new User({
|
user = new User({
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
name: 'Fake User',
|
name: 'Fake User',
|
||||||
email: 'test@test.com',
|
email: 'test@test.com',
|
||||||
password: 'password'
|
password: 'password'
|
||||||
});
|
});
|
||||||
promotion = new Promotion({
|
promotion = new Promotion({
|
||||||
title: 'Test Prom 1',
|
title: 'Test Prom 1',
|
||||||
user: user
|
user: user
|
||||||
});
|
});
|
||||||
promotion2 = new Promotion({
|
promotion2 = new Promotion({
|
||||||
title: 'Test Prom 1',
|
title: 'Test Prom 1',
|
||||||
user: user
|
user: user
|
||||||
});
|
});
|
||||||
// Clear promotions before testing
|
// Clear promotions before testing
|
||||||
Promotion.remove().exec();
|
Promotion.remove().exec();
|
||||||
User.remove().exec();
|
User.remove().exec();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function(done) {
|
afterEach(function (done) {
|
||||||
//going to leave the data intact post test
|
//going to leave the data intact post test
|
||||||
//as it is removed in before()
|
//as it is removed in before()
|
||||||
//Promotion.remove().exec();
|
//Promotion.remove().exec();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should begin with no promotions', function(done) {
|
it('should begin with no promotions', function (done) {
|
||||||
Promotion.find({}, function(err, promotions) {
|
Promotion.find({}, function (err, promotions) {
|
||||||
promotions.should.have.length(0);
|
promotions.should.have.length(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Save methods', function(){
|
describe('Save methods', function () {
|
||||||
it('should be able to save', function(done){
|
it('should be able to save', function (done) {
|
||||||
promotion.save(function(err){
|
promotion.save(function (err) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should fail when saving without a user', function(done) {
|
it('should fail when saving without a user', function (done) {
|
||||||
promotion.user = '';
|
promotion.user = '';
|
||||||
promotion.save(function(err) {
|
promotion.save(function (err) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should fail when saving without a title', function(done) {
|
it('should fail when saving without a title', function (done) {
|
||||||
promotion.title = '';
|
promotion.title = '';
|
||||||
promotion.save(function(err) {
|
promotion.save(function (err) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should fail when saving a duplicate promotion', function(done){
|
it('should fail when saving a duplicate promotion', function (done) {
|
||||||
promotion.save(function(err){
|
promotion.save(function (err) {
|
||||||
promotion2.save(function(err){
|
promotion2.save(function (err) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Search methods', function(){
|
describe('Search methods', function () {
|
||||||
it('should find promotion by title', function(done){
|
it('should find promotion by title', function (done) {
|
||||||
debugger;
|
Promotion.findOne({title: 'Test Prom 1', user: user}, function (err, result) {
|
||||||
Promotion.findByTitle('Test Prom 1', function(result){
|
|
||||||
should.exist(result);
|
should.exist(result);
|
||||||
|
should.not.exist(err);
|
||||||
result.title.should.equal('Test Prom 1');
|
result.title.should.equal('Test Prom 1');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user