Decision
Thanks to this gist form of Stephen Harman, I got her job. devise_mail_helpers.rb
module Features module MailHelpers def last_email ActionMailer::Base.deliveries[0] end
I added the devise_mail_helpers.rb file to the same folder as the function specifications, and wrote this specification.
require 'devise_mail_helpers.rb' include Features include MailHelpers describe "PasswordResets" do it "emails user when requesting password reset" do user = FactoryGirl.create(:user) visit root_url find("#login_link").click click_link "Forgot your password?" fill_in "Email", :with => user.email click_button "Send instructions" current_path.should eq('/users/sign_in') page.should have_content("You will receive an email with instructions about how to reset your password in a few minutes.") last_email.to.should include(user.email) token = extract_token_from_email(:reset_password)
This will take care of the specs to make it work in the browser, look at Dave's answer below.
Original question
In my 4 rails application, I updated the application to version 3.1 and ran rails s , after which I got the following:
`raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError) config.secret_key = '--secret--'
I added a secret key to the project initializer.
After that, I get the following error when trying to reset the password
Reset password token is invalid
It seems that the token sent by email is incorrect. Everything else works. I come in and go out like a warm knife with butter.
Update
Now I assume that it should be something with encryption reset_password_token Here from the function specification:
user = FactoryGirl.create(:user, :reset_password_token => "something", :reset_password_sent_at => 1.hour.ago) visit edit_password_url(user, :reset_password_token => user.reset_password_token) fill_in "user_password", :with => "foobar" click_button "Change my password" page.should have_content("Password confirmation doesn't match Password")
An error has occurred:
Failure/Error: page.should have_content ("Password confirmation doesn't match Password") expected to find text "Password confirmation doesn't match Password" in "Reset password token is invalid"
Any ideas on what I am missing?
ruby-on-rails ruby-on-rails-4 devise rspec2 factory-bot
Andreas Lyngstad Sep 06 '13 at 15:47 2013-09-06 15:47
source share