blob: 025534a900d13c47c55195937aaf6eb2a6cefd36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
module LoginHelpers
# Internal: Create and log in as a user of the specified role
#
# role - User role (e.g., :admin, :user)
def login_as(role)
ActiveRecord::Base.observers.enable(:user_observer) do
@user = create(role)
end
login_with(@user)
end
# Internal: Login as the specified user
#
# user - User instance to login with
def login_with(user)
visit new_user_session_path
fill_in "user_login", with: user.email
fill_in "user_password", with: "123456"
click_button "Sign in"
Thread.current[:current_user] = user
end
def logout
click_link "Logout" rescue nil
end
end
|