discourse-rewind/spec/requests/rewinds_controller_spec.rb
Martin Brennan 1cdd3fd708
FIX: Various bugs from 2024 rewind (#29)
* Use post excerpt for best posts to avoid giant posts
  ruining it
* Make sure short emojis (e.g. `😂`) render in best posts
  and best topics
* Make images show in best post excerpts (requires core change)
* Fix invite action error, using column that doesn't exist
* Add missing # for top category slugs
* Refactor report service + controller a little to make it easier
  to figure out what went wrong if it fails, and to use the guardian
  user

Copies a couple of fixes from
https://github.com/discourse/discourse-rewind/pull/28 to make
things work locally, the conflicts will be easy to resolve.

**Best topics before**

<img width="977" height="712" alt="image"
src="https://github.com/user-attachments/assets/e120507f-d0d8-44f0-b242-e1056084ef03"
/>


**Best topics after**

<img width="969" height="648" alt="image"
src="https://github.com/user-attachments/assets/dd13f6ac-35df-4e9a-907e-9ed5102843b6"
/>

**Categories before**

<img width="904" height="465" alt="image"
src="https://github.com/user-attachments/assets/0d15e73d-3534-4836-b776-2c97381e58ef"
/>


**Categories after**

<img width="925" height="466" alt="image"
src="https://github.com/user-attachments/assets/3d6e4eae-32ed-4f11-a4f4-090e4473ebe9"
/>
2025-11-19 09:36:08 +10:00

48 lines
1.2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe DiscourseRewind::RewindsController do
before { SiteSetting.discourse_rewind_enabled = true }
describe "#show" do
fab!(:current_user, :user)
before { sign_in(current_user) }
context "when out of valid month" do
before { freeze_time DateTime.parse("2022-11-24") }
it "returns 404" do
get "/rewinds.json"
expect(response.status).to eq(404)
expect(response.parsed_body["errors"].first).to eq(I18n.t("discourse_rewind.invalid_year"))
end
end
context "when in valid month" do
before { freeze_time DateTime.parse("2022-12-24") }
it "returns 200" do
get "/rewinds.json"
expect(response.status).to eq(200)
end
context "when reports are not found or error" do
before do
DiscourseRewind::Action::TopWords.stubs(:call).raises(StandardError.new("Some error"))
end
it "returns 404 with message" do
get "/rewinds.json"
expect(response.status).to eq(404)
expect(response.parsed_body["errors"].first).to eq(
I18n.t("discourse_rewind.report_failed"),
)
end
end
end
end
end