aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/cache/behaviors/autoloading_cache_behavior.rb
blob: b340eb6c489f1b0f3342a6773a10a1a3cba2d9a0 (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
# frozen_string_literal: true

require "dependencies_test_helpers"

module AutoloadingCacheBehavior
  include DependenciesTestHelpers

  def test_simple_autoloading
    with_autoloading_fixtures do
      @cache.write("foo", EM.new)
    end

    remove_constants(:EM)
    ActiveSupport::Dependencies.clear

    with_autoloading_fixtures do
      assert_kind_of EM, @cache.read("foo")
    end

    remove_constants(:EM)
    ActiveSupport::Dependencies.clear
  end

  def test_two_classes_autoloading
    with_autoloading_fixtures do
      @cache.write("foo", [EM.new, ClassFolder.new])
    end

    remove_constants(:EM, :ClassFolder)
    ActiveSupport::Dependencies.clear

    with_autoloading_fixtures do
      loaded = @cache.read("foo")
      assert_kind_of Array, loaded
      assert_equal 2, loaded.size
      assert_kind_of EM, loaded[0]
      assert_kind_of ClassFolder, loaded[1]
    end

    remove_constants(:EM, :ClassFolder)
    ActiveSupport::Dependencies.clear
  end
end