Add tests for moderation reports

Added an HTML render for the new endpoint to get the tests to work.
It should probably have had one anyways so this is alright.
This commit is contained in:
BrokenEagle
2020-01-18 22:45:13 +00:00
parent 491d476456
commit f3ce811def
3 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
require 'test_helper'
class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
context "The moderation reports controller" do
setup do
travel_to(2.weeks.ago) do
@user = create(:user)
@builder = create(:builder_user)
@mod = create(:moderator_user)
end
@user.as_current do
@comment = create(:comment)
end
end
context "new action" do
should "render the access denied page" do
get_auth new_moderation_report_path, @user
assert_response 403
assert_select "h1", /Access Denied/
end
should "render" do
get_auth new_moderation_report_path, @mod, params: {:moderation_report => {:model_id => @comment.id, :model_type => "Comment"}}
assert_response :success
end
end
context "index action" do
setup do
@builder.as_current do
create(:moderation_report, model: @comment)
end
end
should "render the access denied page" do
get_auth moderation_reports_path, @builder
assert_response 403
assert_select "h1", /Access Denied/
end
should "render" do
get_auth moderation_reports_path, @mod
assert_response :success
end
context "with search parameters" do
should "render" do
get_auth moderation_reports_path, @mod, params: {:search => {:model_id => @comment.id}}
assert_response :success
end
end
context "create action" do
should "create a new moderation report" do
assert_difference("ModerationReport.count", 1) do
assert_difference("ModerationReport.count") do
post_auth moderation_reports_path, @builder, params: {:format => "js", :moderation_report => {:model_id => @comment.id, :model_type => "Comment", :reason => "xxx"}}
end
end
end
end
end
end
end