Giải phápNâng cấp để đưa ra 3.1 => nhận được Thiết lập lại mật khẩu thẻ không hợp lệ
Nhờ gist hình thức này Steven Harman, tôi đã nhận nó làm việc. devise_mail_helpers.rb
module Features
module MailHelpers
def last_email
ActionMailer::Base.deliveries[0]
end
# Can be used like:
# extract_token_from_email(:reset_password)
def extract_token_from_email(token_name)
mail_body = last_email.body.to_s
mail_body[/#{token_name.to_s}_token=([^"]+)/, 1]
end
end
end
tôi đã thêm các tập tin devise_mail_helpers.rb
vào thư mục tương tự như các tính năng kỹ thuật và viết spec này.
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) # Here I call the MailHelper form above
visit edit_password_url(reset_password_token: token)
fill_in "user_password", :with => "foobar"
fill_in "user_password_confirmation", :with => "foobar1"
find('.signup_firm').find(".submit").click
page.should have_content("Password confirmation doesn't match Password")
end
end
Điều này đảm bảo thông số kỹ thuật, làm cho trình duyệt hoạt động trong trình duyệt xem câu trả lời của Dave bên dưới.
Câu hỏi gốc
Trong ray của tôi 4 ứng dụng, tôi đã nâng cấp devise đến 3.1 và chạy rails s
, sau đó tôi nhận điều này:
`raise_no_secret_key': Devise.secret_key was not set.
Please add the following to your Devise initializer: (RuntimeError)
config.secret_key = '--secret--'
tôi thêm chìa khóa bí mật để initializer devise .
Sau này tôi nhận được lỗi sau khi tôi cố gắng để thiết lập lại mật khẩu
Reset password token is invalid
Nó có vẻ như các token được gửi trong email là không đúng. Mọi thứ khác đang hoạt động. Tôi đăng nhập vào và ra như một con dao máng ấm áp.
Cập nhật
Bây giờ tôi đoán rằng nó đã nhận được một cái gì đó với mã hóa của reset_password_token
đây từ tính năng spec:
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")
lỗi xảy ra là:
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"
Bất kỳ ý tưởng nào về những gì tôi đang thiếu?
Đây là giải pháp đúng để làm cho nó hoạt động trên trình duyệt, nhưng làm thế nào để kiểm tra nó? –
Trong nháy mắt, kiểm tra Rspec của bạn ở trên trông giống như nó nên làm các trick. Giả sử sự cố 'mã thông báo không hợp lệ' đã biến mất và nếu nó không thành công tại một vị trí cụ thể, bạn nên chia sẻ lỗi. Về mặt chiến lược, việc kết hợp Rspec hoặc Cucumber với email_spec sẽ cho phép bạn tự động kiểm tra điều này. Câu hỏi liên kết của tôi và [wiki này] (https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Cucumber) có thêm thông tin về cách kiểm tra Devise with Cucumber. –
bài kiểm tra đang trôi qua. Trước khi tôi khắc phục sự cố, nó đã bị lỗi với 'mã thông báo không hợp lệ'. –