discourse/plugins/discourse-patreon/spec
Rafael dos Santos Silva b4c5526c51
FIX: Restore "All Patrons" pseudo-tier in admin UI (#39349)
## Summary

The Patreon plugin maintains a synthetic `rewards[\"0\"]` tier ("All
Patrons") that catches every patron, including paying patrons whose
pledge doesn't map to any predefined tier. It's supposed to appear as
`\$0 - All Patrons` in the admin dropdown where group filters are
configured.

In affected campaigns, this option silently disappeared and was replaced
by `\$0 - Free` (Patreon's real default free tier, with its own numeric
id). Admins lost the ability to filter on "any patron".

### Root cause

`rewards[\"0\"] ||= {}` in `lib/campaign.rb` relied on Patreon's payload
having already populated `rewards[\"0\"][\"id\"] = \"0\"` via the
adapter's `parse_campaigns`. For campaigns where Patreon no longer
returns a reward keyed on `\"0\"` (e.g. when the campaign has a real
"Free" tier), the pseudo-tier ended up stored with only `title` and
`amount_cents` — no `id`.

The admin dropdown filters rewards client-side with `r.id >= 0` (in
`assets/javascripts/discourse/controllers/admin-plugins/patreon.js`).
Since `undefined >= 0` evaluates to `false`, "All Patrons" was dropped
from the options. Existing filter rules keyed on `\"0\"` continued to
work on the backend, but admins could no longer create or edit them.

### Fix

Assign `rewards[\"0\"][\"id\"] = \"0\"` explicitly so the pseudo-tier is
always selectable. Confirmed against a live v1 site:
`reward-users[\"0\"]` still tracked all 946 patrons, the backend state
was healthy, only the UI was broken. Applies equally to v1 and v2 since
the assignment runs adapter-agnostic.

Existing filter rules keyed on `\"0\"` keep working and start matching
again on the next sync — no data migration needed.

## Test plan

- [x] `bin/rspec plugins/discourse-patreon/spec/lib/campaign_spec.rb`
passes under both v1 and v2 shared examples, asserting `rewards[\"0\"]`
includes `id: \"0\"`
- [x] `bin/lint` clean
- [ ] On the affected site, run \`Patreon::Campaign.update!\` (or click
*Update Data*) and verify \`\$0 - All Patrons\` reappears in the admin
dropdown and can be assigned to a group
2026-04-17 14:15:37 -03:00
..
fixtures DEV: Upgrade Patreon plugin to API v2 with v1 backward compatibility (#38871) 2026-03-30 14:43:34 -03:00
integration DEV: Upgrade Patreon plugin to API v2 with v1 backward compatibility (#38871) 2026-03-30 14:43:34 -03:00
jobs DEV: Upgrade Patreon plugin to API v2 with v1 backward compatibility (#38871) 2026-03-30 14:43:34 -03:00
lib FIX: Restore "All Patrons" pseudo-tier in admin UI (#39349) 2026-04-17 14:15:37 -03:00
requests DEV: Upgrade Patreon plugin to API v2 with v1 backward compatibility (#38871) 2026-03-30 14:43:34 -03:00
services/problem_check DEV: Upgrade Patreon plugin to API v2 with v1 backward compatibility (#38871) 2026-03-30 14:43:34 -03:00
system DEV: Update rubocop (#38721) 2026-03-20 00:39:52 +01:00
spec_helper.rb DEV: Upgrade Patreon plugin to API v2 with v1 backward compatibility (#38871) 2026-03-30 14:43:34 -03:00