Skip to content

Commit

Permalink
Show deprecation message for relative_url_root only if used
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Dec 30, 2023
1 parent eb6c420 commit 2146a2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
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 2146a2f

Please sign in to comment.