Last active
August 29, 2015 14:06
-
-
Save alex-ross/35c0a30a9842611b8b49 to your computer and use it in GitHub Desktop.
Integration example that allows multiple sessions at same time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test_helper" | |
class CompaniesTest < ActionDispatch::IntegrationTest | |
it "admin can signin and visit companies" do | |
admin = new_session_as :admin | |
admin.goes_to "/companies" | |
end | |
private | |
module CompaniesTestDSL | |
def goes_to(path) | |
get path | |
assert_response :success | |
end | |
def goes_to_signin | |
get "/signin" | |
assert_response :success | |
end | |
def signin_as(person) | |
@current_user = users(person) | |
post "/sessions", email: @current_user.email, password: "password" | |
assert_response :redirect | |
follow_redirect! | |
assert_template "welcome/index" | |
end | |
end | |
def new_session | |
open_session do |session| | |
session.extend(CompaniesTestDSL) | |
yield session if block_given? | |
end | |
end | |
def new_session_as(person) | |
new_session do |session| | |
session.goes_to_signin | |
session.signin_as person | |
yield session if block_given? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment