posts: rework post events page.
* Add a global /post_events page that shows the history of all approvals, disapprovals, flags, appeals, and replacements on a single page. * Redesign the /posts/:id/events page to show all approval, disapproval, flag, appeal, and replacement events for a single post (before it only showed approvals, flags, and appeals). * Remove the replacement history link from the post show page. Replacements are now included in the post events page (closes #4948: Highlighed replacements). * Add /post_approvals/:id and /post_replacements/:id routes (these are used by the "Details" link on the post events page).
This commit is contained in:
@@ -80,5 +80,23 @@ class PostApprovalsControllerTest < ActionDispatch::IntegrationTest
|
||||
should respond_to_search(post: {uploader_name: "komachi"}).with { @post_approval }
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
@approval = create(:post_approval)
|
||||
end
|
||||
|
||||
should "render for html" do
|
||||
get post_approval_path(@approval)
|
||||
|
||||
assert_redirected_to post_approvals_path(search: { id: @approval.id })
|
||||
end
|
||||
|
||||
should "render for json" do
|
||||
get post_approval_path(@approval), as: :json
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,42 +1,78 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostEventsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
travel_to(2.weeks.ago) do
|
||||
@user = create(:user)
|
||||
@mod = create(:mod_user)
|
||||
end
|
||||
context "The post approvals controller" do
|
||||
context "index action" do
|
||||
setup do
|
||||
@user = create(:user)
|
||||
@post = create(:post, uploader: @user, is_pending: true)
|
||||
|
||||
as(@user) do
|
||||
@post = create(:post, is_flagged: true)
|
||||
create(:post_flag, post: @post, status: :rejected)
|
||||
@post.update(is_deleted: true)
|
||||
create(:post_appeal, post: @post, status: :succeeded)
|
||||
create(:post_approval, post: @post, user: @mod)
|
||||
end
|
||||
end
|
||||
@approval = create(:post_approval, post: @post)
|
||||
@flag = create(:post_flag, post: @post, creator: @user, is_deletion: true)
|
||||
@post.update!(is_deleted: true)
|
||||
@appeal = create(:post_appeal, post: @post, creator: @user)
|
||||
@disapproval = create(:post_disapproval, post: @post, user: @user)
|
||||
@replacement = create(:post_replacement, post: @post, creator: @user)
|
||||
end
|
||||
|
||||
context "get /posts/:post_id/events" do
|
||||
should "render" do
|
||||
get_auth post_events_path(post_id: @post.id), @user
|
||||
assert_response :ok
|
||||
end
|
||||
should "render for a global listing" do
|
||||
get post_events_path
|
||||
|
||||
should "render for mods" do
|
||||
get_auth post_events_path(post_id: @post.id), @mod
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "get /posts/:post_id/events.xml" do
|
||||
setup do
|
||||
get_auth post_events_path(post_id: @post.id), @user, params: {:format => "xml"}
|
||||
@xml = Hash.from_xml(response.body)
|
||||
@appeal = @xml["post_events"].find { |e| e["type"] == "a" }
|
||||
end
|
||||
should "render for a single post listing" do
|
||||
get post_post_events_path(@post.id)
|
||||
|
||||
should "render" do
|
||||
assert_not_nil(@appeal)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render for a json response" do
|
||||
get post_events_path, as: :json
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "for a moderator" do
|
||||
should "render" do
|
||||
get_auth post_events_path, create(:mod_user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "allow searching flags by creator" do
|
||||
get_auth post_events_path(search: { creator_name: @user.name }), create(:mod_user), as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(5, response.parsed_body.size)
|
||||
assert_equal(@flag.creator_id, response.parsed_body.find { |event| event["model_type"] == "PostFlag" }["creator_id"])
|
||||
assert_equal(@disapproval.user_id, response.parsed_body.find { |event| event["model_type"] == "PostDisapproval" }["creator_id"])
|
||||
end
|
||||
|
||||
should "include the creator_id in the API" do
|
||||
get_auth post_events_path, create(:mod_user), as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(@flag.creator_id, response.parsed_body.find { |event| event["model_type"] == "PostFlag" }["creator_id"])
|
||||
end
|
||||
end
|
||||
|
||||
context "for a non-moderator" do
|
||||
should "not allow searching flags by creator" do
|
||||
get post_events_path(search: { creator_name: @user.name }), as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_equal(3, response.parsed_body.size)
|
||||
assert_nil(response.parsed_body.find { |event| event["model_type"] == "PostFlag" })
|
||||
assert_nil(response.parsed_body.find { |event| event["model_type"] == "PostDisapproval" })
|
||||
end
|
||||
|
||||
should "not include the creator_id in the API" do
|
||||
get post_events_path, as: :json
|
||||
|
||||
assert_response :success
|
||||
assert_nil(response.parsed_body.find { |event| event["model_type"] == "PostFlag" }["creator_id"])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,5 +224,23 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
|
||||
should respond_to_search(creator_name: "yukari").with { @post_replacement }
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
@replacement = create(:post_replacement)
|
||||
end
|
||||
|
||||
should "render for html" do
|
||||
get post_replacement_path(@replacement)
|
||||
|
||||
assert_redirected_to post_replacements_path(search: { id: @replacement.id })
|
||||
end
|
||||
|
||||
should "render for json" do
|
||||
get post_replacement_path(@replacement), as: :json
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user