我想寫一個軌道集成測試(使用ActionDispatch::IntegrationTest
)。我正在使用設計進行認證和機械師測試模型。我無法成功登錄使用設計寶石的Rails集成測試
下面是一個簡單的例子:
class UserFlowsTest < ActionDispatch::IntegrationTest
setup do
User.make
end
test "sign in to the site"
# sign in
post_via_redirect 'users/sign_in', :email => '[email protected]', :password => 'qwerty'
p flash
p User.all
end
下面是調試輸出:
Loaded suite test/integration/user_flows_test
Started
{:alert=>"Invalid email or password."}
[#<User id: 980190962, email: "", encrypted_password: "", password_salt: "", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2010-11-27 16:44:10", updated_at: "2010-11-27 16:44:10">, #<User id: 980190963, email: "[email protected]", encrypted_password: "$2a$10$vYSpjIfAd.Irl6eFvhJL0uAwp4qniv5gVl4O.Hnw/BUR...", password_salt: "$2a$10$vYSpjIfAd.Irl6eFvhJL0u", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2010-11-27 17:09:13", updated_at: "2010-11-27 17:09:13">]
"/unauthenticated"
F
這裏是我的blueprints.rb:
require 'machinist/active_record'
require 'sham'
User.blueprint do
email {"[email protected]"}
password {"qwerty"}
end
我最近開始閱讀Rails Test Prescriptions(http://pragprog.com/titles/nrtest/rails-test-prescriptions)。在書中相當早的時候,Noel提到他將使用Devise進行認證。我跳到github.com看他的示例應用程序(https://github.com/noelrappin/huddle),看看他是否能解決這個問題。雖然他沒有任何集成測試功能,但我將其發佈在此處供參考。 – hiwaylon 2010-11-30 12:40:09
我也切換(返回)在我的應用程序中使用AuthLogic(https://github.com/binarylogic/authlogic)進行身份驗證。我之前使用過它,喜歡它比Devise好得多。 – hiwaylon 2010-11-30 12:41:37