Skip to content

Commit

Permalink
Remove any references to relative_url_root
Browse files Browse the repository at this point in the history
Despite being added in webpacker, it never got used. There is no
functionality tied to this configuration and this commit, removes its
references in the code and tests.
  • Loading branch information
ahangarha committed Nov 24, 2023
1 parent ed9b516 commit a627eb4
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 59 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _Please add entries here for your pull requests that are not yet released._

### Added
- Experimental support for other JS package managers using `package_json` gem [PR 349](https://github.com/shakacode/shakapacker/pull/349) by [G-Rath](https://github.com/g-rath).
- Use `config/shakapacker.yml` as the secondary source for `asset_host` and `relative_url_root` configurations [PR 376](https://github.com/shakacode/shakapacker/pull/376) by [ahangarha](https://github.com/ahangarha).
- Use `config/shakapacker.yml` as the secondary source for `asset_host` configuration [PR 376](https://github.com/shakacode/shakapacker/pull/376) by [ahangarha](https://github.com/ahangarha).

### Fixed
- Recommend `server` option instead of deprecated `https` option when `--https` is provided [PR 380](https://github.com/shakacode/shakapacker/pull/380) by [G-Rath](https://github.com/g-rath)
Expand Down
2 changes: 0 additions & 2 deletions lib/install/config/shakapacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ default: &default
# SHAKAPACKER_ASSET_HOST will override both configurations.
# asset_host: custom-path

# relative_url_root: custom-path

development:
<<: *default
compile: true
Expand Down
1 change: 0 additions & 1 deletion lib/shakapacker/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def webpack_env

env.merge(
"SHAKAPACKER_ASSET_HOST" => instance.config.asset_host,
"SHAKAPACKER_RELATIVE_URL_ROOT" => instance.config.relative_url_root,
"SHAKAPACKER_CONFIG" => instance.config_path.to_s
)
end
Expand Down
7 changes: 0 additions & 7 deletions lib/shakapacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ def asset_host
).to_s
end

def relative_url_root
ENV.fetch(
"SHAKAPACKER_RELATIVE_URL_ROOT",
fetch(:relative_url_root) || ActionController::Base.relative_url_root
).to_s
end

private
def data
@data ||= load
Expand Down
3 changes: 0 additions & 3 deletions spec/backward_compatibility_specs/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@

it "accepts external env variables" do
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq ""
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq ""

ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"

expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq "/baz"
end
end
3 changes: 0 additions & 3 deletions spec/shakapacker/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@

it "accepts external env variables" do
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq ""
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq ""

allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("foo.bar")
allow(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("/baz")

expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq "/baz"
end
end
42 changes: 0 additions & 42 deletions spec/shakapacker/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,46 +373,4 @@
end
end
end

describe "#relative_url_root" do
let(:config) do
Shakapacker::Configuration.new(
root_path: ROOT_PATH,
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
env: "production"
)
end

it "returns the value of SHAKAPACKER_RELATIVE_URL_ROOT if set" do
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

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

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

0 comments on commit a627eb4

Please sign in to comment.