在我的控制器中,使用以下代码完成重定向:
会话控制器
def create
render js: "window.location.pathname = #{home_path.to_json}"
end
但是当我运行capybara时,login
提交后,它无法访问home_page:
describe "Login Test", :js => true do
before do
@user = FactoryGirl.create(:user)
end
it 'should show the users first name' do
visit login_path
fill_in 'email', with: @user.email
fill_in 'password', with: @user.password
click_button "Log In"
save_and_open_page
assert page.has_content? @user.first_name
end
end
当我通过添加launchy gem
并运行save_and_open_page
进行问题排查时,我会看到一个包含以下文字的页面:
window.location.pathname = "/"
Capybara给了我以下错误:
Capybara::ElementNotFound: Unable to find xpath "/html"
似乎水豚从未通过登录按钮。
答案 0 :(得分:0)
respond_to do |format|
format.js { render :js => 'window.location.href = "#{home_path.to_json}"' }
end