From f3ce811defb7efca9dc577ed71bdd2753edbd3f1 Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Sat, 18 Jan 2020 22:45:13 +0000 Subject: [PATCH] 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. --- app/views/moderation_reports/new.html.erb | 5 ++ test/factories/moderation_report.rb | 5 ++ .../moderation_reports_controller_test.rb | 66 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 app/views/moderation_reports/new.html.erb create mode 100644 test/factories/moderation_report.rb create mode 100644 test/functional/moderation_reports_controller_test.rb diff --git a/app/views/moderation_reports/new.html.erb b/app/views/moderation_reports/new.html.erb new file mode 100644 index 000000000..70ebcbda7 --- /dev/null +++ b/app/views/moderation_reports/new.html.erb @@ -0,0 +1,5 @@ +
+
+ <%= render "moderation_reports/new", moderation_report: @moderation_report %> +
+
diff --git a/test/factories/moderation_report.rb b/test/factories/moderation_report.rb new file mode 100644 index 000000000..55cdbaa78 --- /dev/null +++ b/test/factories/moderation_report.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory(:moderation_report) do + reason {"xxx"} + end +end diff --git a/test/functional/moderation_reports_controller_test.rb b/test/functional/moderation_reports_controller_test.rb new file mode 100644 index 000000000..3d18bc445 --- /dev/null +++ b/test/functional/moderation_reports_controller_test.rb @@ -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