2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/models/reviewable_post_spec.rb
Krzysztof Kotlarek 53d799eb8b
DEV: Remove reviewable_ui_refresh feature flag and legacy code (#36752)
Following PR #36711 which enabled the refreshed review UI for all users, this commit removes the old feature flag infrastructure and cleans up legacy code that is no longer needed.

Backend Changes:
  - Removed ReviewableActionLog model and its spec entirely
  - Removed CalculateFinalStatusFromLogs service and spec
  - Removed site settings: force_old_reviewable_ui, reviewable_old_moderator_actions
  - Simplified ReviewableActionBuilder — stripped out legacy action-building methods (build_user_actions_bundle, build_post_actions_bundle, build_new_separated_actions)
  - Cleaned up reviewable models (ReviewableFlaggedPost, ReviewablePost, ReviewableQueuedPost, ReviewableUser, Chat::ReviewableMessage, ReviewablePostVotingComment) — removed unused/legacy action definitions
  - Removed legacy specs for action builder, action logs, flagged post actions, post actions, user actions, and status-from-logs
  - Updated system tests and page objects to reflect the new UI structure

  Frontend Changes:

  - Deleted legacy components: reviewable-item.gjs, reviewable-user.gjs, review-index-legacy.gjs
  - Renamed reviewable-refresh/ → reviewable/ — moved all sub-components (created-by, flagged-post, item, post, queued-post, topic-link, user, etc.) out of the refresh directory into the canonical reviewable/ namespace
  - Simplified reviewable/item.gjs — removed feature flag conditionals and legacy code paths
  - Cleaned up review/index.gjs and review/show.gjs templates — removed branching between old/new UI
  - Updated plugin components (chat, AI, post-voting) to import from reviewable/ instead of reviewable-refresh/
  - Removed acceptance tests (review-test.js) replaced by system tests
  - Renamed and updated integration tests from reviewable-refresh/* to reviewable/*

Plan for next PRs:
- Move plugins from Pages::RefreshedReview to Pages::Review 
- Move plugins to import from `reviewable/` and not `refreshed-reviewable/`
- Move reviewable-user.js import in plugin to use `reviewable/user.js`
- Remove unused settings like `reviewable_old_moderator_actions` from plugins
- Delete `Pages::RefreshedReview`
- Delete `reviewable-refresh/` directory
- Delete `reviewable-user.js` component
- Delete `reviewable_old_moderator_actions` site setting

Plugins PRs:
- https://github.com/discourse/discourse-akismet/pull/203
- https://github.com/discourse/discourse-antivirus/pull/98
- https://github.com/discourse/discourse-category-experts/pull/223
2026-02-23 10:45:36 +08:00

128 lines
3.9 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ReviewablePost do
fab!(:admin)
describe "#build_actions" do
let(:post) { Fabricate.build(:post) }
let(:reviewable) { ReviewablePost.new(target: post) }
let(:guardian) { Guardian.new }
it "Does not return available actions when the reviewable is no longer pending" do
available_actions =
(Reviewable.statuses.keys - ["pending"]).reduce([]) do |actions, status|
reviewable.status = status
actions.concat reviewable_actions(guardian).to_a
end
expect(available_actions).to be_empty
end
it "only shows the approve post action if users cannot delete the post" do
expect(reviewable_actions(guardian).has?(:approve)).to eq(true)
expect(reviewable_actions(guardian).has?(:reject_and_delete)).to eq(false)
end
it "includes the reject and delete action if the user is allowed" do
expect(reviewable_actions(Guardian.new(admin)).has?(:reject_and_delete)).to eq(true)
end
it "includes the approve post and unhide action if the post is hidden" do
post.hidden = true
actions = reviewable_actions(guardian)
expect(actions.has?(:approve_and_unhide)).to eq(true)
end
it "includes the reject post and keep deleted action is the post is deleted" do
post.deleted_at = 1.day.ago
actions = reviewable_actions(guardian)
expect(actions.has?(:approve_and_restore)).to eq(false)
expect(actions.has?(:reject_and_keep_deleted)).to eq(true)
end
it "includes an option to approve and restore the post if the user is allowed" do
post.deleted_at = 1.day.ago
actions = reviewable_actions(Guardian.new(admin))
expect(actions.has?(:approve_and_restore)).to eq(false)
end
def reviewable_actions(guardian)
actions = Reviewable::Actions.new(reviewable, guardian, {})
reviewable.build_actions(actions, guardian, {})
actions
end
end
describe "Performing actions" do
let(:post) { Fabricate(:post) }
let(:reviewable) { ReviewablePost.needs_review!(target: post, created_by: admin) }
before { reviewable.created_new! }
describe "#perform_approve" do
it "transitions to the approved state" do
result = reviewable.perform admin, :approve
expect(result.transition_to).to eq :approved
end
end
describe "#perform_reject_and_suspend" do
it "transitions to the rejected state" do
result = reviewable.perform admin, :reject_and_suspend
expect(result.transition_to).to eq :rejected
end
end
describe "#perform_reject_and_keep_deleted" do
it "transitions to the rejected state and keep the post deleted" do
post.trash!
result = reviewable.perform admin, :reject_and_keep_deleted
expect(result.transition_to).to eq :rejected
expect(Post.where(id: post.id).exists?).to eq(false)
end
end
describe "#perform_approve_and_restore" do
it "transitions to the approved state and restores the post" do
post.trash!
result = reviewable.reload.perform admin, :approve_and_restore
expect(result.transition_to).to eq :approved
expect(Post.where(id: post.id).exists?).to eq(true)
end
end
describe "#perform_approve_and_unhide" do
it "transitions to the approved state and unhides the post" do
post.update!(hidden: true)
result = reviewable.reload.perform admin, :approve_and_unhide
expect(result.transition_to).to eq :approved
expect(post.reload.hidden).to eq(false)
end
end
describe "#perform_reject_and_delete" do
it "transitions to the rejected state and deletes the post" do
result = reviewable.perform admin, :reject_and_delete
expect(result.transition_to).to eq :rejected
expect(Post.where(id: post.id).exists?).to eq(false)
end
end
end
end