【发布时间】:2016-06-22 05:02:52
【问题描述】:
我正在尝试升级 Ember CLI 应用以使用 Simple Auth 1.0。我的验收测试不再起作用。我已将测试套件配置为针对作为我的 API 副本的 Rails 服务器运行。要登录,我是这样做的:
visit("/")
fillIn(".identification-field", "test@email.com");
fillIn(".password-field", "testpassword");
click(".btn.login-submit");
andThen(function(){
equal(currentSession(application).get('user_email'), "test@email.com");
});
这适用于 simple-auth 0.7.3,但不适用于 1.0.0。我在我的应用程序路由中添加了其他方法来设置会话,如下所示:
_populateCurrentUser: function() {
var user_id = this.get('session.data.user_id');
var user_email = this.get('session.data.user_email');
var _this = this;
return this.store.find('user', user_id).then(function(user){
_this.get('currentUser').set('content', user);
// Below is for backward-compatibility
_this.get('session').set('currentUser', user);
_this.get('session').set('user_id', user_id);
_this.get('session').set('user_email', user_email);
user;
});
}
sessionAuthenticated: function(){
this._populateCurrentUser();
this._super();
}
beforeModel: function() {
if (this.get('session.isAuthenticated')) {
return this._populateCurrentUser();
}
}
这是基于以下指南:http://miguelcamba.com/blog/2015/06/18/how-to-inject-the-current-user-using-ember-simple-auth/
当我运行应用程序但破坏了我的测试套件时,这非常有效。现在,当我登录时,似乎没有填充会话 - _populateCurrentUser 方法失败,因为 this.get('session.data.user_id') 未定义。
有人可以帮忙吗?也许是因为在 1.0 中自动使用了临时会话存储,但如果是这样,我不确定如何解决这个问题?
非常感谢
【问题讨论】:
标签: ember-cli ember-simple-auth