我在rails项目中使用describe('testing directive', function(){
const elemScope = element.isolateScope;
it('should trigger callingFn if loggedMsg is emitted', function(){
scope.$emit('loggedMsg');
scope.$apply();
//elemScope.callingFn will be called due to the apply. Is there a way to just spy on that fn being called?
}
});
gem进行用户身份验证。现在我有一个问题。
我想在默认登录过程之前添加条件,例如:
devise
此条件不应影响方法if admin?
sign in
else
error
end
,因为我使用此方法允许用户使用另一个隧道登录。
我尝试覆盖方法sign_in_and_redirect
,但它也影响了active_for_authentication?
如何实现这个?
答案 0 :(得分:0)
您可以覆盖默认的sessions_controller.rb并使用自定义条件重新创建它。以下是覆盖注册控制器的方法,它与Sessions控制器类似:https://gist.github.com/kinopyo/2343176
然后在自定义控制器中重新创建默认的创建操作但有条件。
这是默认的sessions_controller.rb https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb
这是使用条件
创建会话操作 # POST /resource/sign_in
def create
self.resource = warden.authenticate!(auth_options)
if [CONDITION]
set_flash_message!(:notice, :signed_in)
sign_in(resource_name, resource)
yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource)
else
[ERROR]
end
end