How to enable page caching in a functional test in rails?
Asked Answered
L

2

2

Is it possible to turn on page caching for a functional test? The following didn't work:

class ArticlesControllerTest < ActionController::TestCase
 def setup
    ActionController::Base.public_class_method :page_cache_path
    ActionController::Base.perform_caching = true
 end
end

thanks in advance

Deb

Leupold answered 4/5, 2010 at 13:31 Comment(0)
L
0

I couldn't figure out why this was not working, so I ended up enabling caching directly on environments/test.rb:

config.action_controller.perform_caching             = true
Leupold answered 18/5, 2010 at 17:5 Comment(1)
I'm trying this in Rails 3.1.8 and it doesn't seem to work. The page is regenerated on every request.Intellect
Z
3

My current workaround is to enable perform_caching then reload the controller:

class ProjectsCachingTest < ActionController::IntegrationTest
  def setup
    # force the controller to be reloaded when caching is enabled
    ActionController::Base.perform_caching = true
    load "projects_controller.rb"
  end

  def teardown
    # undo the actions above
    ActionController::Base.perform_caching = false
    load "projects_controller.rb"
  end
end

In the latest version of Rails 2, the issue you are experiencing has to do with the class methods caches_action and caches_page. They both create an around filter to do the caching, but only when perform_caching is enabled.

So, modifying perform_caching at runtime does not recreate the expected around filters. The example above is one way to force your controller to be re-evaluated.

Zeus answered 8/12, 2010 at 22:32 Comment(0)
L
0

I couldn't figure out why this was not working, so I ended up enabling caching directly on environments/test.rb:

config.action_controller.perform_caching             = true
Leupold answered 18/5, 2010 at 17:5 Comment(1)
I'm trying this in Rails 3.1.8 and it doesn't seem to work. The page is regenerated on every request.Intellect

© 2022 - 2024 — McMap. All rights reserved.