1

Am trying to use Rails.cache.read and Rails.cache.write helpers during my rspec scenario but it doesn't work. Am using dalli_store for cache store. I wrote

ActionController::Base.perform_caching = true 

in any random test scenario and then run only this rspec. And when I jump to the next line to the breakpoint and try to write in console

Rails.cache.write("f", "b") => true
Rails.cache.read("f") => nil 

When I do the same thing in console running in dev env - I've got all expected results. It stores the values in cache and returns it

mr.freeman13
  • 93
  • 1
  • 4

1 Answers1

0

Is Dalli configured

config.cache_store = :dalli_store

in your config/environments/test.rb environment? I believe it defaults to :null_store, which means your test environment will not have caching enabled. Also, be sure to return ActionController::Base.perform_caching back to its original state after your spec runs.

Benjamin Manns
  • 9,028
  • 4
  • 37
  • 48
  • config.cache_store is sets to :dalli_store value. But it doesn't help. Am thinking maybe just Rails.cache.* helpers are doesn't work. Cause if I try to initialize dalli staff like this: CACHE = Dalli::Client.new(’127.0.0.1′, { :namespace => “my_project”, :expires_in => 3600, :socket_timeout => 3, :compress => true }) - I can set and get data via: CACHE.set and CACHE.get. – mr.freeman13 Oct 20 '15 at 23:35
  • Is `config.cache_store` set specifically in the config/environments/ **test.rb** file? – Benjamin Manns Oct 20 '15 at 23:38
  • yes. I have 2 options for caching in test.rb file. config.action_controller.perform_caching = true config.cache_store = :dalli_store – mr.freeman13 Oct 21 '15 at 00:10