我想写一个轨道集成测试(使用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