Allows flagging comments as inappropriate

This commit is contained in:
kikito
2015-08-20 18:47:16 +02:00
parent e5f893c8d1
commit e7effbf77c
7 changed files with 68 additions and 2 deletions

View File

@@ -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

View File

@@ -37,6 +37,11 @@
</span>
<% end %>
&nbsp;&bullet;&nbsp;<%= 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? %>

View File

@@ -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 %>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>');

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>');

View File

@@ -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

View File

@@ -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