Skip to content

Instantly share code, notes, and snippets.

@alex-ross
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-ross/35c0a30a9842611b8b49 to your computer and use it in GitHub Desktop.
Save alex-ross/35c0a30a9842611b8b49 to your computer and use it in GitHub Desktop.
Integration example that allows multiple sessions at same time
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