Ich habe eine Spezifikation wie folgt.Schienen Capybara kann nicht anmelden
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
Wenn ich driver: :selenium
entfernte, funktioniert es. Ich dachte, es ist wegen der RSpec-Konfiguration für Transaktionen. Daher habe ich Datenbank-Reiniger hinzugefügt und deaktiviert config.use_transactional_fixtures = false
. Es scheiterte jedoch immer noch. Ich debuggte Devise (devise-4.2.1/l ib/devise/strategies/database_authenticatable.rb) wie folgt.
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
Nach Überprüfung ich mapping.to.find_for_database_authentication(authentication_hash)
zurückgibt den Benutzer als wollte sehen. Bei Selen ON ist jedoch validate(resource)
ausgefallen. Ich habe mehr hineingecheckt und herausgefunden, dass def self.compare(klass, hashed_password, password)
die Ursache ist (in devise-4.2.1/l ib/devise/encryptor.rb).
Also der Hauptgrund war, weil es das Passwort nicht vergleichen konnte. Ich vermute, es hat mit Verschlüsselung zu tun. Kann jemand helfen?