|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require "test_helper"
|
| 4 | +require "view_component/configurable" |
4 | 5 |
|
5 | 6 | class ViewComponent::Base::UnitTest < Minitest::Test
|
6 | 7 | def test_identifier
|
@@ -154,4 +155,54 @@ def test_component_local_config_is_inheritable
|
154 | 155 | # This component overrides the defaults.
|
155 | 156 | assert_equal true, ConfigurableComponent.configuration.strip_trailing_whitespace
|
156 | 157 | end
|
| 158 | + |
| 159 | + module TestModuleWithoutConfig |
| 160 | + class SomeComponent < ViewComponent::Base |
| 161 | + end |
| 162 | + end |
| 163 | + |
| 164 | + # Config defined on top-level module as opposed to engine. |
| 165 | + module TestModuleWithConfig |
| 166 | + include ViewComponent::Configurable |
| 167 | + |
| 168 | + configure do |config| |
| 169 | + config.view_component.test_controller = "AnotherController" |
| 170 | + end |
| 171 | + |
| 172 | + class SomeComponent < ViewComponent::Base |
| 173 | + end |
| 174 | + end |
| 175 | + |
| 176 | + module TestAlreadyConfigurableModule |
| 177 | + include ActiveSupport::Configurable |
| 178 | + include ViewComponent::Configurable |
| 179 | + |
| 180 | + configure do |config| |
| 181 | + config.view_component.test_controller = "AnotherController" |
| 182 | + end |
| 183 | + |
| 184 | + class SomeComponent < ViewComponent::Base |
| 185 | + end |
| 186 | + end |
| 187 | + |
| 188 | + module TestAlreadyConfiguredModule |
| 189 | + include ActiveSupport::Configurable |
| 190 | + |
| 191 | + configure do |config| |
| 192 | + config.view_component = ActiveSupport::InheritableOptions[test_controller: "AnotherController"] |
| 193 | + end |
| 194 | + |
| 195 | + include ViewComponent::Configurable |
| 196 | + |
| 197 | + class SomeComponent < ViewComponent::Base |
| 198 | + end |
| 199 | + end |
| 200 | + |
| 201 | + def test_uses_module_configuration |
| 202 | + # We override this ourselves in test/sandbox/config/environments/test.rb. |
| 203 | + assert_equal "IntegrationExamplesController", TestModuleWithoutConfig::SomeComponent.test_controller |
| 204 | + assert_equal "AnotherController", TestModuleWithConfig::SomeComponent.test_controller |
| 205 | + assert_equal "AnotherController", TestAlreadyConfigurableModule::SomeComponent.test_controller |
| 206 | + assert_equal "AnotherController", TestAlreadyConfiguredModule::SomeComponent.test_controller |
| 207 | + end |
157 | 208 | end
|
0 commit comments