臭名昭著的AbstractController :: ActionNotFound-设计+ Rails [英] Infamous AbstractController::ActionNotFound - Devise + Rails

查看:167
本文介绍了臭名昭著的AbstractController :: ActionNotFound-设计+ Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经阅读了如何解决此问题:

So I have read how to solve this problem:

RSpec Test of Custom Devise Session Controller Fails with AbstractController::ActionNotFound

http://lostincode.net/ Blog / testing-devise-controllers

但是我要在哪个文件下添加这些更改是我的问题:

But under which file do I add these changes is my problem:

我的


registrations_controller

registrations_controller

我尝试过此操作

before :each do
  request.env['devise.mapping'] = Devise.mappings[:user]
end

require 'spec_helper'

describe RegistrationsController do

  describe "GET 'edit'" do
    it "should be successful" do
      get 'edit'
      response.should be_success
    end
  end

end

不起作用的地方,将不胜感激对特定文件进行更改以使其起作用的帮助。

Which didn't work, any help with the specific files to change to make this work would be greatly appreciated.

EDIT

所以我也尝试过-

https://github.com/ plataformatec / devise / wiki /操作方法:控制器和视图测试与Rails-3-(and-rspec)

so我用规格/支持创建了一个文件夹,并创建了一个名为 controllers_macros.rb

so I made a folder with spec/support and made a file called controllers_macros.rb

module ControllerMacros
  def login_admin
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:admin]
      sign_in Factory.create(:admin) # Using factory girl as an example
    end
  end

  def login_user
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      user = Factory.create(:user)
      user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module
      sign_in user
    end
  end
end

$ b时才需要
$ b

我的 registrations_controller 现在是这个:

And my registrations_controller is now this:

require 'spec_helper'

describe RegistrationsController do

  describe "GET 'edit'" do
    before :each do
      request.env['devise.mapping'] = Devise.mappings[:user]
    end
    it "should be successful" do
      get 'edit'
      response.should be_success
    end
  end

end

我在rspec中还有其他控制器,是否需要更改每个控制器单身吗?还是对在哪里进行更改感到困惑。

I have other controllers in rspec do I need to change every single one? Or I'm confused on where to make the changes.

推荐答案

只需采用您尝试过的第一个版本,但将<$在第一个describe块内部的c $ c> before 块之内,如下所示:

Just take the first version you tried, but move the before block inside the first describe block like this:

require 'spec_helper'

describe RegistrationsController do
  before :each do
    request.env['devise.mapping'] = Devise.mappings[:user]
  end

  describe "GET 'edit'" do
    it "should be successful" do
      get 'edit'
      response.should be_success
    end
  end
end

这篇关于臭名昭著的AbstractController :: ActionNotFound-设计+ Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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