Fix #4278: Certain users are unable to use the report function.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class ModerationReportsController < ApplicationController
|
class ModerationReportsController < ApplicationController
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
before_action :builder_only, only: [:new, :create]
|
before_action :member_only, only: [:new, :create]
|
||||||
before_action :moderator_only, only: [:index]
|
before_action :moderator_only, only: [:index]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -3,37 +3,35 @@ require 'test_helper'
|
|||||||
class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
|
class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
|
||||||
context "The moderation reports controller" do
|
context "The moderation reports controller" do
|
||||||
setup do
|
setup do
|
||||||
travel_to(2.weeks.ago) do
|
@user = create(:user, created_at: 2.weeks.ago)
|
||||||
@user = create(:user)
|
@spammer = create(:user, created_at: 2.weeks.ago)
|
||||||
@builder = create(:builder_user)
|
@mod = create(:moderator_user, created_at: 2.weeks.ago)
|
||||||
@mod = create(:moderator_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
@user.as_current do
|
@spammer.as_current do
|
||||||
@comment = create(:comment, creator: @user)
|
@comment = create(:comment, creator: @spammer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "new action" do
|
context "new action" do
|
||||||
should "render the access denied page" do
|
should "render the access denied page" do
|
||||||
get_auth new_moderation_report_path, @user
|
get_auth new_moderation_report_path, User.anonymous
|
||||||
assert_response 403
|
assert_response 403
|
||||||
assert_select "h1", /Access Denied/
|
assert_select "h1", /Access Denied/
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render" do
|
should "render" do
|
||||||
get_auth new_moderation_report_path, @mod, params: {:moderation_report => {:model_id => @comment.id, :model_type => "Comment"}}
|
get_auth new_moderation_report_path, @user, params: {:moderation_report => {:model_id => @comment.id, :model_type => "Comment"}}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "index action" do
|
context "index action" do
|
||||||
setup do
|
setup do
|
||||||
create(:moderation_report, model: @comment, creator: @builder)
|
create(:moderation_report, model: @comment, creator: @user)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the access denied page" do
|
should "render the access denied page" do
|
||||||
get_auth moderation_reports_path, @builder
|
get_auth moderation_reports_path, @user
|
||||||
assert_response 403
|
assert_response 403
|
||||||
assert_select "h1", /Access Denied/
|
assert_select "h1", /Access Denied/
|
||||||
end
|
end
|
||||||
@@ -49,14 +47,13 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "create action" do
|
context "create action" do
|
||||||
should "create a new moderation report" do
|
should "create a new moderation report" do
|
||||||
assert_difference("ModerationReport.count", 1) do
|
assert_difference("ModerationReport.count", 1) do
|
||||||
assert_difference("ModerationReport.count") do
|
post_auth moderation_reports_path, @user, params: {:format => "js", :moderation_report => {:model_id => @comment.id, :model_type => "Comment", :reason => "xxx"}}
|
||||||
post_auth moderation_reports_path, @builder, params: {:format => "js", :moderation_report => {:model_id => @comment.id, :model_type => "Comment", :reason => "xxx"}}
|
assert_response :success
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user