aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/railties/plugin_ordering_test.rb
blob: f6ca493fdf905a3f5f3c203e630de4cba7015e23 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "isolation/abstract_unit"

module RailtiesTest
  class PluginOrderingTest < Test::Unit::TestCase
    include ActiveSupport::Testing::Isolation

    def setup
      build_app
      $arr = []
      plugin "a_plugin", "$arr << :a"
      plugin "b_plugin", "$arr << :b"
      plugin "c_plugin", "$arr << :c"
    end

    def boot_rails
      super
      require "#{app_path}/config/environment"
    end

    test "plugins are loaded alphabetically by default" do
      boot_rails
      assert_equal [:a, :b, :c], $arr
    end

    test "if specified, only those plugins are loaded" do
      add_to_config "config.plugins = [:b_plugin]"
      boot_rails
      assert_equal [:b], $arr
    end

    test "the plugins are initialized in the order they are specified" do
      add_to_config "config.plugins = [:b_plugin, :a_plugin]"
      boot_rails
      assert_equal [:b, :a], $arr
    end

    test "if :all is specified, the remaining plugins are loaded in alphabetical order" do
      add_to_config "config.plugins = [:c_plugin, :all]"
      boot_rails
      assert_equal [:c, :a, :b], $arr
    end

    test "if :all is at the beginning, it represents the plugins not otherwise specified" do
      add_to_config "config.plugins = [:all, :b_plugin]"
      boot_rails
      assert_equal [:a, :c, :b], $arr
    end

    test "plugin order array is strings" do
      add_to_config "config.plugins = %w( c_plugin all )"
      boot_rails
      assert_equal [:c, :a, :b], $arr
    end

    test "can require lib file from a different plugin" do
      plugin "foo", "require 'bar'" do |plugin|
        plugin.write "lib/foo.rb", "$foo = true"
      end

      plugin "bar", "require 'foo'" do |plugin|
        plugin.write "lib/bar.rb", "$bar = true"
      end

      add_to_config "config.plugins = [:foo, :bar]"

      boot_rails

      assert $foo
      assert $bar
    end
  end
end