Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Waishnav committed Aug 14, 2024
1 parent 87266fd commit f1d2ba5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion app/models/spam_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class User < ApplicationRecord
:recoverable, :rememberable, :validatable

def moderator?
true
moderator
end
end
5 changes: 5 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ one:
two:
name: "Second User"
email: "[email protected]"

moderator:
name: "Moderator"
email: "[email protected]"
moderator: true
71 changes: 67 additions & 4 deletions test/integration/forum_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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"
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}"
}
Expand All @@ -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: {
Expand All @@ -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

0 comments on commit f1d2ba5

Please sign in to comment.