|
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 |
@@ -149,27 +150,51 @@ def test_no_method_error_does_not_reference_missing_helper |
149 | 150 |
|
150 | 151 | module TestModuleWithoutConfig |
151 | 152 | class SomeComponent < ViewComponent::Base |
152 | | - |
153 | 153 | end |
154 | 154 | end |
155 | 155 |
|
156 | 156 | # Config defined on top-level module as opposed to engine. |
157 | 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 |
158 | 169 | include ActiveSupport::Configurable |
| 170 | + include ViewComponent::Configurable |
159 | 171 |
|
160 | 172 | configure do |config| |
161 | | - # To get this green. |
162 | | - config.view_component = ActiveSupport::InheritableOptions.new |
163 | 173 | config.view_component.test_controller = "AnotherController" |
164 | 174 | end |
165 | 175 |
|
166 | 176 | class SomeComponent < ViewComponent::Base |
167 | 177 | end |
168 | 178 | end |
169 | 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 | + |
170 | 193 | def test_uses_module_configuration |
171 | 194 | # We override this ourselves in test/sandbox/config/environments/test.rb. |
172 | 195 | assert_equal "IntegrationExamplesController", TestModuleWithoutConfig::SomeComponent.test_controller |
173 | 196 | assert_equal "AnotherController", TestModuleWithConfig::SomeComponent.test_controller |
| 197 | + assert_equal "AnotherController", TestAlreadyConfigurableModule::SomeComponent.test_controller |
| 198 | + assert_equal "AnotherController", TestAlreadyConfiguredModule::SomeComponent.test_controller |
174 | 199 | end |
175 | 200 | end |
0 commit comments