A platform for community discussion. Free, open, simple.
FIX: links in rss feeds are sometimes wrong on subfolder installs
Neil Lalondeebe7835316d6
diff --git a/app/views/topics/show.rss.erb b/app/views/topics/show.rss.erbindex a7efff93641..729fa86071d 100644--- a/app/views/topics/show.rss.erb+++ b/app/views/topics/show.rss.erb@@ -31,7 +31,7 @@<link><%= post_url %></link><pubDate><%= post.created_at.rfc2822 %></pubDate><guid isPermaLink="false"><%= Discourse.current_hostname %>-post-<%= post.topic_id %>-<%= post.post_number %></guid>- <source url="<%= @topic_view.absolute_url %>.rss"><%= @topic_view.title %></source>+ <source url="<%= topic_url %>.rss"><%= @topic_view.title %></source></item><% end %></channel>diff --git a/lib/topic_view.rb b/lib/topic_view.rbindex 8020ba72de2..710ca9ddf1b 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -144,7 +144,7 @@ class TopicViewenddef absolute_url- "#{Discourse.base_url}#{relative_url}"+ "#{Discourse.base_url_no_prefix}#{relative_url}"enddef relative_urldiff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex 05fd50db590..6dc6bc72c75 100644--- a/spec/components/topic_view_spec.rb+++ b/spec/components/topic_view_spec.rb@@ -161,7 +161,18 @@ describe TopicView doendit "provides an absolute url" do- expect(topic_view.absolute_url).to be_present+ expect(topic_view.absolute_url).to eq("http://test.localhost/t/#{topic.slug}/#{topic.id}")+ end++ context 'subfolder' do+ before do+ GlobalSetting.stubs(:relative_url_root).returns('/forum')+ Discourse.stubs(:base_uri).returns("/forum")+ end++ it "provides the correct absolute url" do+ expect(topic_view.absolute_url).to eq("http://test.localhost/forum/t/#{topic.slug}/#{topic.id}")+ endendit "provides a summary of the first post" dodiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 3ea4170486f..7791f2dda32 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -270,6 +270,17 @@ RSpec.describe ListController doexpect(response.content_type).to eq('application/rss+xml')end+ it 'renders links correctly with subfolder' do+ GlobalSetting.stubs(:relative_url_root).returns('/forum')+ Discourse.stubs(:base_uri).returns("/forum")+ post = Fabricate(:post, topic: topic, user: user)+ get "/latest.rss"+ expect(response.status).to eq(200)+ expect(response.body).to_not include("/forum/forum")+ expect(response.body).to include("http://test.localhost/forum/t/#{topic.slug}")+ expect(response.body).to include("http://test.localhost/forum/u/#{post.user.username}")+ end+it 'renders top RSS' doget "/top.rss"expect(response.status).to eq(200)diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex ea6638697b6..94c9a010055 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1540,6 +1540,15 @@ RSpec.describe TopicsController doexpect(response.status).to eq(200)expect(response.content_type).to eq('application/rss+xml')end++ it 'renders rss of the topic correctly with subfolder' do+ GlobalSetting.stubs(:relative_url_root).returns('/forum')+ Discourse.stubs(:base_uri).returns("/forum")+ get "/t/foo/#{topic.id}.rss"+ expect(response.status).to eq(200)+ expect(response.body).to_not include("/forum/forum")+ expect(response.body).to include("http://test.localhost/forum/t/#{topic.slug}")+ endenddescribe '#invite_group' do