Move diary comments hide/unhide actions to comments controller

This commit is contained in:
Anton Khorev 2024-06-17 18:10:32 +03:00
parent 1a5adb2a4a
commit a128b4f585
8 changed files with 104 additions and 97 deletions

View file

@ -12,6 +12,14 @@ class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
{ :path => "/user/username/diary/comments", :method => :get },
{ :controller => "diary_comments", :action => "index", :display_name => "username" }
)
assert_routing(
{ :path => "/user/username/diary/1/hidecomment/2", :method => :post },
{ :controller => "diary_comments", :action => "hide", :display_name => "username", :id => "1", :comment => "2" }
)
assert_routing(
{ :path => "/user/username/diary/1/unhidecomment/2", :method => :post },
{ :controller => "diary_comments", :action => "unhide", :display_name => "username", :id => "1", :comment => "2" }
)
get "/user/username/diary/comments/1"
assert_redirected_to "/user/username/diary/comments"
@ -60,4 +68,68 @@ class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to :controller => :errors, :action => :bad_request
end
end
def test_hide
user = create(:user)
diary_entry = create(:diary_entry, :user => user)
diary_comment = create(:diary_comment, :diary_entry => diary_entry)
# Try without logging in
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_response :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
session_for(user)
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :controller => :errors, :action => :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Try as a moderator
session_for(create(:moderator_user))
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to diary_entry_path(user, diary_entry)
assert_not DiaryComment.find(diary_comment.id).visible
# Reset
diary_comment.reload.update(:visible => true)
# Finally try as an administrator
session_for(create(:administrator_user))
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to diary_entry_path(user, diary_entry)
assert_not DiaryComment.find(diary_comment.id).visible
end
def test_unhide
user = create(:user)
diary_entry = create(:diary_entry, :user => user)
diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
# Try without logging in
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_response :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
session_for(user)
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :controller => :errors, :action => :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Now try as a moderator
session_for(create(:moderator_user))
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to diary_entry_path(user, diary_entry)
assert DiaryComment.find(diary_comment.id).visible
# Reset
diary_comment.reload.update(:visible => true)
# Finally try as an administrator
session_for(create(:administrator_user))
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to diary_entry_path(user, diary_entry)
assert DiaryComment.find(diary_comment.id).visible
end
end

View file

@ -81,14 +81,6 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
{ :path => "/user/username/diary/1/unhide", :method => :post },
{ :controller => "diary_entries", :action => "unhide", :display_name => "username", :id => "1" }
)
assert_routing(
{ :path => "/user/username/diary/1/hidecomment/2", :method => :post },
{ :controller => "diary_entries", :action => "hidecomment", :display_name => "username", :id => "1", :comment => "2" }
)
assert_routing(
{ :path => "/user/username/diary/1/unhidecomment/2", :method => :post },
{ :controller => "diary_entries", :action => "unhidecomment", :display_name => "username", :id => "1", :comment => "2" }
)
assert_routing(
{ :path => "/user/username/diary/1/subscribe", :method => :get },
{ :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
@ -828,70 +820,6 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
assert DiaryEntry.find(diary_entry.id).visible
end
def test_hidecomment
user = create(:user)
diary_entry = create(:diary_entry, :user => user)
diary_comment = create(:diary_comment, :diary_entry => diary_entry)
# Try without logging in
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_response :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
session_for(user)
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :controller => :errors, :action => :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Try as a moderator
session_for(create(:moderator_user))
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_not DiaryComment.find(diary_comment.id).visible
# Reset
diary_comment.reload.update(:visible => true)
# Finally try as an administrator
session_for(create(:administrator_user))
post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_not DiaryComment.find(diary_comment.id).visible
end
def test_unhidecomment
user = create(:user)
diary_entry = create(:diary_entry, :user => user)
diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
# Try without logging in
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_response :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
session_for(user)
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :controller => :errors, :action => :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Now try as a moderator
session_for(create(:moderator_user))
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert DiaryComment.find(diary_comment.id).visible
# Reset
diary_comment.reload.update(:visible => true)
# Finally try as an administrator
session_for(create(:administrator_user))
post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert DiaryComment.find(diary_comment.id).visible
end
def test_subscribe_page
user = create(:user)
other_user = create(:user)