0

我有以下代码片段

def index
    session[:previous_url] = request.referer 

   if session[:previous_url].blank?
     redirect_to registration_path(id: current_user.associate_username)
   end 
end

我正在为它写一个测试测试:

describe 'index' do
  it 'renders the index page' do
    controller.stub(current_user: FactoryGirl.create(:admin_user))
    session = {}
    session[:previous_url] = 'http://example.com/new'
    get :index, params, session
    expect(response).to render_template(:index)
  end
end

这不允许我通过blank?. 有谁知道我可以通过其他方式blank?返回false而不是重定向。谢谢

4

2 回答 2

0

request.env["HTTP_REFERER"]你可以在你的before块中分配。像这样:

  before do
    request.env["HTTP_REFERER"] = "http://localhost:3000/"
  end
于 2013-10-23T14:22:40.363 回答
0

这个怎么样?

describe 'index' do
  it 'renders the index page' do
    controller.stub(current_user: FactoryGirl.create(:admin_user),
                    session: {previous_url: "http://example.com/new"})
    get :index, params, session
    expect(response).to render_template(:index)
  end
end
于 2013-10-23T14:22:57.797 回答