Allows flagging debates as inappropriate
This commit is contained in:
@@ -51,6 +51,16 @@ class DebatesController < ApplicationController
|
||||
set_debate_votes(@debate)
|
||||
end
|
||||
|
||||
def flag_as_inappropiate
|
||||
InappropiateFlag.flag!(current_user, @debate)
|
||||
respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions'
|
||||
end
|
||||
|
||||
def undo_flag_as_inappropiate
|
||||
InappropiateFlag.unflag!(current_user, @debate)
|
||||
respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def debate_params
|
||||
|
||||
6
app/views/debates/_flag_as_inappropiate_actions.html.erb
Normal file
6
app/views/debates/_flag_as_inappropiate_actions.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<% if can? :flag_as_inappropiate, debate %>
|
||||
<%= link_to t('shared.flag_as_inappropiate'), flag_as_inappropiate_debate_path(debate), method: :put, remote: true %>
|
||||
<% end %>
|
||||
<% if can? :undo_flag_as_inappropiate, debate %>
|
||||
<%= link_to t('shared.undo_flag_as_inappropiate'), undo_flag_as_inappropiate_debate_path(debate), method: :put, remote: true %>
|
||||
<% end %>
|
||||
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@debate) %> .js-flag-as-inappropiate-actions").html('<%= j render("debates/flag_as_inappropiate_actions", debate: @debate) %>');
|
||||
@@ -41,6 +41,10 @@
|
||||
<span class="bullet"> • </span>
|
||||
<i class="icon-chat-bubble-two"></i>
|
||||
<%= link_to t("debates.show.comments", count: @debate.comment_threads.count), "#comments" %>
|
||||
|
||||
<span class='right js-flag-as-inappropiate-actions'>
|
||||
<%= render 'debates/flag_as_inappropiate_actions', debate: @debate %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<%= @debate.description %>
|
||||
|
||||
@@ -315,4 +315,37 @@ feature 'Debates' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Flagging as inappropiate", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
|
||||
login_as(user)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#debate_#{debate.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, debate)).to be
|
||||
end
|
||||
|
||||
scenario "Undoing flagging as inappropiate", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
InappropiateFlag.flag!(user, debate)
|
||||
|
||||
login_as(user)
|
||||
visit debate_path(debate)
|
||||
|
||||
within "#debate_#{debate.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, debate)).to_not be
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user