-
Notifications
You must be signed in to change notification settings - Fork 54
Support multiple css paths #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
michael-misshore
merged 5 commits into
mudbugmedia:master
from
randallreedjr:multiple-css-paths
Dec 28, 2018
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c58d70
Support multiple css paths
randallreedjr 667f242
Add note to readme about puppeteer
randallreedjr 0682adf
Add page h1 tag to more clearly identify test page
randallreedjr 90f7fa4
Add to Usage section of README
randallreedjr 077a68b
Merge branch 'master' into multiple-css-paths
michael-misshore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| module CriticalPathCSS | ||
| module Rails | ||
| VERSION = '2.6.0'.freeze | ||
| VERSION = '2.7.0'.freeze | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| <h1>Critical Path CSS Rails Test App</h1> | ||
| <p><%= CriticalPathCss.fetch(request.path) %></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe 'CssFetcher' do | ||
| describe '#fetch' do | ||
| let(:subject) { CriticalPathCss::CssFetcher.new(config) } | ||
| let(:response) { | ||
| ['foo','', OpenStruct.new(exitstatus: 0)] | ||
| } | ||
| let(:routes) { ['/', '/new_route'] } | ||
| let(:config) do | ||
| OpenStruct.new( | ||
| base_url: 'http://0.0.0.0:9292', | ||
| css_path: css_path, | ||
| css_paths: css_paths, | ||
| penthouse_options: {}, | ||
| routes: routes | ||
| ) | ||
| end | ||
|
|
||
| context 'when a single css_path is configured' do | ||
| let(:css_path) { '/test.css' } | ||
| let(:css_paths) { [] } | ||
|
|
||
| it 'generates css for each route from the same file' do | ||
| expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| | ||
| options = JSON.parse(arg3) | ||
| expect(options['css']).to eq '/test.css' | ||
| end.twice.and_return(response) | ||
| subject.fetch | ||
| end | ||
| end | ||
|
|
||
| context 'when multiple css_paths are configured' do | ||
| let(:css_path) { '' } | ||
| let(:css_paths) { ['/test.css', '/test2.css'] } | ||
|
|
||
| it 'generates css for each route from the respective file' do | ||
| expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| | ||
| options = JSON.parse(arg3) | ||
| expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/' | ||
| expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route' | ||
| end.twice.and_return(response) | ||
| subject.fetch | ||
| end | ||
| end | ||
|
|
||
| context 'when same css file applies to multiple routes' do | ||
| let(:css_path) { '' } | ||
| let(:css_paths) { ['/test.css', '/test2.css', '/test.css'] } | ||
| let(:routes) { ['/', '/new_route', '/newer_route'] } | ||
|
|
||
| it 'generates css for each route from the respective file' do | ||
| expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| | ||
| options = JSON.parse(arg3) | ||
| expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/' | ||
| expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route' | ||
| expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/newer_route' | ||
| end.thrice.and_return(response) | ||
| subject.fetch | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| require 'spec_helper' | ||
|
|
||
| RSpec.describe 'ConfigLoader' do | ||
| let(:subject) { CriticalPathCss::Rails::ConfigLoader.new } | ||
| describe '#load' do | ||
| before do | ||
| allow(File).to receive(:read).and_return(config_file) | ||
| end | ||
|
|
||
| context 'when single css_path is specified' do | ||
| let(:config_file) { | ||
| <<~CONFIG | ||
| defaults: &defaults | ||
| base_url: http://0.0.0.0:9292 | ||
| css_path: /test.css | ||
| routes: | ||
| - / | ||
|
|
||
| development: | ||
| <<: *defaults | ||
|
|
||
| test: | ||
| <<: *defaults | ||
| CONFIG | ||
| } | ||
|
|
||
| it 'sets css_path with the path' do | ||
| config = subject.load | ||
|
|
||
| expect(config['css_path']).to eq '/app/spec/internal/public/test.css' | ||
| end | ||
|
|
||
| it 'leaves css_paths empty' do | ||
| config = subject.load | ||
|
|
||
| expect(config['css_paths']).to eq [] | ||
| end | ||
| end | ||
|
|
||
| context 'when multiple css_paths are specified' do | ||
| let(:config_file) { | ||
| <<~CONFIG | ||
| defaults: &defaults | ||
| base_url: http://0.0.0.0:9292 | ||
| css_paths: | ||
| - /test.css | ||
| - /test2.css | ||
| routes: | ||
| - / | ||
| - /new_route | ||
|
|
||
| development: | ||
| <<: *defaults | ||
|
|
||
| test: | ||
| <<: *defaults | ||
| CONFIG | ||
| } | ||
|
|
||
| it 'sets css_path to empty string' do | ||
| config = subject.load | ||
|
|
||
| expect(config['css_path']).to eq '' | ||
| end | ||
|
|
||
| it 'leaves css_paths to an array of paths' do | ||
| config = subject.load | ||
|
|
||
| expect(config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css'] | ||
| end | ||
| end | ||
|
|
||
| context 'when single css_path and multiple css_paths are both specified' do | ||
| let(:config_file) { | ||
| <<~CONFIG | ||
| defaults: &defaults | ||
| base_url: http://0.0.0.0:9292 | ||
| css_path: /test.css | ||
| css_paths: | ||
| - /test.css | ||
| - /test2.css | ||
| routes: | ||
| - / | ||
| - /new_route | ||
|
|
||
| development: | ||
| <<: *defaults | ||
|
|
||
| test: | ||
| <<: *defaults | ||
| CONFIG | ||
| } | ||
|
|
||
| it 'raises an error' do | ||
| expect { subject.load }.to raise_error LoadError, 'Cannot specify both css_path and css_paths' | ||
| end | ||
| end | ||
|
|
||
| context 'when css_paths and routes are not the same length' do | ||
| let(:config_file) { | ||
| <<~CONFIG | ||
| defaults: &defaults | ||
| base_url: http://0.0.0.0:9292 | ||
| css_paths: | ||
| - /test.css | ||
| - /test2.css | ||
| routes: | ||
| - / | ||
| - /new_route | ||
| - /newer_route | ||
|
|
||
| development: | ||
| <<: *defaults | ||
|
|
||
| test: | ||
| <<: *defaults | ||
| CONFIG | ||
| } | ||
|
|
||
| it 'raises an error' do | ||
| expect { subject.load }.to raise_error LoadError, 'Must specify css_paths for each route' | ||
| end | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@randallreedjr, Is it possible to move this config into a fixture of sorts? I think it may help improve the readability and clean up this spec if we were able to write something like
let(:config_file) { File.open('/path/to/single_css_path_conf.yml') }or something along those lines. Not sure if a fixture is the right call or just moving the config into a file in aconfigdirectory. Likewise, the same can be done with the other similar config variables.Once this is address, I'll go ahead and merge this in and tag you with the merge request that has the refactors in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@randallreedjr Can you see my above message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-misshore Yep, will do!