Authlogic密码仅在测试模式下无效

时间:2012-04-14 09:45:07

标签: ruby ruby-on-rails-3 integration-testing capybara authlogic

我正在使用Authlogic和Rails 3.2.3。 Authlogic在开发模式下正确验证用户,我可以在注册后使用活动用户登录,但在测试模式下,当我使用Capybara I运行集成测试时出现password is not valid错误。

我确保密码相同,有效且我甚至尝试过设置


  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

我的数据库字段都允许使用varpted(255)

的crypted_pa​​ssword字段

+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| id                  | int(11)      | NO   | PRI | NULL    | auto_increment |
| crypted_password    | varchar(255) | NO   |     | NULL    |                |
| password_salt       | varchar(255) | NO   |     | NULL    |                |
| email               | varchar(255) | NO   |     | NULL    |                |
| persistence_token   | varchar(255) | NO   |     | NULL    |                |
| single_access_token | varchar(255) | NO   |     | NULL    |                |
| perishable_token    | varchar(255) | NO   |     | NULL    |                |
| login_count         | int(11)      | NO   |     | 0       |                |
| failed_login_count  | int(11)      | NO   |     | 0       |                |
| last_request_at     | datetime     | YES  |     | NULL    |                |
| current_login_at    | datetime     | YES  |     | NULL    |                |
| last_login_at       | datetime     | YES  |     | NULL    |                |
| current_login_ip    | varchar(255) | YES  |     | NULL    |                |
| last_login_ip       | varchar(255) | YES  |     | NULL    |                |
| name                | varchar(255) | NO   |     |         |                |
| created_at          | datetime     | NO   |     | NULL    |                |
| updated_at          | datetime     | NO   |     | NULL    |                |
| active              | tinyint(1)   | YES  |     | 0       |                |
+---------------------+--------------+------+-----+---------+----------------+


我正在使用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      

我的user_sessions_controller看起来像这样



  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

0 个答案:

没有答案