Skip to content

Commit 04f4125

Browse files
committed
Fix component path not being used outside of config
1 parent a6fd855 commit 04f4125

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

lib/view_component/scoped_styles/railtie.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class Railtie < Rails::Railtie
2222

2323
class << self
2424
def component_path
25-
Rails.root.join("app/components/**/*.rb")
25+
Rails.root.join(
26+
ViewComponent::ScopedStyles.configuration.components_path,
27+
"**",
28+
"*.rb"
29+
)
2630
end
2731

2832
def load_and_register_components
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe ViewComponent::ScopedStyles::Railtie do
4+
describe ".component_path" do
5+
let(:rails_root) { Pathname.new("/tmp/myapp") }
6+
7+
before do
8+
allow(Rails).to receive(:root).and_return(rails_root)
9+
end
10+
11+
after do
12+
ViewComponent::ScopedStyles.configuration.components_path =
13+
File.join("app", "components")
14+
end
15+
16+
it "uses the configured components_path" do
17+
ViewComponent::ScopedStyles.configuration.components_path =
18+
File.join("app", "view_components")
19+
20+
expect(described_class.component_path.to_s).to eq(
21+
"/tmp/myapp/app/view_components/**/*.rb"
22+
)
23+
end
24+
25+
it "defaults to app/components" do
26+
expect(described_class.component_path.to_s).to eq(
27+
"/tmp/myapp/app/components/**/*.rb"
28+
)
29+
end
30+
end
31+
end

spec/view_component/scoped_styles_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
end
77

88
describe "Configuration" do
9-
it "defaults assets_path and stylesheet_name" do
9+
it "defaults components_path, assets_path, and stylesheet_name" do
1010
config = ViewComponent::ScopedStyles::Configuration.new
1111

12+
expect(config.components_path).to eq(File.join("app", "components"))
1213
expect(config.assets_path).to eq(File.join("app", "assets", "stylesheets"))
1314
expect(config.stylesheet_name).to eq("components.scoped.css")
1415
end

0 commit comments

Comments
 (0)