|
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 |
@@ -145,4 +146,54 @@ def test_no_method_error_does_not_reference_missing_helper |
145 | 146 | MESSAGE |
146 | 147 | assert !exception_message_regex.match?(exception.message) |
147 | 148 | end |
| 149 | + |
| 150 | + module TestModuleWithoutConfig |
| 151 | + class SomeComponent < ViewComponent::Base |
| 152 | + end |
| 153 | + end |
| 154 | + |
| 155 | + # Config defined on top-level module as opposed to engine. |
| 156 | + module TestModuleWithConfig |
| 157 | + include ViewComponent::Configurable |
| 158 | + |
| 159 | + configure do |config| |
| 160 | + config.view_component.test_controller = "AnotherController" |
| 161 | + end |
| 162 | + |
| 163 | + class SomeComponent < ViewComponent::Base |
| 164 | + end |
| 165 | + end |
| 166 | + |
| 167 | + module TestAlreadyConfigurableModule |
| 168 | + include ActiveSupport::Configurable |
| 169 | + include ViewComponent::Configurable |
| 170 | + |
| 171 | + configure do |config| |
| 172 | + config.view_component.test_controller = "AnotherController" |
| 173 | + end |
| 174 | + |
| 175 | + class SomeComponent < ViewComponent::Base |
| 176 | + end |
| 177 | + end |
| 178 | + |
| 179 | + module TestAlreadyConfiguredModule |
| 180 | + include ActiveSupport::Configurable |
| 181 | + |
| 182 | + configure do |config| |
| 183 | + config.view_component = ActiveSupport::InheritableOptions[test_controller: "AnotherController"] |
| 184 | + end |
| 185 | + |
| 186 | + include ViewComponent::Configurable |
| 187 | + |
| 188 | + class SomeComponent < ViewComponent::Base |
| 189 | + end |
| 190 | + end |
| 191 | + |
| 192 | + def test_uses_module_configuration |
| 193 | + # We override this ourselves in test/sandbox/config/environments/test.rb. |
| 194 | + assert_equal "IntegrationExamplesController", TestModuleWithoutConfig::SomeComponent.test_controller |
| 195 | + assert_equal "AnotherController", TestModuleWithConfig::SomeComponent.test_controller |
| 196 | + assert_equal "AnotherController", TestAlreadyConfigurableModule::SomeComponent.test_controller |
| 197 | + assert_equal "AnotherController", TestAlreadyConfiguredModule::SomeComponent.test_controller |
| 198 | + end |
148 | 199 | end |
0 commit comments