1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/test/support/integration.rb

77 lines
2 KiB
Ruby
Raw Normal View History

require 'action_dispatch/testing/integration'
class ActionDispatch::IntegrationTest
def warden
request.env['warden']
end
def create_user(options={})
@user ||= begin
user = User.create!(
2010-02-05 19:33:32 -05:00
:username => 'usertest',
:email => 'user@test.com',
:password => '123456',
:password_confirmation => '123456',
:created_at => Time.now.utc
)
user.confirm! unless options[:confirm] == false
user.lock_access! if options[:locked] == true
user
end
end
def create_admin(options={})
@admin ||= begin
admin = Admin.create!(
:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456'
)
admin
end
end
def sign_in_as_user(options={}, &block)
2009-10-19 22:31:33 -04:00
user = create_user(options)
get new_user_session_path unless options[:visit] == false
fill_in 'email', :with => 'user@test.com'
fill_in 'password', :with => '123456'
2009-10-19 22:31:33 -04:00
check 'remember me' if options[:remember_me] == true
yield if block_given?
click_button 'Sign In'
2009-10-19 22:31:33 -04:00
user
end
def sign_in_as_admin(options={}, &block)
2009-10-19 22:31:33 -04:00
admin = create_admin(options)
get new_admin_session_path unless options[:visit] == false
fill_in 'email', :with => 'admin@test.com'
fill_in 'password', :with => '123456'
yield if block_given?
click_button 'Sign In'
2009-10-19 22:31:33 -04:00
admin
end
2009-10-11 22:24:57 -04:00
def assert_current_path(path)
2010-02-19 03:52:04 -05:00
assert_equal(prepend_host(path), prepend_host(current_url))
end
2009-10-11 22:24:57 -04:00
# 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