mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 02:59:07 +08:00
Previously, the RSS Polling plugin's admin page predated Discourse's admin interface guidelines: it was a single inline-editable table with no breadcrumbs or page header, it truncated long feed URLs, it required horizontal scrolling on mobile, and it gave admins no way to verify a feed before saving it. This change rebuilds the page on the standard plugin "show route" structure (breadcrumbs, page header, and Settings + Feeds tabs) with a `d-table` feed list and dedicated FormKit new/edit routes, so the UI now matches the rest of the admin interface and works on mobile. It also: - Adds a **Test feed** dry-run that fetches a feed and previews which items would be imported or skipped, with plain-language reasons, so admins can validate a feed (and fix setup errors) before saving it. - Adds the `rss_polling_feed_request_timeout` and `rss_polling_verbose_logging` site settings. - Extracts the fetch/parse and import/skip logic into `FeedFetcher` and `FeedAnalyzer`, shared by the poll job and the new preview so the dry-run and the real import always agree. - Normalizes feed dates and categories so Atom feeds (which use `<updated>` and `term`-style `<category>` elements) are handled like RSS, and returns a clean error instead of a 500 when a feed cannot be read. --------- Co-authored-by: Martin Brennan <martin@discourse.org>
78 lines
2.1 KiB
Ruby
Vendored
78 lines
2.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe DiscourseRssPolling::RssFeed do
|
|
fab!(:user)
|
|
|
|
describe "#user" do
|
|
it "belongs_to a user" do
|
|
feed = Fabricate(:rss_feed, user: user)
|
|
expect(feed.user).to eq(user)
|
|
end
|
|
|
|
it "falls back to the system user when the author is missing or was deleted" do
|
|
feed = Fabricate(:rss_feed, user: nil)
|
|
expect(feed.user).to eq(Discourse.system_user)
|
|
end
|
|
end
|
|
|
|
describe "#enabled" do
|
|
it "defaults to true" do
|
|
feed = Fabricate(:rss_feed, user: user)
|
|
expect(feed.enabled).to eq(true)
|
|
end
|
|
end
|
|
|
|
describe ".enabled" do
|
|
it "only returns enabled feeds" do
|
|
enabled_feed = Fabricate(:rss_feed, user: user)
|
|
Fabricate(:rss_feed, user: user, enabled: false)
|
|
|
|
expect(described_class.enabled).to contain_exactly(enabled_feed)
|
|
end
|
|
end
|
|
|
|
describe "legacy author column" do
|
|
it "is hidden by ignored_columns so the model cannot drift again" do
|
|
expect { described_class.new(author: "anything") }.to raise_error(
|
|
ActiveModel::UnknownAttributeError,
|
|
)
|
|
end
|
|
end
|
|
|
|
describe "#poll" do
|
|
fab!(:feed) do
|
|
Fabricate(
|
|
:rss_feed,
|
|
url: "https://example.com/feed",
|
|
user: user,
|
|
category_id: 1,
|
|
tags: "foo,bar",
|
|
category_filter: "updates",
|
|
)
|
|
end
|
|
|
|
it "enqueues a PollFeed job with the feed's attributes" do
|
|
Sidekiq::Testing.fake! do
|
|
expect { feed.poll }.to change { Jobs::DiscourseRssPolling::PollFeed.jobs.size }.by(1)
|
|
|
|
args = Jobs::DiscourseRssPolling::PollFeed.jobs.last["args"][0]
|
|
expect(args).to include(
|
|
"feed_url" => "https://example.com/feed",
|
|
"user_id" => user.id,
|
|
"discourse_category_id" => 1,
|
|
"discourse_tags" => %w[foo bar],
|
|
"feed_category_filter" => "updates",
|
|
)
|
|
end
|
|
end
|
|
|
|
it "executes the PollFeed job inline when inline: true is passed" do
|
|
Jobs::DiscourseRssPolling::PollFeed
|
|
.any_instance
|
|
.expects(:execute)
|
|
.with(has_entries(feed_url: "https://example.com/feed", user_id: user.id))
|
|
|
|
feed.poll(inline: true)
|
|
end
|
|
end
|
|
end
|