65 lines
1.7 KiB
Ruby
65 lines
1.7 KiB
Ruby
include ApplicationHelper
|
|
|
|
def cookie_jar
|
|
Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
|
end
|
|
|
|
|
|
def in_client(name) # to assist multiple-client RSpec/Capybara testing
|
|
Capybara.session_name = name
|
|
|
|
yield
|
|
end
|
|
|
|
|
|
def sign_in(user)
|
|
visit signin_path
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
# Sign in when not using Capybara as well.
|
|
cookie_jar[:remember_token] = user.remember_token
|
|
end
|
|
|
|
|
|
def sign_in_poltergeist(user)
|
|
visit signin_path
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
if Capybara.javascript_driver == :poltergeist
|
|
page.driver.set_cookie(:remember_token, user.remember_token)
|
|
else
|
|
page.driver.browser.manage.add_cookie :name => :remember_token, :value => user.remember_token
|
|
end
|
|
end
|
|
|
|
|
|
def wait_for_ajax(wait=Capybara.default_wait_time)
|
|
wait = wait * 10 #(because we sleep .1)
|
|
|
|
counter = 0
|
|
while page.execute_script("$.active").to_i > 0
|
|
counter += 1
|
|
sleep(0.1)
|
|
raise "AJAX request took longer than #{wait} seconds." if counter >= wait
|
|
end
|
|
end
|
|
|
|
# waits until the user object has been requested, which comes after the 'curtain' is lifted
|
|
# and after a call to /api/user/:id for the current user is called initially
|
|
def wait_until_user(wait=Capybara.default_wait_time)
|
|
wait = wait * 10 #(because we sleep .1)
|
|
|
|
counter = 0
|
|
# while page.execute_script("$('.curtain').is(:visible)") == "true"
|
|
# counter += 1
|
|
# sleep(0.1)
|
|
# raise "Waiting for user to populate took longer than #{wait} seconds." if counter >= wait
|
|
# end
|
|
end
|
|
|
|
def wait_until_curtain_gone
|
|
should have_no_selector('.curtain')
|
|
end |