[英]devise not working properly in rails integration tests
所以首先,我使用的是Rails附帶的內置集成測試套件,而不是黃瓜,webrat等。我想在切換到另一個測試套件之前掌握內置套件。
使用裝置1.4.2和導軌3.1。
無論如何,我正在編寫一個集成測試,模擬用戶注冊一個帳戶,確認該帳戶,重新登錄並填寫表格。 這是事情似乎向南的地方。 據我所知,Devise的控制器創建動作有問題,由於devise的這些問題,current_user為零。 這是一個片段:
require 'test_helper'
class SignupTest < ActionDispatch::IntegrationTest
test "new signup and application" do
go_to_signup_page
create_new_account :user => {:email => "kjsdfkjksjdf@sdfsdf.com", :user_name => "dfdfdf",
:password => "dfdfdfdfdfdf", :password_confirmation => "dfdfdfdfdfdf"}
confirm_account_creation
go_to_signin_page
log_in
go_to_form
submit_form
end
.....其他測試...
def go_to_form
get "/applications/new"
assert_response :success
assert_template "applications/new"
assert_equal 'Please fill out this application', flash[:notice]
end
def submit_form
post "/applications", :application => {.....}
assert_response :redirect
assert_equal 'Application Successful ', flash[:notice]
end
在我的控制器中
before_filter :authenticate_user!
根據我的判斷,“ def go_to_form”可以通過。 但是,當我嘗試以“ def Submit_form”進行POST時,它告訴我我需要“請先登錄或注冊”,這是您嘗試在尚未登錄時訪問功能時的典型設計錯誤。 我認為這個問題也導致current_user為零。
如果我刪除before_filter,我要發布,但current_user仍然為NIL。
我無法解釋這里發生了什么。 除此CREATE動作外,所有其他動作都帶有飛色。
這是我正在使用FactoryGirl的工作代碼,通過這段代碼,您可以成功登錄,確保輸入了正確的電子郵件和密碼。 但是在Devise gem中也有內置的測試用例,看看那里。
setup do
@user = FactoryGirl.create(:user)
end
def do_login
visit '/'
click_link "Sign in"
fill_in 'user_email', :with => 'xxx@xxx.com'
fill_in 'user_password', :with => 'xxxx'
click_on('sign_in')
end
test 'should go to section index' do
do_login
assert page.has_content?('Signed in successfully.')
end
這是一家工廠:
FactoryGirl.define do
factory :user do
email "xxx@xxx.com"
password "xxxx"
password_confirmation "xxxx"
:user_name "admin"
confirmed_at "#{Time.now }"
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.