Add image composite element to feed if user exists (#10739) [deploy]
* Add image composite element to feed if user exists If the feed is a tag or the latest feed, user won't exist and we don't want to render an <image> tag in the feed. * Use profile_image_90 to limit the width and height * Add tests for feed; address cr comments * Fix typo * Address rubocop issues * Fix another typo * Fix tests Co-authored-by: rhymes <rhymes@hey.com>
This commit is contained in:
parent
d03d03bc39
commit
977f4d8840
2 changed files with 39 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
# rubocop:disable Metrics/BlockLength
|
||||
|
||||
xml.instruct! :xml, version: "1.0"
|
||||
xml.rss version: "2.0" do
|
||||
xml.channel do
|
||||
|
|
@ -8,7 +10,13 @@ xml.rss version: "2.0" do
|
|||
xml.description user ? user.summary : SiteConfig.community_description
|
||||
xml.link user ? app_url(user.path) : app_url
|
||||
xml.language "en"
|
||||
|
||||
if user
|
||||
xml.image do
|
||||
xml.url user.profile_image_90
|
||||
xml.title "#{user.name} profile image"
|
||||
xml.link app_url(user.path)
|
||||
end
|
||||
end
|
||||
articles.each do |article|
|
||||
xml.item do
|
||||
xml.title article.title
|
||||
|
|
@ -24,3 +32,4 @@ xml.rss version: "2.0" do
|
|||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/BlockLength
|
||||
|
|
|
|||
|
|
@ -26,6 +26,13 @@ RSpec.describe "Articles", type: :request do
|
|||
expect { get "/feed/#{tag.name}" }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "does not contain image tag" do
|
||||
create(:article, featured: true)
|
||||
|
||||
get feed_path
|
||||
expect(response.body).not_to include("<image>")
|
||||
end
|
||||
|
||||
context "with caching headers" do
|
||||
before do
|
||||
create(:article, featured: true)
|
||||
|
|
@ -92,6 +99,14 @@ RSpec.describe "Articles", type: :request do
|
|||
it "contains the full user URL" do
|
||||
expect(response.body).to include("<link>#{URL.user(user)}</link>")
|
||||
end
|
||||
|
||||
it "contains a user composite profile image tag" do
|
||||
expect(response.body).to include("<image>")
|
||||
expect(response.body).to include("<url>#{user.profile_image_90}</url>")
|
||||
expect(response.body).to include("<title>#{user.name} profile image</title>")
|
||||
expect(response.body).to include("<link>#{URL.user(user)}</link>")
|
||||
expect(response.body).to include("</image>")
|
||||
end
|
||||
end
|
||||
|
||||
context "when :username param is given and belongs to an organization" do
|
||||
|
|
@ -110,6 +125,14 @@ RSpec.describe "Articles", type: :request do
|
|||
it "contains the full organization URL" do
|
||||
expect(response.body).to include("<link>#{URL.organization(organization)}</link>")
|
||||
end
|
||||
|
||||
it "contains an organization composite profile image tag" do
|
||||
expect(response.body).to include("<image>")
|
||||
expect(response.body).to include("<url>#{organization.profile_image_90}</url>")
|
||||
expect(response.body).to include("<title>#{organization.name} profile image</title>")
|
||||
expect(response.body).to include("<link>#{URL.user(organization)}</link>")
|
||||
expect(response.body).to include("</image>")
|
||||
end
|
||||
end
|
||||
|
||||
context "when :username param is given but it belongs to neither user nor organization" do
|
||||
|
|
@ -169,6 +192,12 @@ RSpec.describe "Articles", type: :request do
|
|||
|
||||
expect(response.body).to include("<link>#{URL.url}</link>")
|
||||
end
|
||||
|
||||
it "does not contain image tag" do
|
||||
get tag_feed_path(tag.name)
|
||||
|
||||
expect(response.body).not_to include("<image>")
|
||||
end
|
||||
end
|
||||
|
||||
context "when :tag param is given and tag exists and is an alias" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue