Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module AuthHelpers
def authenticate_with(account)
Capybara.current_session.driver.headers = { 'Auth-Token' => account.authentication_token }
end
def authenticate_with_account(account)
@headers = {}
@headers['Auth-token'] = account.authentication_token
end
def authorized?(subject, action, object)
ability = Ability.new(subject).can?(action, object)
end
def device_sign_in(device)
params = {
'authenticationToken': device.account.authentication_token,
'accountableId': device.account.accountable_id,
'accountableType': 'Device'
}
visit devices_sign_in_path
page
.execute_script(
"localStorage
.setItem(
'currentSession',
JSON.stringify(
{authenticationToken:'#{params['authenticationToken']}',
accountableId:'#{params['accountableId']}',
accountableType:'Device'}
)
)
")
end
def user_sign_in
visit users_sign_in_path
fill_in 'email', with: 'nourish@gmail.com'
fill_in 'password', with: '123'
click_button('submit')
expect(page).to have_xpath('//a')
expect(current_url).to include(admin_users_path)
end
end
RSpec.configure { |config| config.include AuthHelpers }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.