FIX: Render links with subfolders properly in Discobot
Currently, some links aren’t properly built in Discobot when Discourse is hosted in a subfolder. This is because we’re providing `Discourse.base_url` to the Rails helpers which contains the base URL *with* the prefix. But Rails helpers already handle this prefix so the resulting link gets the prefix twice. The fix is quite simple: use `Discourse.base_url_no_prefix` instead of `Discourse.base_url`.
This commit is contained in:
parent
a5235f7d16
commit
430d6308a8
plugins/discourse-narrative-bot
lib/discourse_narrative_bot
spec/discourse_narrative_bot
spec/support
|
@ -638,7 +638,10 @@ module DiscourseNarrativeBot
|
|||
end
|
||||
|
||||
def url_helpers(url, opts = {})
|
||||
Rails.application.routes.url_helpers.public_send(url, opts.merge(host: Discourse.base_url))
|
||||
Rails.application.routes.url_helpers.public_send(
|
||||
url,
|
||||
opts.merge(host: Discourse.base_url_no_prefix),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -286,22 +286,27 @@ RSpec.describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
)
|
||||
end
|
||||
|
||||
it "should create the right reply when the bookmark is created" do
|
||||
post.update!(user: discobot_user)
|
||||
narrative.expects(:enqueue_timeout_job).with(user)
|
||||
|
||||
narrative.input(:bookmark, user, post: post)
|
||||
new_post = Post.last
|
||||
profile_page_url = "#{Discourse.base_url}/u/#{user.username}"
|
||||
|
||||
expected_raw = <<~RAW
|
||||
context "when the bookmark is created" do
|
||||
let(:profile_page_url) { "#{Discourse.base_url_no_prefix}/prefix/u/#{user.username}" }
|
||||
let(:new_post) { Post.last }
|
||||
let(:user_state) { narrative.get_data(user)[:state].to_sym }
|
||||
let(:expected_raw) { <<~RAW }
|
||||
#{I18n.t("discourse_narrative_bot.new_user_narrative.bookmark.reply", bookmark_url: "#{profile_page_url}/activity/bookmarks", base_uri: "")}
|
||||
|
||||
#{I18n.t("discourse_narrative_bot.new_user_narrative.onebox.instructions", base_uri: "")}
|
||||
RAW
|
||||
|
||||
expect(new_post.raw).to eq(expected_raw.chomp)
|
||||
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_onebox)
|
||||
before do
|
||||
set_subfolder("/prefix")
|
||||
post.update!(user: discobot_user)
|
||||
narrative.stubs(:enqueue_timeout_job).with(user)
|
||||
end
|
||||
|
||||
it "creates the right reply" do
|
||||
narrative.input(:bookmark, user, post: post)
|
||||
expect(new_post.raw).to eq(expected_raw.chomp)
|
||||
expect(user_state).to eq(:tutorial_onebox)
|
||||
end
|
||||
end
|
||||
|
||||
it "should skip tutorials in SiteSetting.discourse_narrative_bot_skip_tutorials" do
|
||||
|
|
|
@ -153,6 +153,7 @@ module Helpers
|
|||
global_setting :relative_url_root, f
|
||||
old_root = ActionController::Base.config.relative_url_root
|
||||
ActionController::Base.config.relative_url_root = f
|
||||
Rails.application.routes.stubs(:relative_url_root).returns(f)
|
||||
|
||||
before_next_spec { ActionController::Base.config.relative_url_root = old_root }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue