class MemCacheStoreTest
You need to start a memcached server inorder to run these tests
Constants
- MEMCACHE_UP
Public Instance Methods
setup()
click to toggle source
# File activesupport/test/cache/stores/mem_cache_store_test.rb, line 19 def setup skip "memcache server is not up" unless MEMCACHE_UP @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, expires_in: 60) @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store) @data = @cache.instance_variable_get(:@data) @cache.clear @cache.silence! @cache.logger = ActiveSupport::Logger.new(File::NULL) end
test_deserializes_unloaded_class()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 138 def test_deserializes_unloaded_class with_test_route_set do with_autoload_path "session_autoload_test" do get "/set_serialized_session_value" assert_response :success assert cookies["_session_id"] end with_autoload_path "session_autoload_test" do get "/get_session_id" assert_response :success end end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_getting_from_nonexistent_session()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 89 def test_getting_from_nonexistent_session with_test_route_set do get "/get_session_value" assert_response :success assert_equal "foo: nil", response.body assert_nil cookies["_session_id"], "should only create session on write, not read" end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_getting_nil_session_value()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 58 def test_getting_nil_session_value with_test_route_set do get "/get_session_value" assert_response :success assert_equal "foo: nil", response.body end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_getting_session_id()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 123 def test_getting_session_id with_test_route_set do get "/set_session_value" assert_response :success assert cookies["_session_id"] session_id = cookies["_session_id"] get "/get_session_id" assert_response :success assert_equal session_id, response.body, "should be able to read session id without accessing the session hash" end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_getting_session_value_after_session_reset()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 68 def test_getting_session_value_after_session_reset with_test_route_set do get "/set_session_value" assert_response :success assert cookies["_session_id"] session_cookie = cookies.send(:hash_for)["_session_id"] get "/call_reset_session" assert_response :success assert_not_equal [], headers["Set-Cookie"] cookies << session_cookie # replace our new session_id with our old, pre-reset session_id get "/get_session_value" assert_response :success assert_equal "foo: nil", response.body, "data for this session should have been obliterated from memcached" end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_local_cache_raw_values()
click to toggle source
# File activesupport/test/cache/stores/mem_cache_store_test.rb, line 51 def test_local_cache_raw_values cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.with_local_cache do cache.write("foo", 2) assert_equal "2", cache.read("foo") end end
test_local_cache_raw_values_with_marshal()
click to toggle source
# File activesupport/test/cache/stores/mem_cache_store_test.rb, line 60 def test_local_cache_raw_values_with_marshal cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.with_local_cache do cache.write("foo", Marshal.dump([])) assert_equal [], cache.read("foo") end end
test_prevents_session_fixation()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 168 def test_prevents_session_fixation with_test_route_set do get "/get_session_value" assert_response :success assert_equal "foo: nil", response.body session_id = cookies["_session_id"] reset! get "/set_session_value", params: { _session_id: session_id } assert_response :success assert_not_equal session_id, cookies["_session_id"] end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_raw_values()
click to toggle source
# File activesupport/test/cache/stores/mem_cache_store_test.rb, line 37 def test_raw_values cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.write("foo", 2) assert_equal "2", cache.read("foo") end
test_raw_values_with_marshal()
click to toggle source
# File activesupport/test/cache/stores/mem_cache_store_test.rb, line 44 def test_raw_values_with_marshal cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.write("foo", Marshal.dump([])) assert_equal [], cache.read("foo") end
test_read_should_return_a_different_object_id_each_time_it_is_called()
click to toggle source
# File activesupport/test/cache/stores/mem_cache_store_test.rb, line 69 def test_read_should_return_a_different_object_id_each_time_it_is_called @cache.write("foo", "bar") value = @cache.read("foo") assert_not_equal value.object_id, @cache.read("foo").object_id value << "bingo" assert_not_equal value, @cache.read("foo") end
test_setting_and_getting_session_value()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 44 def test_setting_and_getting_session_value with_test_route_set do get "/set_session_value" assert_response :success assert cookies["_session_id"] get "/get_session_value" assert_response :success assert_equal 'foo: "bar"', response.body end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
test_setting_session_value_after_session_reset()
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 100 def test_setting_session_value_after_session_reset with_test_route_set do get "/set_session_value" assert_response :success assert cookies["_session_id"] session_id = cookies["_session_id"] get "/call_reset_session" assert_response :success assert_not_equal [], headers["Set-Cookie"] get "/get_session_value" assert_response :success assert_equal "foo: nil", response.body get "/get_session_id" assert_response :success assert_not_equal session_id, response.body end rescue Dalli::RingError => ex skip ex.message, ex.backtrace end
Private Instance Methods
with_test_route_set() { || ... }
click to toggle source
# File actionpack/test/dispatch/session/mem_cache_store_test.rb, line 189 def with_test_route_set with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do get ":action", to: ::MemCacheStoreTest::TestController end end @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::MemCacheStore, key: "_session_id", namespace: "mem_cache_store_test:#{SecureRandom.hex(10)}" middleware.delete ActionDispatch::ShowExceptions end yield end end