Skip to content

Commit

Permalink
feat!: remove relative_url_root option (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored and ahangarha committed Mar 28, 2024
1 parent 45474a8 commit 7f58b14
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ _next_ branch is for v8 changes
Changes since the last non-beta release.

### Breaking changes
- Remove `relative_url_root` [PR 413](https://github.com/shakacode/shakapacker/pull/413) by [G-Rath](https://github.com/g-rath).

- Removes deprecated support of `Webpacker` spelling, config variables and constants. [PR 429](https://github.com/shakacode/shakapacker/pull/429) by [tomdracz](https://github.com/tomdracz).

The usage of those has been deprecated in Shakapacker v7 and now fully removed in v8. See the [v7 Upgrade Guide](./docs/v7_upgrade.md) for more information if you are still yet to address this deprecation.
Expand Down
5 changes: 2 additions & 3 deletions lib/shakapacker/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ def webpack_env
return env unless defined?(ActionController::Base)

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
"SHAKAPACKER_ASSET_HOST" => instance.config.asset_host,
"SHAKAPACKER_CONFIG" => instance.config_path.to_s
)
end

Expand Down
13 changes: 0 additions & 13 deletions lib/shakapacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ def asset_host
)
end

def relative_url_root
result = ENV.fetch(
"SHAKAPACKER_RELATIVE_URL_ROOT",
fetch(:relative_url_root) || ActionController::Base.relative_url_root
)

if result
Shakapacker.puts_deprecation_message("The usage of relative_url_root is deprecated in Shakapacker and will be removed in v8.")
end

result
end

private
def data
@data ||= load
Expand Down
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 be nil
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to be nil

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
52 changes: 0 additions & 52 deletions spec/shakapacker/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,56 +374,4 @@
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

context "with SHAKAPACKER_RELATIVE_URL_ROOT set" do
before do
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value")
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" do
expect(config.relative_url_root).to eq "custom_value"
end
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 be nil
end

it "doesn't shows deprecation message" do
expect { config.relative_url_root }.to_not output(/deprecated/).to_stdout
end
end
end
end
end
end

0 comments on commit 7f58b14

Please sign in to comment.