caching_test.rb
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'abstract_unit'
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
FILE_STORE_PATH = File.expand_path('../../../temp/test_cache', __FILE__)
class CachingController < ActionController::Base
abstract!
self.cache_store = :file_store, FILE_STORE_PATH
end
class FunctionalCachingController < CachingController
def js_fragment_cached_with_partial
respond_to do |format|
format.js
end
end
def formatted_fragment_cached
respond_to do |format|
format.js
end
end
end
class FunctionalFragmentCachingTest < ActionController::TestCase
def setup
super
@store = ActiveSupport::Cache::MemoryStore.new
@controller = FunctionalCachingController.new
@controller.perform_caching = true
@controller.cache_store = @store
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_fragment_caching_in_rjs_partials
xhr :get, :js_fragment_cached_with_partial
assert_response :success
assert_match(/Old fragment caching in a partial/, @response.body)
assert_match "Old fragment caching in a partial", @store.instance_variable_get('@data').values.first.value
end
end