FIX: links in rss feeds are sometimes wrong on subfolder installs

This commit is contained in:
Neil Lalonde 2018-08-27 18:05:08 -04:00
parent d6144c6d60
commit ebe7835316
5 changed files with 34 additions and 3 deletions

View File

@ -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>

View File

@ -144,7 +144,7 @@ class TopicView
end
def absolute_url
"#{Discourse.base_url}#{relative_url}"
"#{Discourse.base_url_no_prefix}#{relative_url}"
end
def relative_url

View File

@ -161,7 +161,18 @@ describe TopicView do
end
it "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}")
end
end
it "provides a summary of the first post" do

View File

@ -270,6 +270,17 @@ RSpec.describe ListController do
expect(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' do
get "/top.rss"
expect(response.status).to eq(200)

View File

@ -1540,6 +1540,15 @@ RSpec.describe TopicsController do
expect(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}")
end
end
describe '#invite_group' do