A platform for community discussion. Free, open, simple.
FIX: Render links with subfolders properly in Discobot
Loïc Guitaut430d6308a818
diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rbindex fc1a69ea195..7ad317c77e4 100644--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb@@ -638,7 +638,10 @@ module DiscourseNarrativeBotenddef 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),+ )endendenddiff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rbindex 500a0b68af0..37654e5886e 100644--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb@@ -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)+ endendit "should skip tutorials in SiteSetting.discourse_narrative_bot_skip_tutorials" dodiff --git a/spec/support/helpers.rb b/spec/support/helpers.rbindex ff611df35e3..6cc73913d98 100644--- a/spec/support/helpers.rb+++ b/spec/support/helpers.rb@@ -153,6 +153,7 @@ module Helpersglobal_setting :relative_url_root, fold_root = ActionController::Base.config.relative_url_rootActionController::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