Class: ActionController::TestSession

Inherits:
Rack::Session::Abstract::PersistedSecure::SecureSessionHash
  • Object
show all
Defined in:
actionpack/lib/action_controller/test_case.rb

Overview

Methods #destroy and #load! are overridden to avoid calling methods on the

Constant Summary collapse

DEFAULT_OPTIONS =

:nodoc:

Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS

Instance Method Summary collapse

Constructor Details

#initialize(session = {}, id = Rack::Session::SessionId.new(SecureRandom.hex(16))) ⇒ TestSession

Returns a new instance of TestSession.


185
186
187
188
189
190
191
# File 'actionpack/lib/action_controller/test_case.rb', line 185

def initialize(session = {}, id = Rack::Session::SessionId.new(SecureRandom.hex(16)))
  super(nil, nil)
  @id = id
  @data = stringify_keys(session)
  @loaded = true
  @initially_empty = @data.empty?
end

Instance Method Details

#destroyObject


205
206
207
# File 'actionpack/lib/action_controller/test_case.rb', line 205

def destroy
  clear
end

#dig(*keys) ⇒ Object


209
210
211
212
# File 'actionpack/lib/action_controller/test_case.rb', line 209

def dig(*keys)
  keys = keys.map.with_index { |key, i| i.zero? ? key.to_s : key }
  @data.dig(*keys)
end

#enabled?Boolean

Returns:

  • (Boolean)

218
219
220
# File 'actionpack/lib/action_controller/test_case.rb', line 218

def enabled?
  true
end

#exists?Boolean

Returns:

  • (Boolean)

193
194
195
# File 'actionpack/lib/action_controller/test_case.rb', line 193

def exists?
  true
end

#fetch(key, *args, &block) ⇒ Object


214
215
216
# File 'actionpack/lib/action_controller/test_case.rb', line 214

def fetch(key, *args, &block)
  @data.fetch(key.to_s, *args, &block)
end

#id_wasObject


222
223
224
# File 'actionpack/lib/action_controller/test_case.rb', line 222

def id_was
  @id
end

#keysObject


197
198
199
# File 'actionpack/lib/action_controller/test_case.rb', line 197

def keys
  @data.keys
end

#valuesObject


201
202
203
# File 'actionpack/lib/action_controller/test_case.rb', line 201

def values
  @data.values
end