Devise Test Helper - sign_in不工作 [英] Devise Test Helper - sign_in does not work

查看:138
本文介绍了Devise Test Helper - sign_in不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我无法获得设计帮助程序sign_in的工作。 current_user保持为null。任何想法可能是什么问题?

For some reason, I can not get the devise helper method sign_in to work. current_user keeps on being null. Any idea what the problem could be?

测试:

  before :each do
    @user = FactoryGirl.create :user
    sign_in @user
  end

  describe "GET index" do
    it "assigns all subscribers as @subscribers" do
      subscriber = @user.subscribers.create! valid_attributes
      get :index
      assigns(:subscribers).should eq([subscriber])
    end
  end

实现:

  def index
    @subscribers = current_user.subscribers.all    <------- ERROR

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @subscribers }
    end
  end

Error:
 NoMethodError:
       undefined method `subscribers' for nil:NilClass

任何帮助都赞赏。谢谢!

Any help is appreciated. Thanks!

推荐答案

看起来你解决了这个,你的代码判断。我之前发生过这种情况,由于某种原因,每次都会得到我。

Looks like you solved this, judging by your code. I have had this happen before, and for some reason it gets me every time.

控制器规范的rspec / rails脚手架不会与Devise :: TestHelpers关闭的盒子。

The rspec/rails scaffold for controller specs won't work with Devise::TestHelpers out of the box.

get :index, {}, valid_session

valid_session调用将覆盖Devise设置的会话内容。删除它:

The valid_session call overwrites the session stuff that Devise sets up. Remove it:

get :index, {}

这应该可以工作!

这篇关于Devise Test Helper - sign_in不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆