aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/abstract/details_cache_test.rb
blob: ee746c1bb081068450f085c7bbfc7a1e5bce22aa (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'abstract_unit'

module AbstractController
  module Testing
  
    class CachedController < AbstractController::Base
      include AbstractController::Rendering
      include AbstractController::DetailsCache

      self.view_paths = [ActionView::FixtureResolver.new(
        "default.erb" => "With Default",
        "template.erb" => "With Template",
        "some/file.erb" => "With File",
        "template_name.erb" => "With Template Name"
      )]
    end

    class TestLocalizedCache < ActiveSupport::TestCase

      def setup
        @controller = CachedController.new
        CachedController.clear_template_caches!
      end

      def test_templates_are_cached
        @controller.render :template => "default.erb"
        assert_equal "With Default", @controller.response_body

        cached = @controller.class.template_cache
        assert_equal 1, cached.size
        assert_kind_of ActionView::Template, cached.values.first["default.erb"]
      end

      def test_cache_is_used
        CachedController.new.render :template => "default.erb"

        @controller.expects(:find_template).never
        @controller.render :template => "default.erb"

        assert_equal 1, @controller.class.template_cache.size
      end

      def test_cache_changes_with_locale
        CachedController.new.render :template => "default.erb"

        I18n.locale = :es
        @controller.render :template => "default.erb"

        assert_equal 2, @controller.class.template_cache.size
      ensure
        I18n.locale = :en
      end

    end

  end
end