我在rails 3.2上使用 capybara / rspec / selenium / devise_invitable
请参阅此规范,它会邀请用户并邮寄邀请网址。我从电子邮件正文中提取invitation_token并尝试访问接受邀请网址,如下所示。 ('/ users / invitation / accept?'+ inv_token)
仅供参考:如果我没有设置它会起作用:js =>真
require 'spec_helper'
describe "LoginSpec" do
it "Click enquiries tabs", :js => true do
build(:user) do |user|
user.invite!
last_email.to.should include(user.email)
inv_url = Capybara.string(last_email.body.encoded).first(".inbox > a")[:href]
inv_token = inv_url.split("?")[1]
inv_url_final = '/users/invitation/accept?' + inv_token
visit inv_url_final
end
end
end
但是这会一直重定向到'/ users / sign_in'。这是测试日志。
Started GET "/users/invitation/accept?invitation_token=Ww-y2QbgsswZCgovAzWx" for 127.0.0.1 at 2014-01-30 04:47:14 +0530
Processing by Users::InvitationsController#edit as HTML
Parameters: {"invitation_token"=>"Ww-y2QbgsswZCgovAzWx"}
[1m[36mUser Load (0.7ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`invitation_token` = 'e75e32adac5414243930d19e927c8a6275c404b8296757e77dc4a49b2593882a' LIMIT 1[0m
[1m[35mUser Load (0.6ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`invitation_token` = 'Ww-y2QbgsswZCgovAzWx' LIMIT 1
Redirected to http://127.0.0.1:56113/
Filter chain halted as :resource_from_invitation_token rendered or redirected
有任何帮助吗?
答案 0 :(得分:0)
您的spec_helper中的以下内容有效,来自 http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end