* Use the feed source url when the feed url (from links) is empty This probably should just be using @feed_source_url always to make a base path for absolute paths without a hostname, rather than expecting this from the feed. An example why we should not be using @feed.url would be individual posts at domain/slug but the "index" page at domain/blog (with a generic screen on /), and images hosted from /assets/ without /blog/ anywhere in the asset path. Partial fix for #15488 * Use item.url as base_url for relative links It's possible the rss feed and the contained articles are served from separate hosts/subdomains/paths. Don't assume the entries are related to the feed or the feed_source_url, use the item's url for relative links in that item. * Update failing spec to add url to item double
55 lines
1.8 KiB
Ruby
55 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Feeds::AssembleArticleMarkdown, type: :service do
|
|
let(:user) do
|
|
create(:user).tap do |u|
|
|
u.setting.update(feed_mark_canonical: true)
|
|
end
|
|
end
|
|
let(:feed_source_url) { "https://feed.source/url" }
|
|
let(:feed) { instance_double("Feedjira::Parser::RSS", url: "https://feed.source/") }
|
|
let(:title) { "A title" }
|
|
let(:content) { "Some content that came in with the item, should be the body" }
|
|
|
|
let(:item) do
|
|
instance_double(
|
|
"Feedjira::Parser::RSSEntry",
|
|
title: title,
|
|
categories: %w[tag1 tag2 tag3 tag4 tag5],
|
|
published: "2020-12-20",
|
|
content: content,
|
|
url: "https://feed.source",
|
|
)
|
|
end
|
|
|
|
let(:feeds_assemble_article_markdown) { described_class.new(item, user, feed, feed_source_url) }
|
|
|
|
it "creates markdown head matter" do
|
|
body = feeds_assemble_article_markdown.call
|
|
|
|
expect(body).to include("title: A title")
|
|
expect(body).to include("date: 2020-12-20")
|
|
end
|
|
|
|
it "includes the content from the feed" do
|
|
body = feeds_assemble_article_markdown.call
|
|
|
|
expect(body).to include(content)
|
|
end
|
|
|
|
context "when item has a long title" do
|
|
let(:title) { "Words " * 25 }
|
|
|
|
it "limits the title to 128 characters by truncation" do
|
|
body = feeds_assemble_article_markdown.call
|
|
|
|
title_line = body.lines.detect { |line| line.starts_with?("title:") }
|
|
shortened_title = title_line.split(":").second.strip
|
|
# we expect 21 "Words" plus an ellipsis, total of 128 characters
|
|
expected_title = "Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words Words..." # rubocop:disable Layout/LineLength
|
|
|
|
expect(shortened_title.size).to eq(128)
|
|
expect(shortened_title).to eq(expected_title)
|
|
end
|
|
end
|
|
end
|