2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-05 15:27:34 +08:00
discourse/spec/support/shared_examples/common_basic_reviewable_seralizer.rb
Loïc Guitaut 4f82ceaf39 DEV: Introduce core features system specs for plugins
This patch adds a new shared example to be used as a smoke test in
plugins and themes.

A `skip_examples` argument is available to easily opt-out from a
category of tests.

Example:
```rb
RSpec.describe "Testing core features", type: :system do
  it_behaves_like "having working core features", skip_examples: %i[search login]
end
```
2025-03-27 12:12:01 +01:00

47 lines
1.3 KiB
Ruby

# frozen_string_literal: true
RSpec.shared_examples "basic reviewable attributes" do
describe "#id" do
it "equals the reviewable's id" do
expect(subject[:id]).to eq(reviewable.id)
end
end
describe "#type" do
it "is the reviewable's type" do
expect(subject[:type]).to eq(reviewable.type)
end
end
describe "#pending" do
it "is false if the reviewable is approved" do
reviewable.update!(status: Reviewable.statuses[:approved])
expect(subject[:pending]).to eq(false)
end
it "is false if the reviewable is rejected" do
reviewable.update!(status: Reviewable.statuses[:rejected])
expect(subject[:pending]).to eq(false)
end
it "is true if the reviewable is pending" do
reviewable.update!(status: Reviewable.statuses[:pending])
expect(subject[:pending]).to eq(true)
end
end
describe "#flagger_username" do
it "equals to the username of the user who created the reviewable" do
reviewable.update!(created_by: Fabricate(:user, username: "gg.osama"))
expect(subject[:flagger_username]).to eq("gg.osama")
end
end
describe "#created_at" do
it "serializes the reviewable's created_at field correctly" do
time = 10.minutes.ago
reviewable.update!(created_at: time)
expect(subject[:created_at]).to eq(time)
end
end
end