Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Desive Rspec期望响应具有成功状态代码(2xx),但它是302_Ruby On Rails_Ruby_Rspec_Devise - Fatal编程技术网

Ruby on rails Desive Rspec期望响应具有成功状态代码(2xx),但它是302

Ruby on rails Desive Rspec期望响应具有成功状态代码(2xx),但它是302,ruby-on-rails,ruby,rspec,devise,Ruby On Rails,Ruby,Rspec,Devise,我有一个用户,我正在使用FactoryGirl创建该用户,它需要有一个公司,才能成功登录到我的根url 我没有任何运气,在所有的存根用户方法登录。我遵循了用户的Desive部分,需要对其进行一些修改,因为我的用户还需要一个公司与之关联 我现在创建了一个名为Scans的新模型/控制器,它位于Desive的authenticate过滤器后面,我的第一次测试失败是: 5) ScansController GET #show returns http success Failure/Error

我有一个
用户
,我正在使用FactoryGirl创建该用户,它需要有一个
公司
,才能成功登录到我的
根url

我没有任何运气,在所有的存根用户方法登录。我遵循了用户的Desive部分,需要对其进行一些修改,因为我的用户还需要一个
公司
与之关联

我现在创建了一个名为
Scans
的新模型/控制器,它位于Desive的
authenticate
过滤器后面,我的第一次测试失败是:

5) ScansController GET #show returns http success
     Failure/Error: expect(response).to have_http_status(:success)
       expected the response to have a success status code (2xx) but it was 302
     # ./spec/controllers/scans_controller_spec.rb:32:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:127:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:126:in `block (2 levels) in <top (required)>'
我正在对响应执行
放置
,因为我想查看返回的内容:

ScansController
  GET #show
302
{"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Location"=>"http://test.host/login", "Content-Type"=>"text/html; charset=utf-8"}
#<Rack::BodyProxy:0x007fb52a7407c0>
现在,我的登录功能目前不起作用(手动测试)。
ApplicationController
之后触发的第一个控制器是
PagesController\home

def home
  if current_user && current_user.company
     verify_subscription
     ....
  else
     redirect_to new_company_path
  end
end
如果
verify_subscription
失败,用户也会被发送到
new_company_path
,因此这似乎与此问题无关


基于我基本的rspec功能,我是否正确地假设我甚至没有接近模仿登录?如果没有,我做错了什么?

经过一番努力,我终于通过了考试。我最终在我的用户工厂中创建了一家公司:

after(:build) do |user|
  user.company = create(:company)
end

你也读过了吗,使用了
方法的
登录\u在哪里?@zettetic为你更新了rspec方法<代码>登录时使用
def home
  if current_user && current_user.company
     verify_subscription
     ....
  else
     redirect_to new_company_path
  end
end
after(:build) do |user|
  user.company = create(:company)
end