Class: ActionController::TestSession

Inherits:
Rack::Session::Abstract::PersistedSecure::SecureSessionHash
  • Object
show all
Defined in:
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.



192
193
194
195
196
197
198
# File 'lib/action_controller/test_case.rb', line 192

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



212
213
214
# File 'lib/action_controller/test_case.rb', line 212

def destroy
  clear
end

#dig(*keys) ⇒ Object



216
217
218
219
# File 'lib/action_controller/test_case.rb', line 216

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

#enabled?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'lib/action_controller/test_case.rb', line 225

def enabled?
  true
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  true
end

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



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

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

#id_wasObject



229
230
231
# File 'lib/action_controller/test_case.rb', line 229

def id_was
  @id
end

#keysObject



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

def keys
  @data.keys
end

#valuesObject



208
209
210
# File 'lib/action_controller/test_case.rb', line 208

def values
  @data.values
end