Sha256: d1c3b62eb1d8beebd3c15d47d11664607c49fd1859fa8e68cfa9508db4281440
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
module Challah # Used to persist session data in test mode instead of using cookies. Stores the session # data lazily in a global var, accessible across the testing environment. class TestSessionStore def initialize(session = nil) @session = session end def destroy $challah_test_session = nil end def read if $challah_test_session return $challah_test_session.to_s.split(":") end nil end def save(token, user_id) $challah_test_session = "#{ token }:#{ user_id }" true end end module Testing # Sign the given user instance in def signin_as(user) Session.create!(user, nil, nil, user.class) end alias_method :login_as, :signin_as # Sign the given user instance out def signout Session.destroy end alias_method :logout, :signout end end class ActiveSupport::TestCase include Challah::Testing setup :signout end if defined?(RSpec) RSpec.configure do |config| config.before(:all) do # make sure challah is using test session in test mode Challah.options[:storage_class] = Challah::TestSessionStore end config.before(:each) do # Reset any challah user sessions for each test. $challah_test_session = nil end config.include Challah::Testing, type: :controller end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
challah-1.2.0 | lib/challah/test.rb |
challah-1.2.0.rc | lib/challah/test.rb |