Просмотр исходного кода

Merge branch 'master' into wip-v1.6.3

Sotaro KARASAWA 8 лет назад
Родитель
Сommit
9cb9e8838f
2 измененных файлов с 62 добавлено и 60 удалено
  1. 2 1
      lib/routes/me.js
  2. 60 59
      test/models/page.test.js

+ 2 - 1
lib/routes/me.js

@@ -90,7 +90,8 @@ module.exports = function(crowi, app) {
       }
       }
 
 
       User.findOne({email: email}, (err, existingUserData) => {
       User.findOne({email: email}, (err, existingUserData) => {
-        if (existingUserData) {
+        // If another user uses the same email, an error will occur.
+        if (existingUserData && !existingUserData._id.equals(userData._id)) {
           debug('Email address was duplicated');
           debug('Email address was duplicated');
           req.form.errors.push('It can not be changed to that mail address');
           req.form.errors.push('It can not be changed to that mail address');
           return res.render('me/index', {});
           return res.render('me/index', {});

+ 60 - 59
test/models/page.test.js

@@ -6,22 +6,22 @@ var chai = require('chai')
   ;
   ;
 chai.use(sinonChai);
 chai.use(sinonChai);
 
 
-describe('Page', function () {
+describe('Page', () => {
   var Page = utils.models.Page,
   var Page = utils.models.Page,
     User   = utils.models.User,
     User   = utils.models.User,
     conn   = utils.mongoose.connection,
     conn   = utils.mongoose.connection,
     createdPages,
     createdPages,
     createdUsers;
     createdUsers;
 
 
-  before(function (done) {
-    Promise.resolve().then(function() {
+  before(done => {
+    Promise.resolve().then(() => {
       var userFixture = [
       var userFixture = [
         {name: 'Anon 0', username: 'anonymous0', email: 'anonymous0@example.com'},
         {name: 'Anon 0', username: 'anonymous0', email: 'anonymous0@example.com'},
         {name: 'Anon 1', username: 'anonymous1', email: 'anonymous1@example.com'}
         {name: 'Anon 1', username: 'anonymous1', email: 'anonymous1@example.com'}
       ];
       ];
 
 
       return testDBUtil.generateFixture(conn, 'User', userFixture);
       return testDBUtil.generateFixture(conn, 'User', userFixture);
-    }).then(function(testUsers) {
+    }).then(testUsers => {
       createdUsers = testUsers;
       createdUsers = testUsers;
       var testUser0 = testUsers[0];
       var testUser0 = testUsers[0];
 
 
@@ -65,17 +65,17 @@ describe('Page', function () {
       ];
       ];
 
 
       return testDBUtil.generateFixture(conn, 'Page', fixture)
       return testDBUtil.generateFixture(conn, 'Page', fixture)
-      .then(function(pages) {
+      .then(pages => {
         createdPages = pages;
         createdPages = pages;
         done();
         done();
       });
       });
     });
     });
   });
   });
 
 
-  describe('.isPublic', function () {
-    context('with a public page', function() {
-      it('should return true', function(done) {
-        Page.findOne({path: '/grant/public'}, function(err, page) {
+  describe('.isPublic', () => {
+    context('with a public page', () => {
+      it('should return true', done => {
+        Page.findOne({path: '/grant/public'}, (err, page) => {
           expect(err).to.be.null;
           expect(err).to.be.null;
           expect(page.isPublic()).to.be.equal(true);
           expect(page.isPublic()).to.be.equal(true);
           done();
           done();
@@ -83,10 +83,10 @@ describe('Page', function () {
       });
       });
     });
     });
 
 
-    ['restricted', 'specified', 'owner'].forEach(function(grant) {
-      context('with a ' + grant + ' page', function() {
-        it('should return false', function(done) {
-          Page.findOne({path: '/grant/' + grant}, function(err, page) {
+    ['restricted', 'specified', 'owner'].forEach(grant => {
+      context('with a ' + grant + ' page', () => {
+        it('should return false', done => {
+          Page.findOne({path: '/grant/' + grant}, (err, page) => {
             expect(err).to.be.null;
             expect(err).to.be.null;
             expect(page.isPublic()).to.be.equal(false);
             expect(page.isPublic()).to.be.equal(false);
             done();
             done();
@@ -96,22 +96,22 @@ describe('Page', function () {
     });
     });
   });
   });
 
 
-  describe('.getDeletedPageName', function() {
-    it('should return trash page name', function() {
+  describe('.getDeletedPageName', () => {
+    it('should return trash page name', () => {
       expect(Page.getDeletedPageName('/hoge')).to.be.equal('/trash/hoge');
       expect(Page.getDeletedPageName('/hoge')).to.be.equal('/trash/hoge');
       expect(Page.getDeletedPageName('hoge')).to.be.equal('/trash/hoge');
       expect(Page.getDeletedPageName('hoge')).to.be.equal('/trash/hoge');
     });
     });
   });
   });
-  describe('.getRevertDeletedPageName', function() {
-    it('should return reverted trash page name', function() {
+  describe('.getRevertDeletedPageName', () => {
+    it('should return reverted trash page name', () => {
       expect(Page.getRevertDeletedPageName('/hoge')).to.be.equal('/hoge');
       expect(Page.getRevertDeletedPageName('/hoge')).to.be.equal('/hoge');
       expect(Page.getRevertDeletedPageName('/trash/hoge')).to.be.equal('/hoge');
       expect(Page.getRevertDeletedPageName('/trash/hoge')).to.be.equal('/hoge');
       expect(Page.getRevertDeletedPageName('/trash/hoge/trash')).to.be.equal('/hoge/trash');
       expect(Page.getRevertDeletedPageName('/trash/hoge/trash')).to.be.equal('/hoge/trash');
     });
     });
   });
   });
 
 
-  describe('.isDeletableName', function() {
-    it('should decide deletable or not', function() {
+  describe('.isDeletableName', () => {
+    it('should decide deletable or not', () => {
       expect(Page.isDeletableName('/hoge')).to.be.true;
       expect(Page.isDeletableName('/hoge')).to.be.true;
       expect(Page.isDeletableName('/user/xxx')).to.be.false;
       expect(Page.isDeletableName('/user/xxx')).to.be.false;
       expect(Page.isDeletableName('/user/xxx123')).to.be.false;
       expect(Page.isDeletableName('/user/xxx123')).to.be.false;
@@ -120,8 +120,8 @@ describe('Page', function () {
     });
     });
   });
   });
 
 
-  describe('.isCreatableName', function() {
-    it('should decide creatable or not', function() {
+  describe('.isCreatableName', () => {
+    it('should decide creatable or not', () => {
       expect(Page.isCreatableName('/hoge')).to.be.true;
       expect(Page.isCreatableName('/hoge')).to.be.true;
 
 
       // edge cases
       // edge cases
@@ -168,13 +168,13 @@ describe('Page', function () {
     });
     });
   });
   });
 
 
-  describe('.isCreator', function() {
-    context('with creator', function() {
-      it('should return true', function(done) {
-        User.findOne({email: 'anonymous0@example.com'}, function(err, user) {
+  describe('.isCreator', () => {
+    context('with creator', () => {
+      it('should return true', done => {
+        User.findOne({email: 'anonymous0@example.com'}, (err, user) => {
           if (err) { done(err); }
           if (err) { done(err); }
 
 
-          Page.findOne({path: '/user/anonymous/memo'}, function(err, page) {
+          Page.findOne({path: '/user/anonymous/memo'}, (err, page) => {
             expect(page.isCreator(user)).to.be.equal(true);
             expect(page.isCreator(user)).to.be.equal(true);
             done();
             done();
           })
           })
@@ -182,12 +182,12 @@ describe('Page', function () {
       });
       });
     });
     });
 
 
-    context('with non-creator', function() {
-      it('should return false', function(done) {
-        User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
+    context('with non-creator', () => {
+      it('should return false', done => {
+        User.findOne({email: 'anonymous1@example.com'}, (err, user) => {
           if (err) { done(err); }
           if (err) { done(err); }
 
 
-          Page.findOne({path: '/user/anonymous/memo'}, function(err, page) {
+          Page.findOne({path: '/user/anonymous/memo'}, (err, page) => {
             expect(page.isCreator(user)).to.be.equal(false);
             expect(page.isCreator(user)).to.be.equal(false);
             done();
             done();
           })
           })
@@ -196,13 +196,13 @@ describe('Page', function () {
     });
     });
   });
   });
 
 
-  describe('.isGrantedFor', function() {
-    context('with a granted user', function() {
-      it('should return true', function(done) {
-        User.findOne({email: 'anonymous0@example.com'}, function(err, user) {
+  describe('.isGrantedFor', () => {
+    context('with a granted user', () => {
+      it('should return true', done => {
+        User.findOne({email: 'anonymous0@example.com'}, (err, user) => {
           if (err) { done(err); }
           if (err) { done(err); }
 
 
-          Page.findOne({path: '/user/anonymous/memo'}, function(err, page) {
+          Page.findOne({path: '/user/anonymous/memo'}, (err, page) => {
             if (err) { done(err); }
             if (err) { done(err); }
 
 
             expect(page.isGrantedFor(user)).to.be.equal(true);
             expect(page.isGrantedFor(user)).to.be.equal(true);
@@ -212,12 +212,12 @@ describe('Page', function () {
       });
       });
     });
     });
 
 
-    context('with a public page', function() {
-      it('should return true', function(done) {
-        User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
+    context('with a public page', () => {
+      it('should return true', done => {
+        User.findOne({email: 'anonymous1@example.com'}, (err, user) => {
           if (err) { done(err); }
           if (err) { done(err); }
 
 
-          Page.findOne({path: '/grant/public'}, function(err, page) {
+          Page.findOne({path: '/grant/public'}, (err, page) => {
             if (err) { done(err); }
             if (err) { done(err); }
 
 
             expect(page.isGrantedFor(user)).to.be.equal(true);
             expect(page.isGrantedFor(user)).to.be.equal(true);
@@ -227,12 +227,12 @@ describe('Page', function () {
       });
       });
     });
     });
 
 
-    context('with a restricted page and an user who has no grant', function() {
-      it('should return false', function(done) {
-        User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
+    context('with a restricted page and an user who has no grant', () => {
+      it('should return false', done => {
+        User.findOne({email: 'anonymous1@example.com'}, (err, user) => {
           if (err) { done(err); }
           if (err) { done(err); }
 
 
-          Page.findOne({path: '/grant/restricted'}, function(err, page) {
+          Page.findOne({path: '/grant/restricted'}, (err, page) => {
             if (err) { done(err); }
             if (err) { done(err); }
 
 
             expect(page.isGrantedFor(user)).to.be.equal(false);
             expect(page.isGrantedFor(user)).to.be.equal(false);
@@ -243,21 +243,21 @@ describe('Page', function () {
     });
     });
   });
   });
 
 
-  describe('Extended field', function () {
-    context('Slack Channel.', function() {
-      it('should be empty', function(done) {
-        Page.findOne({path: '/page/for/extended'}, function(err, page) {
+  describe('Extended field', () => {
+    context('Slack Channel.', () => {
+      it('should be empty', done => {
+        Page.findOne({path: '/page/for/extended'}, (err, page) => {
           expect(page.extended.hoge).to.be.equal(1);
           expect(page.extended.hoge).to.be.equal(1);
           expect(page.getSlackChannel()).to.be.equal('');
           expect(page.getSlackChannel()).to.be.equal('');
           done();
           done();
         })
         })
       });
       });
 
 
-      it('set slack channel and should get it and should keep hoge ', function(done) {
-        Page.findOne({path: '/page/for/extended'}, function(err, page) {
+      it('set slack channel and should get it and should keep hoge ', done => {
+        Page.findOne({path: '/page/for/extended'}, (err, page) => {
           page.updateSlackChannel('slack-channel1')
           page.updateSlackChannel('slack-channel1')
-          .then(function(data) {
-            Page.findOne({path: '/page/for/extended'}, function(err, page) {
+          .then(data => {
+            Page.findOne({path: '/page/for/extended'}, (err, page) => {
               expect(page.extended.hoge).to.be.equal(1);
               expect(page.extended.hoge).to.be.equal(1);
               expect(page.getSlackChannel()).to.be.equal('slack-channel1');
               expect(page.getSlackChannel()).to.be.equal('slack-channel1');
               done();
               done();
@@ -269,23 +269,23 @@ describe('Page', function () {
     });
     });
   });
   });
 
 
-  describe('Normalize path', function () {
-    context('Normalize', function() {
-      it('should start with slash', function(done) {
+  describe('Normalize path', () => {
+    context('Normalize', () => {
+      it('should start with slash', done => {
         expect(Page.normalizePath('hoge/fuga')).to.equal('/hoge/fuga');
         expect(Page.normalizePath('hoge/fuga')).to.equal('/hoge/fuga');
         done();
         done();
       });
       });
 
 
-      it('should trim spaces of slash', function(done) {
+      it('should trim spaces of slash', done => {
         expect(Page.normalizePath('/ hoge / fuga')).to.equal('/hoge/fuga');
         expect(Page.normalizePath('/ hoge / fuga')).to.equal('/hoge/fuga');
         done();
         done();
       });
       });
     });
     });
   });
   });
 
 
-  describe('.findPage', function () {
+  describe('.findPage', () => {
     context('findPageById', () => {
     context('findPageById', () => {
-      it('should find page', function(done) {
+      it('should find page', done => {
         const pageToFind = createdPages[0];
         const pageToFind = createdPages[0];
         Page.findPageById(pageToFind._id)
         Page.findPageById(pageToFind._id)
         .then(pageData => {
         .then(pageData => {
@@ -295,8 +295,8 @@ describe('Page', function () {
       });
       });
     });
     });
 
 
-    context('findPageByIdAndGrantedUser', function() {
-      it('should find page', function(done) {
+    context('findPageByIdAndGrantedUser', () => {
+      it('should find page', done => {
         const pageToFind = createdPages[0];
         const pageToFind = createdPages[0];
         const grantedUser = createdUsers[0];
         const grantedUser = createdUsers[0];
         Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
         Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
@@ -311,6 +311,7 @@ describe('Page', function () {
         const grantedUser = createdUsers[1];
         const grantedUser = createdUsers[1];
         Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
         Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
         .then(pageData => {
         .then(pageData => {
+          done(new Error());
         }).catch(err => {
         }).catch(err => {
           expect(err).to.instanceof(Error);
           expect(err).to.instanceof(Error);
           done();
           done();