如何在 RefineryCMS 测试中登录用户? [英] How to login a user in RefineryCMS tests?
问题描述
我正在精炼CMS中开发一个自定义控制器,放置在应用程序的根目录
I'm developing a custom controller in refineryCMS, that placed in the root of the app
class ExchangeController < ApplicationController
def exchange
end
end
它工作正常,但要对其进行测试,我需要像这样登录炼油厂用户
It works fine, but to have it tested I need to login a refinery user like this
describe "Exchange action" do
login_refinery_user
it 'should return a 200' do
get '/exchange'
response.code.should == '200'
end
end
但它不起作用:((未定义的局部变量或方法`login_refinery_user')没有调用我得到的登录方法找不到表'refinery_roles'
But it just doesn't work :( (undefined local variable or method `login_refinery_user') Without calling that login method im getting Could not find table 'refinery_roles'
有人能指出我正确的方向吗?
Could someone point me in the right direction?
推荐答案
对于 Refinery 2,所需要的只是 spec/support/devise.rb 中的以下几行:
For Refinery 2, all that's needed are the following lines in spec/support/devise.rb:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.extend ::Refinery::Testing::ControllerMacros::Authentication, :type => :controller
config.extend ::Refinery::Testing::RequestMacros::Authentication, :type => :request
end
现在login_refinery_user"将与其他助手一起使用https://github.com/resolve/refinerycms/blob/master/testing/lib/refinery/testing/controller_macros/authentication.rb 和https://github.com/resolve/refinerycms/blob/master/testing/lib/refinery/testing/request_macros/authentication.rb
Now "login_refinery_user" will be available along with the other helpers from https://github.com/resolve/refinerycms/blob/master/testing/lib/refinery/testing/controller_macros/authentication.rb and https://github.com/resolve/refinerycms/blob/master/testing/lib/refinery/testing/request_macros/authentication.rb
这篇关于如何在 RefineryCMS 测试中登录用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!