2017-11-20 10 views
0

다음과 같은 스펙이 있습니다.Rails Capybara 로그인 할 수 없습니다.

it 'should login with correct user/password', 
    js: true, driver: :selenium do 

    visit new_user_session_path 

    fill_in 'user_email', with: user.email 
    fill_in 'user_password', with: user.password 
    click_on 'loginButton' 

    expect_current_path(home_path) 

end 

driver: :selenium을 제거하면 작동합니다. 나는 그것이 거래를위한 RSpec Configuration 때문이라고 생각했다. 따라서 Database Cleaner를 추가하고 config.use_transactional_fixtures = false을 비활성화했습니다. 그러나 여전히 실패했다. 나는 다음과 같이 Devise (devise-4.2.1/l ib/devise/strategies/database_authenticatable.rb)를 디버깅했다.

def authenticate! 
    resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash) 
    hashed = false 

    debugger 
    if validate(resource){ hashed = true; resource.valid_password?(password) } 
     remember_me(resource) 
     resource.after_database_authentication 
     success!(resource) 
    end 

    mapping.to.new.password = password if !hashed && Devise.paranoid 
    fail(:not_found_in_database) unless resource 
    end 

확인한 결과 mapping.to.find_for_database_authentication(authentication_hash)은 원하는대로 사용자를 반환합니다. 그러나 validate(resource)은 (는) 셀렌 ON이 실패했습니다. 나는 그것에 더 많은 것을 조사했고, def self.compare(klass, hashed_password, password)이 근본 원인 (devise-4.2.1/l ib/devise/encryptor.rb에서)이라는 것을 알았다.

그래서 주된 이유는 암호를 비교할 수 없었기 때문입니다. 암호화와 관련이 있다고 생각합니다. 누군가 도울 수 있습니까?

답변

0

미친 시간이 지나면 나는 이것에 대한 답을 발견했습니다. 문제는 Capybara Selenium입니다. 3 번을 좋아하지 않습니다. 설명해 드리겠습니다. 내 user.password는 '12345678'이고 코드는 '1245678'

fill_in 'user_email', with: user.email 
fill_in 'user_password', with: user.password 

I는 '331', '123'등 다양한 조합을 시도했습니다 채 웁니다. 그들은 모두 3 번을 제거했습니다. 그러므로, 나는 나의 테스트 암호를 'abcd'로 바꾸었다. 다음은 내 Gemfile.lock에서 얻은 것입니다.

capybara (2.13.0) 
rspec (3.6.0) 
selenium-webdriver (3.4.3)