Skip to content

Commit bdcbc59

Browse files
Only reference css_paths config
1 parent 6f11de6 commit bdcbc59

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

lib/critical_path_css/configuration.rb

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ def base_url
99
@config['base_url']
1010
end
1111

12-
def css_path
13-
@config['css_path']
14-
end
15-
1612
def css_paths
1713
@config['css_paths']
1814
end

lib/critical_path_css/rails/config_loader.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ def configuration_file_path
1919
end
2020

2121
def format_css_paths
22-
if config['css_path']
23-
config['css_path'] = format_path(config['css_path'])
24-
config['css_paths'] = []
25-
elsif config['css_paths']
26-
config['css_path'] = ''
27-
config['css_paths'] = config['css_paths'].collect { |path| format_path(path) }
22+
config['css_paths'] = [config['css_path']] if config['css_path']
23+
24+
if config['css_paths']
25+
config['css_paths'].map! { |path| format_path(path) }
2826
else
29-
config['css_path'] = ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '')
30-
config['css_paths'] = []
27+
config['css_paths'] = [ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '')]
3128
end
3229
end
3330

spec/lib/critical_path_css/css_fetcher_spec.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
describe '#fetch_route' do
2020
context 'when a single css_path is configured' do
21-
let(:css_path) { '/test.css' }
22-
let(:css_paths) { [] }
21+
let(:css_paths) { ['/test.css'] }
2322

2423
it 'generates css for the single route' do
2524
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
@@ -35,8 +34,7 @@
3534

3635
describe '#fetch' do
3736
context 'when a single css_path is configured' do
38-
let(:css_path) { '/test.css' }
39-
let(:css_paths) { [] }
37+
let(:css_paths) { ['/test.css'] }
4038

4139
it 'generates css for each route from the same file' do
4240
expect(Open3).to receive(:capture3) do |arg1, arg2, arg3|
@@ -50,7 +48,6 @@
5048
end
5149

5250
context 'when multiple css_paths are configured' do
53-
let(:css_path) { '' }
5451
let(:css_paths) { ['/test.css', '/test2.css'] }
5552

5653
it 'generates css for each route from the respective file' do
@@ -67,7 +64,6 @@
6764
end
6865

6966
context 'when same css file applies to multiple routes' do
70-
let(:css_path) { '' }
7167
let(:css_paths) { ['/test.css', '/test2.css', '/test.css'] }
7268
let(:routes) { ['/', '/new_route', '/newer_route'] }
7369

spec/lib/critical_path_css/rails/config_loader_spec.rb

+4-16
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@
1111
context 'when single css_path is specified' do
1212
let(:config_file) { file_fixture('config/single-css-path.yml').read }
1313

14-
it 'sets css_path with the path' do
15-
expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css'
16-
end
17-
18-
it 'leaves css_paths empty' do
19-
expect(subject.config['css_paths']).to eq []
14+
it 'sets css_paths with the lone path' do
15+
expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css']
2016
end
2117
end
2218

2319
context 'when multiple css_paths are specified' do
2420
let(:config_file) { file_fixture('config/mutliple-css-paths.yml').read }
2521

26-
it 'sets css_path to empty string' do
27-
expect(subject.config['css_path']).to eq ''
28-
end
29-
3022
it 'leaves css_paths to an array of paths' do
3123
expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css']
3224
end
@@ -35,12 +27,8 @@
3527
context 'when no paths are specified' do
3628
let(:config_file) { file_fixture('config/no-paths-specified.yml').read }
3729

38-
it 'sets css_path with the path' do
39-
expect(subject.config['css_path']).to eq '/stylesheets/application.css'
40-
end
41-
42-
it 'leaves css_paths empty' do
43-
expect(subject.config['css_paths']).to eq []
30+
it 'sets css_paths with the lone manifest path' do
31+
expect(subject.config['css_paths']).to eq ['/stylesheets/application.css']
4432
end
4533
end
4634

0 commit comments

Comments
 (0)