forked from scambra/devise_invitable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_tests_helper.rb
48 lines (41 loc) · 1.28 KB
/
integration_tests_helper.rb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class ActionDispatch::IntegrationTest
def warden
request.env['warden']
end
def create_full_user
@user ||= begin
user = User.create!(
:username => 'usertest',
:email => '[email protected]',
:password => '123456',
:password_confirmation => '123456',
:created_at => Time.now.utc
)
user.confirm
user
end
end
def sign_in_as_user(user = nil)
user ||= create_full_user
resource_name = user.class.name.underscore
visit send("new_#{resource_name}_session_path")
fill_in "#{resource_name}_email", :with => user.email
fill_in "#{resource_name}_password", :with => user.password
click_button 'Log in'
end
# Fix assert_redirect_to in integration sessions because they don't take into
# account Middleware redirects.
#
def assert_redirected_to(url)
assert [301, 302].include?(@integration_session.status),
"Expected status to be 301 or 302, got #{@integration_session.status}"
url = prepend_host(url)
location = prepend_host(@integration_session.headers["Location"])
assert_equal url, location
end
protected
def prepend_host(url)
url = "http://#{request.host}#{url}" if url[0] == ?/
url
end
end