-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Add shakapacker.yml as the secondary source for asset_host and relative_url_root #376
Changes from 10 commits
30f70c9
5f45082
f4329de
7b83800
7e00d32
4a363ef
4b32eaa
3dcebb0
7374cb5
dd6484e
663f294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,11 +117,19 @@ def fetch(key) | |
end | ||
|
||
def asset_host | ||
ENV.fetch("SHAKAPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host) | ||
ENV.fetch( | ||
"SHAKAPACKER_ASSET_HOST", | ||
fetch(:asset_host) || ActionController::Base.helpers.compute_asset_host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 but no change? why? |
||
).to_s | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only concern with this PR is that I ensure the retuned value is a string in any case. This means if nothing is provided, we get That time, I thought it could help with simplification so that could only check I just wanted to raise this again to ensure it is not missed out in the reviews. |
||
|
||
def relative_url_root | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a public API? Do we need docs explaining this change? What is the migration if somebody used this ENV: Is this OK as a feature level bump? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for not making it enough clear. I added more explanation in the commit message but it is not enough visible. So let's quote it here:
and from my private discussion with Judah, he phrased it this way:
So, we just inherited this extra unused configuration from Webpacker. I am not sure if we should keep carrying this code by deprecating it till the next major release. Mentioning this removal in the changelog wouldn't be bad (if needed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I'm not quite following, but I think if We'll want to do a v8 for switching to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is also fine to me. @justin808 I reverted the last commit (of removing If agreed, and there is no other required changes, we are good to go with merge and 7.2 release. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I agree with you. I don't see any good reason for introducing a new public interface to So I will narrow down this PR to only cover There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the actual moving of the logic into the configuration was done in #374. This PR was to add some fixes and improve tests. The PR title is misleading. So I think now that all usages of |
||
ENV.fetch("SHAKAPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root) | ||
Shakapacker.puts_deprecation_message "The usage of relative_url_root is deprecated in Shakapacker and will be removed in v8." | ||
|
||
ENV.fetch( | ||
"SHAKAPACKER_RELATIVE_URL_ROOT", | ||
fetch(:relative_url_root) || ActionController::Base.relative_url_root | ||
).to_s | ||
end | ||
|
||
private | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,11 +346,31 @@ | |
expect(config.asset_host).to eq "custom_host.abc" | ||
end | ||
|
||
it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_ASSET_HOST is not set" do | ||
allow(ActionController::Base.helpers).to receive(:compute_asset_host).and_return("domain.abc") | ||
allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "domain.abc").and_return("domain.abc") | ||
context "without SHAKAPACKER_ASSET_HOST set" do | ||
it "returns asset_host in shakapacker.yml if set" do | ||
expect(config).to receive(:fetch).with(:asset_host).and_return("value-in-config-file.com") | ||
expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "value-in-config-file.com").and_return("value-in-config-file.com") | ||
|
||
expect(config.asset_host).to eq "domain.abc" | ||
expect(config.asset_host).to eq "value-in-config-file.com" | ||
end | ||
|
||
context "without asset_host set in the shakapacker.yml" do | ||
it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_ASSET_HOST is not set" do | ||
expect(config).to receive(:fetch).with(:asset_host).and_return(nil) | ||
expect(ActionController::Base.helpers).to receive(:compute_asset_host).and_return("domain.abc") | ||
allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "domain.abc").and_return("domain.abc") | ||
|
||
expect(config.asset_host).to eq "domain.abc" | ||
end | ||
|
||
context "without ActionController::Base.helpers.compute_asset_host returing any value" do | ||
it "returns an empty string" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why empty strings and not nil? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was the logic when I was implementing these changes: while calculating digest for the watched assets, I noticed that we may get Now I think it is better to return |
||
expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return(nil) | ||
|
||
expect(config.asset_host).to eq "" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
@@ -363,17 +383,40 @@ | |
) | ||
end | ||
|
||
it "shows deprecation message" do | ||
expect { config.relative_url_root }.to output(/deprecated/).to_stdout | ||
end | ||
|
||
it "returns the value of SHAKAPACKER_RELATIVE_URL_ROOT if set" do | ||
allow(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value") | ||
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value") | ||
|
||
expect(config.relative_url_root).to eq "custom_value" | ||
end | ||
|
||
it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_RELATIVE_URL_ROOT is not set" do | ||
allow(ActionController::Base).to receive(:relative_url_root).and_return("abcd") | ||
allow(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "abcd").and_return("abcd") | ||
context "without SHAKAPACKER_RELATIVE_URL_ROOT set" do | ||
it "returns relative_url_root in shakapacker.yml if set" do | ||
expect(config).to receive(:fetch).with(:relative_url_root).and_return("value-in-config-file") | ||
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "value-in-config-file").and_return("value-in-config-file") | ||
|
||
expect(config.relative_url_root).to eq "value-in-config-file" | ||
end | ||
|
||
expect(config.relative_url_root).to eq "abcd" | ||
context "without relative_url_root set in the shakapacker.yml" do | ||
it "returns ActionController::Base.relative_url_root if SHAKAPACKER_RELATIVE_URL_ROOT is not set" do | ||
expect(ActionController::Base).to receive(:relative_url_root).and_return("abcd") | ||
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "abcd").and_return("abcd") | ||
|
||
expect(config.relative_url_root).to eq "abcd" | ||
end | ||
|
||
context "without ActionController::Base.relative_url_root returing any value" do | ||
it "returns an empty string" do | ||
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return(nil) | ||
|
||
expect(config.relative_url_root).to eq "" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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.
Ca fetch return a ""?
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.
It can. Internally, it runs
fetch
on a hash. So it can potentially return""
or" "
. Though it is very unlikely someone deliberately passkey: ""
in the config file.Should we consider this in fetch as kind of normalization to ensure we either get a meaningful value or nil? I cannot think of any scenario where in the config we want to pass
""
and notnil
.