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