Skip to content

Commit

Permalink
Show deprecation message for relative_url_root only if used (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha authored Jan 1, 2024
1 parent eb6c420 commit 3804fd1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Changes since the last non-beta release.

_Please add entries here for your pull requests that are not yet released._

### Fixed
- Show deprecation message for `relative_url_root` only if it is set. [PR 400](https://github.com/shakacode/shakapacker/pull/400) by [ahangarha](https://github.com/ahangarha).

## [v7.2.0] - December 28, 2023

### Added
Expand All @@ -23,7 +26,7 @@ _Please add entries here for your pull requests that are not yet released._
- Disable Hot Module Replacement in `webpack-dev-server` when `hmr: false` [PR 392](https://github.com/shakacode/shakapacker/pull/392) by [thedanbob](https://github.com/thedanbob).

### Deprecated
- The usage of relative_url_root is deprecated in Shakapacker and will be removed in v8. [PR 376](https://github.com/shakacode/shakapacker/pull/376) by [ahangarha](https://github.com/ahangarha).
- The usage of `relative_url_root` is deprecated in Shakapacker and will be removed in v8. [PR 376](https://github.com/shakacode/shakapacker/pull/376) by [ahangarha](https://github.com/ahangarha).

## [v7.1.0] - September 30, 2023

Expand Down
10 changes: 7 additions & 3 deletions lib/shakapacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ def asset_host
end

def 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(
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
Expand Down
21 changes: 14 additions & 7 deletions spec/shakapacker/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,17 @@
)
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
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value")
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

expect(config.relative_url_root).to eq "custom_value"
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
Expand All @@ -415,6 +418,10 @@

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
Expand Down

0 comments on commit 3804fd1

Please sign in to comment.