0

我正在使用ember-cli-simple-authember-cli-simple-auth-devise在一个ember-cli项目中。

我还Session通过初始化程序自定义 simple-auth:

// app/initializers/custom-session.js
import Ember from 'ember';
import Session from 'simple-auth/session';

export default {
  name: 'custom-session',
  before: 'simple-auth',

  initialize: function(container, application) {
    Session.reopen({
      setCurrentUser: function() {
        var id = this.get('user_id'),
            self = this;

        if (!Ember.isEmpty(id)) {
          return container.lookup('store:main').find('user', id)
            .then(function(user) {
              self.set('currentUser', user);
            });
        }
      }.observes('user_id')
    });
  }
};

在一个简单的验收测试(一个简单的调用ok(1))中,我收到以下错误

Error: Assertion Failed: calling set on destroyed object  
Source:     
    at Adapter.extend.exception (localhost:4900/assets/vendor.js:57907:19)
    at apply (http://localhost:4900/assets/vendor.js:21143:27)
    at superWrapper [as exception] (localhost:4900/assets/vendor.js:20721:15)
    at RSVP.onerrorDefault (localhost:4900/assets/vendor.js:59827:26)
    at Object.__exports__.default.trigger (localhost:4900/assets/vendor.js:22673:13)
    at Promise._onerror (localhost:4900/assets/vendor.js:23397:16)
    at publishRejection (localhost:4900/assets/vendor.js:23804:17)
    at http://localhost:4900/assets/vendor.js:29217:9

如果我注释掉该self.set('currentUser', user);行,错误就会消失。

处理此问题的适当方法是什么?有没有办法在测试中忽略这个初始化程序?

我也收到此日志消息:

没有为 Ember 简单身份验证配置授权工厂 - 如果需要授权后端请求,请指定一个。

4

1 回答 1

1

首先,您应该将 Ember Simple Auth 更新到最新版本 0.6.4,它允许您指定自定义会话类而无需重新打开默认会话:https ://github.com/simplabs/ember-simple-auth/releases /标签/0.6.4

其次,关于授权者的警告仅仅意味着到后端服务器的请求将不会被授权(例如,没有授权头),因为没有定义授权者。这可能没问题,但取决于您的设置。

关于被破坏的对象问题,您可以简单地检查对象是否被破坏:

if (!self.isDestroyed) {
  self.set('currentUser', user);
}
于 2014-07-30T10:06:50.440 回答