Allows flagging comments as inappropriate
This commit is contained in:
@@ -22,6 +22,16 @@ class CommentsController < ApplicationController
|
||||
respond_with @comment
|
||||
end
|
||||
|
||||
def flag_as_inappropiate
|
||||
InappropiateFlag.flag!(current_user, @comment)
|
||||
respond_with @comment
|
||||
end
|
||||
|
||||
def undo_flag_as_inappropiate
|
||||
InappropiateFlag.unflag!(current_user, @comment)
|
||||
respond_with @comment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def comment_params
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
</span>
|
||||
<% end %>
|
||||
• <%= time_ago_in_words(comment.created_at) %>
|
||||
|
||||
<span class="right js-flag-as-inappropiate-actions">
|
||||
<%= render 'comments/flag_as_inappropiate_actions', comment: comment %>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
||||
<% if comment.user.official? %>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<% if can? :flag_as_inappropiate, comment %>
|
||||
<%= link_to t('shared.flag_as_inappropiate'), flag_as_inappropiate_comment_path(comment), method: :put, remote: true %>
|
||||
<% end %>
|
||||
<% if can? :undo_flag_as_inappropiate, comment %>
|
||||
<%= link_to t('shared.undo_flag_as_inappropiate'), undo_flag_as_inappropiate_comment_path(comment), method: :put, remote: true %>
|
||||
<% end %>
|
||||
1
app/views/comments/flag_as_inappropiate.js.erb
Normal file
1
app/views/comments/flag_as_inappropiate.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>');
|
||||
1
app/views/comments/undo_flag_as_inappropiate.js.erb
Normal file
1
app/views/comments/undo_flag_as_inappropiate.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>');
|
||||
@@ -13,10 +13,18 @@ Rails.application.routes.draw do
|
||||
root 'welcome#index'
|
||||
|
||||
resources :debates do
|
||||
member { post :vote }
|
||||
member do
|
||||
post :vote
|
||||
put :flag_as_inappropiate
|
||||
put :undo_flag_as_inappropiate
|
||||
end
|
||||
|
||||
resources :comments, only: :create, shallow: true do
|
||||
member { post :vote }
|
||||
member do
|
||||
post :vote
|
||||
put :flag_as_inappropiate
|
||||
put :undo_flag_as_inappropiate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -133,4 +133,39 @@ feature 'Comments' do
|
||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
||||
end
|
||||
|
||||
scenario "Flagging as inappropiate", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate)
|
||||
|
||||
login_as(user)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to_not have_link "Undo flag as inappropiate"
|
||||
click_on 'Flag as inappropiate'
|
||||
expect(page).to have_link "Undo flag as inappropiate"
|
||||
end
|
||||
|
||||
expect(InappropiateFlag.flagged?(user, comment)).to be
|
||||
end
|
||||
|
||||
scenario "Undoing flagging as inappropiate", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate)
|
||||
InappropiateFlag.flag!(user, comment)
|
||||
|
||||
login_as(user)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to_not have_link("Flag as inappropiate", exact: true)
|
||||
click_on 'Undo flag as inappropiate'
|
||||
expect(page).to have_link("Flag as inappropiate", exact: true)
|
||||
end
|
||||
|
||||
expect(InappropiateFlag.flagged?(user, comment)).to_not be
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user