aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/plugins/configuration_test.rb
blob: 0843d05577c7093e42f2bd1ce6381b1b557764b0 (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
require "isolation/abstract_unit"

module PluginsTest
  class ConfigurationTest < Test::Unit::TestCase
    def setup
      build_app
      boot_rails
      require "rails"
    end

    module Bar; end
    module Baz; end
    module All; end

    test "config is available to plugins" do
      class Foo < Rails::Plugin ; end
      assert_nil Foo.config.action_controller.foo
    end

    test "a config name is available for the plugin" do
      class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end
      assert_equal "hello", Foo.config.foo.greetings
    end

    test "plugin configurations are available in the application" do
      class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end
      require "#{app_path}/config/application"
      assert_equal "hello", AppTemplate::Application.config.foo.greetings
    end

    test "plugin configurations allow modules to be given" do
      class Foo < Rails::Plugin ; config.foo.include(Bar, Baz) ; end
      assert_equal [Bar, Baz], Foo.config.foo.includes
    end

    test "plugin includes given modules in given class" do
      class Foo < Rails::Plugin ; config.foo.include(Bar, "PluginsTest::ConfigurationTest::Baz") ; include_modules_in All ; end
      Foo.new.run_initializers(Foo)
      assert All.ancestors.include?(Bar)
      assert All.ancestors.include?(Baz)
    end

    test "plugin config merges are deep" do
      class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end
      class MyApp < Rails::Application
        config.foo.bar = "bar"
      end
      assert_equal "hello", MyApp.config.foo.greetings
      assert_equal "bar",   MyApp.config.foo.bar
    end
  end
end