Class: Challah::TestSessionStore

Inherits:
Object
  • Object
show all
Defined in:
lib/challah/test.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(session = nil) ⇒ TestSessionStore

Returns a new instance of TestSessionStore.



5
6
7
# File 'lib/challah/test.rb', line 5

def initialize(session = nil)
  @session = session
end

Instance Method Details

#destroyObject



9
10
11
# File 'lib/challah/test.rb', line 9

def destroy
  $challah_test_session = nil
end

#readObject



13
14
15
16
17
18
19
# File 'lib/challah/test.rb', line 13

def read
  if $challah_test_session
    return $challah_test_session.to_s.split("@")
  end

  nil
end

#save(token, user_id) ⇒ Object



21
22
23
24
# File 'lib/challah/test.rb', line 21

def save(token, user_id)
  $challah_test_session = "#{ token }@#{ user_id }"
  true
end