diff --git a/README.md b/README.md index 0433edc..e07c58b 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,10 @@ By default, SimpleDiscussion will attempt to send email and slack notifications SimpleDiscussion.setup do |config| config.send_email_notifications = false # Default: true config.send_slack_notifications = false # Default: true + + config.markdown_circuit_embed = false # Default: false + config.markdown_user_tagging = false # Default: false + config.markdown_video_embed = false # Default false end ``` diff --git a/app/models/spam_report.rb b/app/models/spam_report.rb index 58b8acb..bc9b113 100644 --- a/app/models/spam_report.rb +++ b/app/models/spam_report.rb @@ -3,7 +3,7 @@ class SpamReport < ApplicationRecord belongs_to :user validates :forum_post_id, :user_id, :reason, presence: true - validates :details, presence: true, if: -> { reason == "other" } + validates :details, presence: true, if: -> { reason == "others" } enum reason: { sexual_content: 0, diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb index 0735bb1..a420c59 100644 --- a/test/dummy/app/models/user.rb +++ b/test/dummy/app/models/user.rb @@ -7,6 +7,6 @@ class User < ApplicationRecord :recoverable, :rememberable, :validatable def moderator? - true + moderator end end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 297acdf..4323c34 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -5,3 +5,8 @@ one: two: name: "Second User" email: "second@example.com" + +moderator: + name: "Moderator" + email: "moderator@moderator.com" + moderator: true diff --git a/test/integration/forum_test.rb b/test/integration/forum_test.rb index 882dabf..d2f9486 100644 --- a/test/integration/forum_test.rb +++ b/test/integration/forum_test.rb @@ -6,27 +6,34 @@ class ForumTest < ActionDispatch::IntegrationTest include SimpleDiscussion::Engine.routes.url_helpers setup do - sign_in users(:one) + @regular_user = users(:one) + @moderator_user = users(:moderator) + @forum_thread = forum_threads(:hello) + @forum_post = forum_posts(:one) @filter = LanguageFilter::Filter.new end test "threads index" do + sign_in @regular_user get "/" assert_response :success assert_match "Community", response.body end test "categories" do + sign_in @regular_user get forum_category_forum_threads_path(forum_categories(:general)) assert_response :success end test "show forum thread" do - get forum_thread_path(forum_threads(:hello)) + sign_in @regular_user + get forum_thread_path(@forum_thread) assert_response :success end test "create a forum thread" do + sign_in @regular_user assert_difference "ForumThread.count" do assert_difference "ForumPost.count" do post forum_threads_path, params: { @@ -45,8 +52,9 @@ class ForumTest < ActionDispatch::IntegrationTest end test "reply to a forum thread" do + sign_in @regular_user assert_difference "ForumPost.count" do - post forum_thread_forum_posts_path(forum_threads(:hello)), params: { + post forum_thread_forum_posts_path(@forum_thread), params: { forum_post: { body: "Reply" } @@ -57,6 +65,7 @@ class ForumTest < ActionDispatch::IntegrationTest end test "cannot create a forum thread with inappropriate language in title" do + sign_in @regular_user inappropriate_word = @filter.matchlist.to_a.sample assert_no_difference "ForumThread.count" do assert_no_difference "ForumPost.count" do @@ -77,6 +86,8 @@ class ForumTest < ActionDispatch::IntegrationTest end test "cannot create a forum thread with inappropriate language in body" do + sign_in @regular_user + inappropriate_word = @filter.matchlist.to_a.sample assert_no_difference "ForumThread.count" do assert_no_difference "ForumPost.count" do @@ -97,9 +108,11 @@ class ForumTest < ActionDispatch::IntegrationTest end test "cannot reply to a forum thread with inappropriate language" do + sign_in @regular_user + inappropriate_word = @filter.matchlist.to_a.sample assert_no_difference "ForumPost.count" do - post forum_thread_forum_posts_path(forum_threads(:hello)), params: { + post forum_thread_forum_posts_path(@forum_thread), params: { forum_post: { body: "contains inappropriate language: #{inappropriate_word}" } @@ -111,6 +124,8 @@ class ForumTest < ActionDispatch::IntegrationTest end test "can create a forum thread with appropriate language in title and body" do + sign_in @regular_user + assert_difference "ForumThread.count" do assert_difference "ForumPost.count" do post forum_threads_path, params: { @@ -127,4 +142,52 @@ class ForumTest < ActionDispatch::IntegrationTest assert_redirected_to forum_thread_path(ForumThread.last) end + + test "can report a post" do + sign_in @regular_user + + assert_difference "SpamReport.count" do + post report_post_forum_thread_forum_post_path(@forum_thread, @forum_post), params: { + reason: "irrelevant_content", + } + end + assert_redirected_to forum_thread_path(@forum_thread, anchor: dom_id(@forum_post)) + + spam_report = SpamReport.last + assert_equal @forum_post, spam_report.forum_post + assert_equal users(:one), spam_report.user + assert_equal "irrelevant_content", spam_report.reason + end + + test "can report a post with 'other' reason and details" do + sign_in @regular_user + + assert_difference "SpamReport.count" do + post report_post_forum_thread_forum_post_path(@forum_thread, @forum_post), params: { + reason: "others", + details: "This post contains copyrighted material." + } + end + + assert_redirected_to forum_thread_path(@forum_thread, anchor: dom_id(@forum_post)) + + spam_report = SpamReport.last + assert_equal "others", spam_report.reason + assert_equal "This post contains copyrighted material.", spam_report.details + end + + test "modeartor can view spam reports page" do + sign_in @moderator_user + + get spam_reports_forum_threads_path + assert_response :success + end + + test "regular user can't view spam reports page" do + sign_in @regular_user + + get spam_reports_forum_threads_path + assert_response :redirect + assert_redirected_to forum_threads_path + end end