0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/plugins/discourse-rss-polling/spec/system/admin_spec.rb
Régis Hanol d1a27693cf
FIX: Normalize tag-chooser tags to names in RSS polling and chat archive (#41654)
### What

Since #36678, `tag-chooser`/`mini-tag-chooser` emit an array of tag
**objects** instead of tag name strings. Two consumers still assumed
name strings and broke:

1. **RSS polling feed form** — the client-side required-tag validation
compared the category's required tag *names* against the selected tag
*objects*, so the comparison always failed. A feed pointed at a category
with a required tag group could never be saved from the UI, even when
the required tag was selected (reported on meta).

2. **Chat "archive channel → new topic"** — the selected tags were
POSTed as objects, which the controller's `tags: []` strong parameter
rejects, so the destination topic was created without any of the chosen
tags.

### Fix

Both consumers now map the tag objects to their `.name` before comparing
/ submitting, matching what the server (`normalize_tags`) and
select-kit's own `validateCreate` already do.

### Tests

Extended the existing system specs rather than adding new ones:
- RSS polling admin spec: the "saves the configuration" test's category
now requires the tag it selects, so the save exercises the required-tag
validation.
- Chat archive spec: the "works" test now selects a tag and asserts it
reaches the archive (`destination_tags`).
2026-07-13 14:19:14 +02:00

158 lines
5.1 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "Rss Polling - admin" do
fab!(:current_user, :admin)
fab!(:category_1, :category)
fab!(:tag_1, :tag)
let(:url) { "http://example.com/rss" }
before do
SiteSetting.rss_polling_enabled = true
sign_in(current_user)
end
it "tests a feed and saves the configuration" do
stub_request(:get, url).to_return(status: 200, body: file_from_fixtures("feed.rss", "feed"))
tag_group = Fabricate(:tag_group, tags: [tag_1])
CategoryRequiredTagGroup.create!(category: category_1, tag_group:, min_count: 1)
visit("/admin/plugins/discourse-rss-polling/feeds")
find(".rss-polling-feeds__add").click
form = PageObjects::Components::FormKit.new(".rss-polling-feed-form")
form.field("feed_url").fill_in(url)
form.field("feed_category_filter").fill_in("updates")
author = PageObjects::Components::SelectKit.new(".rss-polling-feed-form__author")
author.expand
author.search(current_user.username)
author.select_row_by_value(current_user.username)
category = PageObjects::Components::SelectKit.new(".rss-polling-feed-form__category")
category.expand
category.search(category_1.name)
category.select_row_by_value(category_1.id)
tag = PageObjects::Components::SelectKit.new(".rss-polling-feed-form__tags")
tag.expand
tag.search(tag_1.name)
tag.select_row_by_name(tag_1.name)
tag.collapse
find(".rss-polling-feed-form__test").click
expect(page).to have_css(".rss-polling-feed-test")
form.submit
expect(page).to have_css(".rss-polling-feed-form")
expect(DiscourseRssPolling::RssFeed.last).to have_attributes(
url:,
user_id: current_user.id,
category_filter: "updates",
category_id: category_1.id,
tags: tag_1.name,
)
end
it "keeps Test feed enabled and surfaces the server error for a blank URL" do
visit("/admin/plugins/discourse-rss-polling/feeds")
find(".rss-polling-feeds__add").click
expect(page).to have_no_css(".rss-polling-feed-form__test[disabled]")
find(".rss-polling-feed-form__test").click
expect(page).to have_css(".rss-polling-feed-test__error")
expect(page).to have_content(I18n.t("js.admin.rss_polling.test.errors.blank_feed_url"))
end
it "can disable and re-enable a feed without deleting it" do
feed = Fabricate(:rss_feed, user: current_user)
visit("/admin/plugins/discourse-rss-polling/feeds")
expect(page).to have_css(".rss-polling-feed")
toggle = PageObjects::Components::DToggleSwitch.new(".rss-polling-feed__toggle")
expect(toggle).to be_checked
toggle.toggle
expect(page).to have_css(".rss-polling-feed.is-disabled")
expect(toggle).to be_unchecked
try_until_success { expect(feed.reload.enabled).to eq(false) }
toggle.toggle
expect(page).to have_no_css(".rss-polling-feed.is-disabled")
expect(toggle).to be_checked
try_until_success { expect(feed.reload.enabled).to eq(true) }
end
it "shows the feed settings and its poll history on one page" do
feed = Fabricate(:rss_feed, user: current_user)
DiscourseRssPolling::PollAttempt.record!(
rss_feed_id: feed.id,
items: [
{
"title" => "An imported item",
"url" => "https://example.com/rss/item",
"status" => "imported",
"topic_url" => "/t/-/1",
},
],
)
visit("/admin/plugins/discourse-rss-polling/feeds/#{feed.id}/edit")
expect(page).to have_css(".rss-polling-feed-form")
expect(page).to have_css(".rss-polling-feed-form__poll")
expect(page).to have_css(".rss-polling-feed-history")
expect(page).to have_content("1 imported")
end
it "disables Poll now while the feed has unsaved edits" do
feed = Fabricate(:rss_feed, user: current_user, category_filter: "old")
visit("/admin/plugins/discourse-rss-polling/feeds/#{feed.id}/edit")
expect(page).to have_css(".rss-polling-feed-form__poll")
expect(page).to have_no_css(".rss-polling-feed-form__poll[disabled]")
form = PageObjects::Components::FormKit.new(".rss-polling-feed-form")
form.field("feed_category_filter").fill_in("changed")
expect(page).to have_css(".rss-polling-feed-form__poll[disabled]")
form.submit
expect(page).to have_no_css(".rss-polling-feed-form__poll[disabled]")
expect(feed.reload.category_filter).to eq("changed")
end
it "disables Poll now while the feed is disabled" do
feed = Fabricate(:rss_feed, user: current_user, enabled: false)
visit("/admin/plugins/discourse-rss-polling/feeds/#{feed.id}/edit")
expect(page).to have_css(".rss-polling-feed-form__poll[disabled]")
PageObjects::Components::DToggleSwitch.new(".rss-polling-feed-form__toggle").toggle
expect(page).to have_no_css(".rss-polling-feed-form__poll[disabled]")
try_until_success { expect(feed.reload.enabled).to eq(true) }
end
it "redirects to the feeds list when editing a feed that no longer exists" do
visit("/admin/plugins/discourse-rss-polling/feeds/0/edit")
expect(page).to have_current_path("/admin/plugins/discourse-rss-polling/feeds")
expect(page).to have_css(".rss-polling-feeds__add")
end
end