2014-03-16 15:03:33 +00:00
|
|
|
module Asciinema
|
|
|
|
module Test
|
|
|
|
module Authentication
|
|
|
|
attr_accessor :current_user
|
2015-04-04 17:46:55 +00:00
|
|
|
|
|
|
|
def ensure_authenticated!
|
|
|
|
unauthenticated_user unless current_user
|
|
|
|
end
|
2014-03-16 15:03:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module ControllerHelpers
|
|
|
|
def login_as(user)
|
|
|
|
controller.current_user = user
|
|
|
|
end
|
2014-03-16 17:34:37 +00:00
|
|
|
|
|
|
|
def logout
|
|
|
|
controller.current_user = nil
|
|
|
|
end
|
2014-03-16 15:03:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module FeatureHelpers
|
|
|
|
def login_as(user)
|
2015-04-04 17:39:21 +00:00
|
|
|
visit new_login_path
|
|
|
|
fill_in :email, with: user.email
|
|
|
|
click_button 'Log in'
|
|
|
|
visit "/login/#{user.expiring_tokens.last.token}"
|
2017-02-21 09:10:37 +00:00
|
|
|
click_button "Log in"
|
2014-03-16 15:03:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.before(:each, type: :controller) do
|
|
|
|
controller.class_eval { include Asciinema::Test::Authentication }
|
|
|
|
end
|
|
|
|
|
|
|
|
config.include Asciinema::Test::ControllerHelpers, type: :controller
|
|
|
|
config.include Asciinema::Test::FeatureHelpers, type: :feature
|
|
|
|
end
|