Skip to content

Commit 307feaa

Browse files
committed
Merge branch 'main' into v4
2 parents 5ee6a1d + 1b3052f commit 307feaa

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

lib/view_component/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToM
267267
raise e, <<~MESSAGE.chomp if view_context && e.is_a?(NameError) && helpers.respond_to?(method_name)
268268
#{e.message}
269269
270-
You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}'?
270+
You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}`?
271271
MESSAGE
272272

273273
raise

test/sandbox/config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Application < Rails::Application
4242
# Prepare test_set_no_duplicate_autoload_paths
4343
config.autoload_paths.push("#{config.root}/my/components/previews")
4444
config.view_component.preview_paths << "#{config.root}/my/components/previews"
45+
config.view_component.preview_paths << "#{Rails.root}/lib/component_previews"
4546
end
4647
end
4748

test/sandbox/config/environments/test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
config.view_component.show_previews = true
3232
config.view_component.instrumentation_enabled = true
33-
config.view_component.preview_paths << "#{Rails.root}/lib/component_previews"
3433
config.view_component.test_controller = "IntegrationExamplesController"
3534

3635
# Tell Action Mailer not to deliver emails to the real world.

test/sandbox/test/base_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_no_method_error_does_not_reference_helper_if_view_context_not_present
121121
exception_message_regex = Regexp.new <<~MESSAGE.chomp, Regexp::MULTILINE
122122
undefined method `current_user' for .*
123123
124-
You may be trying to call a method provided as a view helper. Did you mean `helpers.current_user'?
124+
You may be trying to call a method provided as a view helper. Did you mean `helpers.current_user`?
125125
MESSAGE
126126
assert !exception_message_regex.match?(exception.message)
127127
end
@@ -134,15 +134,15 @@ def current_user
134134
end
135135
}
136136
exception = assert_raises(NameError) { ReferencesMethodOnHelpersComponent.new.render_in(view_context) }
137-
exception_advice = "You may be trying to call a method provided as a view helper. Did you mean `helpers.current_user'?"
137+
exception_advice = "You may be trying to call a method provided as a view helper. Did you mean `helpers.current_user`?"
138138
assert exception.message.include?(exception_advice)
139139
end
140140

141141
def test_no_method_error_does_not_reference_missing_helper
142142
view_context = ActionController::Base.new.view_context
143143
exception = assert_raises(NameError) { ReferencesMethodOnHelpersComponent.new.render_in(view_context) }
144144
exception_message_regex = Regexp.new <<~MESSAGE.chomp
145-
You may be trying to call a method provided as a view helper\\. Did you mean `helpers.current_user'\\?$
145+
You may be trying to call a method provided as a view helper\\. Did you mean `helpers.current_user`\\?$
146146
MESSAGE
147147
assert !exception_message_regex.match?(exception.message)
148148
end

test/sandbox/test/components/render_preview_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ def test_render_preview_unsuffixed
2424

2525
assert_selector("div", text: "subclass")
2626
end
27+
28+
def test_render_preview_custom_path
29+
render_preview(:default, from: MyComponentLibPreview)
30+
31+
assert_selector("div", text: "hello,world!")
32+
end
2733
end

test/sandbox/test/integration_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,4 +723,10 @@ def test_slotable_default_override
723723

724724
assert_includes response.body, "foo"
725725
end
726+
727+
def test_renders_preview_from_custom_preview_path
728+
get "/rails/view_components/my_component_lib/default"
729+
730+
assert_select "div", "hello,world!"
731+
end
726732
end

0 commit comments

Comments
 (0)