class ActionDispatch::Request::SessionTest

Attributes

req[R]

Public Instance Methods

setup() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 11
def setup
  @req = ActionDispatch::Request.empty
end
test_clear() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 76
def test_clear
  s = Session.create(store, req, {})
  s["quails"] = "ftw"
  s["adequate"] = "awesome"

  s.clear
  assert_empty(s.values)
end
test_create_adds_itself_to_env() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 15
def test_create_adds_itself_to_env
  s = Session.create(store, req, {})
  assert_equal s, req.env[Rack::RACK_SESSION]
end
test_create_merges_old() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 27
def test_create_merges_old
  s = Session.create(store, req, {})
  s["foo"] = "bar"

  s1 = Session.create(store, req, {})
  assert_not_equal s, s1
  assert_equal "bar", s1["foo"]
end
test_delete() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 95
def test_delete
  s = Session.create(store, req, {})
  s["quails"] = "ftw"

  s.delete("quails")

  assert_empty(s.keys)
end
test_destroy() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 43
def test_destroy
  s = Session.create(store, req, {})
  s["quails"] = "ftw"

  s.destroy

  assert_empty s
end
test_fetch() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 104
def test_fetch
  session = Session.create(store, req, {})

  session["one"] = "1"
  assert_equal "1", session.fetch(:one)

  assert_equal "2", session.fetch(:two, "2")
  assert_nil session.fetch(:two, nil)

  assert_equal "three", session.fetch(:three) { |el| el.to_s }

  assert_raise KeyError do
    session.fetch(:three)
  end
end
test_find() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 36
def test_find
  assert_nil Session.find(req)

  s = Session.create(store, req, {})
  assert_equal s, Session.find(req)
end
test_keys() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 52
def test_keys
  s = Session.create(store, req, {})
  s["quails"] = "ftw"
  s["adequate"] = "awesome"
  assert_equal %w[quails adequate], s.keys
end
test_keys_with_deferred_loading() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 59
def test_keys_with_deferred_loading
  s = Session.create(store_with_data, req, {})
  assert_equal %w[sample_key], s.keys
end
test_to_hash() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 20
def test_to_hash
  s = Session.create(store, req, {})
  s["foo"] = "bar"
  assert_equal "bar", s["foo"]
  assert_equal({ "foo" => "bar" }, s.to_hash)
end
test_update() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 85
def test_update
  s = Session.create(store, req, {})
  s["quails"] = "ftw"

  s.update(quails: "awesome")

  assert_equal(["quails"], s.keys)
  assert_equal("awesome", s["quails"])
end
test_values() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 64
def test_values
  s = Session.create(store, req, {})
  s["quails"] = "ftw"
  s["adequate"] = "awesome"
  assert_equal %w[ftw awesome], s.values
end
test_values_with_deferred_loading() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 71
def test_values_with_deferred_loading
  s = Session.create(store_with_data, req, {})
  assert_equal %w[sample_value], s.values
end

Private Instance Methods

delete_session(env, id, options) click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 125
def delete_session(env, id, options); 123; end
load_session(env) click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 123
def load_session(env); [1, {}]; end
session_exists?(env) click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 124
def session_exists?(env); true; end
store() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 121
def store
  Class.new {
    def load_session(env); [1, {}]; end
    def session_exists?(env); true; end
    def delete_session(env, id, options); 123; end
  }.new
end
store_with_data() click to toggle source
# File actionpack/test/dispatch/request/session_test.rb, line 129
def store_with_data
  Class.new {
    def load_session(env); [1, { "sample_key" => "sample_value" }]; end
    def session_exists?(env); true; end
    def delete_session(env, id, options); 123; end
  }.new
end