Ruby Authlogic密码仅在测试模式下无效
我正在使用Authlogic和Rails 3.2.3。Authlogic在开发模式下正确验证用户,注册后我可以与活动用户一起登录,但在测试模式下,当我使用Capybara I运行集成测试时,Ruby Authlogic密码仅在测试模式下无效,ruby,ruby-on-rails-3,integration-testing,capybara,authlogic,Ruby,Ruby On Rails 3,Integration Testing,Capybara,Authlogic,我正在使用Authlogic和Rails 3.2.3。Authlogic在开发模式下正确验证用户,注册后我可以与活动用户一起登录,但在测试模式下,当我使用Capybara I运行集成测试时,密码无效错误 我已经确保密码是相同的,有效的,我甚至尝试过设置 acts_as_authentic do |c| c.validate_password_field = false end 在我的测试中,我使用工厂,这是我的工厂定义 FactoryGirl.define do fac
密码无效
错误
我已经确保密码是相同的,有效的,我甚至尝试过设置
acts_as_authentic do |c|
c.validate_password_field = false
end
在我的测试中,我使用工厂,这是我的工厂定义
FactoryGirl.define do
factory :user do
sequence :email do |i|
"test_user_#{i}@example.com"
end
sequence :name do
|i| "test user#{i}"
end
password "testtesttest"
password_confirmation "testtesttest"
password_salt "passwordsalt"
perishable_token "windowintheskies"
single_access_token "123123123"
end
end
我的数据库字段都允许使用加密的\u密码字段,这些字段是Varchar(255)
我正在使用capybara运行集成测试,我发现错误只发生在测试模式中,而不是在开发模式中
此外,我确信密码不是空的
我的集成测试规范如下所示
require 'spec_helper'
describe "/lists" do
before(:each) do
@user = FactoryGirl.build(:user, :password => 'testtesttest', :password_confirmation => 'testtesttest')
@user.activate!
end
it "loads the list creation pages on clicking the new list button" do
visit new_user_session_path
fill_in "user_session_email", :with => @user.email
fill_in "user_session_password", :with => 'testtesttest'
click_button "Login"
page.should have_content "My Lists"
visit lists_path
click_link "Create A New List"
page.should have_content('New List')
end
def create
@user_session = UserSession.new(params[:user_session])
puts "*" * 50
puts " Password - #{params[:user_session][:password].to_s}"
puts " User #{User.where(:email => params[:user_session][:email]).first.inspect}"
puts "Valid #{User.where(:email => params[:user_session][:email]).first.valid_password?(params[:user_session][:password])}"
puts " Active = #{User.where(:email => params[:user_session][:email]).first.active?}"
puts "*" * 50
if @user_session.save!
flash[:notice] = "Login successful!"
redirect_back_or_default lists_url
else
puts "Error : #{@user_session.errors.inspect}"
render :action => :new
end
end
我的用户会话控制器如下所示
require 'spec_helper'
describe "/lists" do
before(:each) do
@user = FactoryGirl.build(:user, :password => 'testtesttest', :password_confirmation => 'testtesttest')
@user.activate!
end
it "loads the list creation pages on clicking the new list button" do
visit new_user_session_path
fill_in "user_session_email", :with => @user.email
fill_in "user_session_password", :with => 'testtesttest'
click_button "Login"
page.should have_content "My Lists"
visit lists_path
click_link "Create A New List"
page.should have_content('New List')
end
def create
@user_session = UserSession.new(params[:user_session])
puts "*" * 50
puts " Password - #{params[:user_session][:password].to_s}"
puts " User #{User.where(:email => params[:user_session][:email]).first.inspect}"
puts "Valid #{User.where(:email => params[:user_session][:email]).first.valid_password?(params[:user_session][:password])}"
puts " Active = #{User.where(:email => params[:user_session][:email]).first.active?}"
puts "*" * 50
if @user_session.save!
flash[:notice] = "Login successful!"
redirect_back_or_default lists_url
else
puts "Error : #{@user_session.errors.inspect}"
render :action => :new
end
end
奇怪,如果我从用户工厂中删除密码和密码确认块,我发现我的测试工作正常。奇怪,如果我从用户工厂中删除密码和密码确认块,我发现我的测试工作正常。