开发者

Why am I seeing test environment data in my development Rails cache?

开发者 https://www.devze.com 2023-03-17 18:43 出处:网络
I am attempting to cache a class variable like so: Rails.cache.write(\"@@page_types\", @@page_types) This method is called within a class I have called PageTypes.

I am attempting to cache a class variable like so:

Rails.cache.write("@@page_types", @@page_types)

This method is called within a class I have called PageTypes.

If I start up a rails console and do:

Rails.cache.write("@@page_types", nil)
Rails.cache.read("@@page_types")

I get nil. I leave the console open and do this in another window:

rake test:units

When the tests are over, I switch back to my rails console window and do

Rails.cache.read("@@page_types")

It returns an array of my t开发者_Python百科est page types! I'm positive they are from my test db because the models all have super high IDs, while my dev data all has very low ones.

I suppose I could append Rails.env to the cache keys, but it seems like the two caches shouldn't be mixing....


Define a different cache backend for your test environment. A memory_store should be perfect for unit tests.

ActionController::Base.cache_store = :memory_store

in config/environments/test.rb:

config.cache_store = :memory_store
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号