Several renamings
InappropiateFlag -> Flag x.flag_as_inappropiate -> x.flag x.undo_flag_as_inappropiate -> x.unflag X.flagged_as_inappropiate -> x.flagged flag-as-inappropiate-actions views & css -> flag-actions views & css
This commit is contained in:
@@ -22,14 +22,14 @@ class CommentsController < ApplicationController
|
||||
respond_with @comment
|
||||
end
|
||||
|
||||
def flag_as_inappropiate
|
||||
InappropiateFlag.flag!(current_user, @comment)
|
||||
respond_with @comment, template: 'comments/_refresh_flag_as_inappropiate_actions'
|
||||
def flag
|
||||
Flag.flag!(current_user, @comment)
|
||||
respond_with @comment, template: 'comments/_refresh_flag_actions'
|
||||
end
|
||||
|
||||
def undo_flag_as_inappropiate
|
||||
InappropiateFlag.unflag!(current_user, @comment)
|
||||
respond_with @comment, template: 'comments/_refresh_flag_as_inappropiate_actions'
|
||||
def unflag
|
||||
Flag.unflag!(current_user, @comment)
|
||||
respond_with @comment, template: 'comments/_refresh_flag_actions'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -51,14 +51,14 @@ 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'
|
||||
def flag
|
||||
Flag.flag!(current_user, @debate)
|
||||
respond_with @debate, template: 'debates/_refresh_flag_actions'
|
||||
end
|
||||
|
||||
def undo_flag_as_inappropiate
|
||||
InappropiateFlag.unflag!(current_user, @debate)
|
||||
respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions'
|
||||
def unflag
|
||||
Flag.unflag!(current_user, @debate)
|
||||
respond_with @debate, template: 'debates/_refresh_flag_actions'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -27,7 +27,7 @@ class Moderation::CommentsController < Moderation::BaseController
|
||||
private
|
||||
|
||||
def load_comments
|
||||
@comments = Comment.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation.includes(:commentable)
|
||||
@comments = Comment.accessible_by(current_ability, :hide).flagged.sorted_for_moderation.includes(:commentable)
|
||||
end
|
||||
|
||||
def set_valid_filters
|
||||
|
||||
@@ -27,7 +27,7 @@ class Moderation::DebatesController < Moderation::BaseController
|
||||
private
|
||||
|
||||
def load_debates
|
||||
@debates = Debate.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation
|
||||
@debates = Debate.accessible_by(current_ability, :hide).flagged.sorted_for_moderation
|
||||
end
|
||||
|
||||
def set_valid_filters
|
||||
|
||||
@@ -22,20 +22,20 @@ class Ability
|
||||
can :create, Comment
|
||||
can :create, Debate
|
||||
|
||||
can :flag_as_inappropiate, Comment do |comment|
|
||||
comment.author_id != user.id && !InappropiateFlag.flagged?(user, comment)
|
||||
can :flag, Comment do |comment|
|
||||
comment.author_id != user.id && !Flag.flagged?(user, comment)
|
||||
end
|
||||
|
||||
can :undo_flag_as_inappropiate, Comment do |comment|
|
||||
comment.author_id != user.id && InappropiateFlag.flagged?(user, comment)
|
||||
can :unflag, Comment do |comment|
|
||||
comment.author_id != user.id && Flag.flagged?(user, comment)
|
||||
end
|
||||
|
||||
can :flag_as_inappropiate, Debate do |debate|
|
||||
debate.author_id != user.id && !InappropiateFlag.flagged?(user, debate)
|
||||
can :flag, Debate do |debate|
|
||||
debate.author_id != user.id && !Flag.flagged?(user, debate)
|
||||
end
|
||||
|
||||
can :undo_flag_as_inappropiate, Debate do |debate|
|
||||
debate.author_id != user.id && InappropiateFlag.flagged?(user, debate)
|
||||
can :unflag, Debate do |debate|
|
||||
debate.author_id != user.id && Flag.flagged?(user, debate)
|
||||
end
|
||||
|
||||
unless user.organization?
|
||||
|
||||
@@ -12,14 +12,14 @@ class Comment < ActiveRecord::Base
|
||||
belongs_to :commentable, polymorphic: true, counter_cache: true
|
||||
belongs_to :user, -> { with_hidden }
|
||||
|
||||
has_many :inappropiate_flags, :as => :flaggable
|
||||
has_many :flags, :as => :flaggable
|
||||
|
||||
scope :recent, -> { order(id: :desc) }
|
||||
|
||||
scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) }
|
||||
scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :pending, -> { where(archived_at: nil, hidden_at: nil) }
|
||||
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
|
||||
scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
|
||||
scope :flagged, -> { where("flags_count > 0") }
|
||||
|
||||
scope :for_render, -> { with_hidden.includes(user: :organization) }
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Debate < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
has_many :inappropiate_flags, :as => :flaggable
|
||||
has_many :flags, :as => :flaggable
|
||||
|
||||
validates :title, presence: true
|
||||
validates :description, presence: true
|
||||
@@ -23,10 +23,10 @@ class Debate < ActiveRecord::Base
|
||||
before_validation :sanitize_description
|
||||
before_validation :sanitize_tag_list
|
||||
|
||||
scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) }
|
||||
scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :pending, -> { where(archived_at: nil, hidden_at: nil) }
|
||||
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
|
||||
scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
|
||||
scope :flagged, -> { where("flags_count > 0") }
|
||||
scope :for_render, -> { includes(:tags) }
|
||||
|
||||
# Ahoy setup
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class InappropiateFlag < ActiveRecord::Base
|
||||
class Flag < ActiveRecord::Base
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :flaggable, polymorphic: true, counter_cache: true, touch: :flagged_as_inappropiate_at
|
||||
belongs_to :flaggable, polymorphic: true, counter_cache: true
|
||||
|
||||
scope(:by_user_and_flaggable, lambda do |user, flaggable|
|
||||
where(user_id: user.id,
|
||||
@@ -12,13 +12,13 @@ class InappropiateFlag < ActiveRecord::Base
|
||||
|
||||
class AlreadyFlaggedError < StandardError
|
||||
def initialize
|
||||
super "The flaggable was already flagged as inappropiate by this user"
|
||||
super "The flaggable was already flagged by this user"
|
||||
end
|
||||
end
|
||||
|
||||
class NotFlaggedError < StandardError
|
||||
def initialize
|
||||
super "The flaggable was not flagged as inappropiate by this user"
|
||||
super "The flaggable was not flagged by this user"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ class User < ActiveRecord::Base
|
||||
has_one :administrator
|
||||
has_one :moderator
|
||||
has_one :organization
|
||||
has_many :inappropiate_flags
|
||||
has_many :flags
|
||||
has_many :identities, dependent: :destroy
|
||||
|
||||
validates :username, presence: true, unless: :organization?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<span class="js-flag-as-inappropiate-actions">
|
||||
<%= render 'comments/flag_as_inappropiate_actions', comment: comment %>
|
||||
<span class="js-flag-actions">
|
||||
<%= render 'comments/flag_actions', comment: comment %>
|
||||
</span>
|
||||
|
||||
<span class='js-moderation-actions'>
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
<% if can? :flag_as_inappropiate, comment %>
|
||||
<% if can? :flag, comment %>
|
||||
<span class="divider"> | </span>
|
||||
<a id="flag-expand-comment-<%= comment.id %>" data-dropdown="flag-drop-comment-<%= comment.id %>" aria-controls="flag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.flag_as_inappropiate') %>">
|
||||
<a id="flag-expand-comment-<%= comment.id %>" data-dropdown="flag-drop-comment-<%= comment.id %>" aria-controls="flag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.flag') %>">
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
</a>
|
||||
<ul id="flag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t("shared.flag_as_inappropiate"), flag_as_inappropiate_comment_path(comment), method: :put, remote: true, id: "flag-comment-#{comment.id}" %>
|
||||
<%= link_to t("shared.flag"), flag_comment_path(comment), method: :put, remote: true, id: "flag-comment-#{comment.id}" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if can? :undo_flag_as_inappropiate, comment %>
|
||||
<% if can? :unflag, comment %>
|
||||
<span class="divider"> | </span>
|
||||
<a id="unflag-expand-comment-<%= comment.id %>" data-dropdown="unflag-drop-comment-<%= comment.id %>" aria-controls="unflag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.undo_flag_as_inappropiate') %>">
|
||||
<a id="unflag-expand-comment-<%= comment.id %>" data-dropdown="unflag-drop-comment-<%= comment.id %>" aria-controls="unflag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.unflag') %>">
|
||||
<i class="icon-flag flag-active"></i>
|
||||
</a>
|
||||
<ul id="unflag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t("shared.undo_flag_as_inappropiate"), undo_flag_as_inappropiate_comment_path(comment), method: :put, remote: true, id: "unflag-comment-#{comment.id}" %>
|
||||
<%= link_to t("shared.unflag"), unflag_comment_path(comment), method: :put, remote: true, id: "unflag-comment-#{comment.id}" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
1
app/views/comments/_refresh_flag_actions.js.erb
Normal file
1
app/views/comments/_refresh_flag_actions.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@comment) %> .js-flag-actions").html('<%= j render("comments/flag_actions", comment: @comment) %>');
|
||||
@@ -1 +0,0 @@
|
||||
$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>');
|
||||
@@ -1,21 +1,21 @@
|
||||
<% if can? :flag_as_inappropiate, debate %>
|
||||
<a id="flag-expand-debate-<%= debate.id %>" data-dropdown="flag-drop-debate-<%= debate.id %>" aria-controls="flag-drop-debate-<%= debate.id %>" aria-expanded="false" title="<%= t('shared.flag_as_inappropiate') %>">
|
||||
<% if can? :flag, debate %>
|
||||
<a id="flag-expand-debate-<%= debate.id %>" data-dropdown="flag-drop-debate-<%= debate.id %>" aria-controls="flag-drop-debate-<%= debate.id %>" aria-expanded="false" title="<%= t('shared.flag') %>">
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
</a>
|
||||
<ul id="flag-drop-debate-<%= debate.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t('shared.flag_as_inappropiate'), flag_as_inappropiate_debate_path(debate), method: :put, remote: true, id: "flag-debate-#{ debate.id }" %>
|
||||
<%= link_to t('shared.flag'), flag_debate_path(debate), method: :put, remote: true, id: "flag-debate-#{ debate.id }" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if can? :undo_flag_as_inappropiate, debate %>
|
||||
<a id="unflag-expand-debate-<%= debate.id %>" data-dropdown="unflag-drop-debate-<%= debate.id %>" aria-controls="unflag-drop-debate-<%= debate.id %>" aria-expanded="false" title="<%= t('shared.undo_flag_as_inappropiate') %>">
|
||||
<% if can? :unflag, debate %>
|
||||
<a id="unflag-expand-debate-<%= debate.id %>" data-dropdown="unflag-drop-debate-<%= debate.id %>" aria-controls="unflag-drop-debate-<%= debate.id %>" aria-expanded="false" title="<%= t('shared.unflag') %>">
|
||||
<i class="icon-flag flag-active"></i>
|
||||
</a>
|
||||
<ul id="unflag-drop-debate-<%= debate.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t('shared.undo_flag_as_inappropiate'), undo_flag_as_inappropiate_debate_path(debate), method: :put, remote: true, id: "unflag-debate-#{ debate.id }" %>
|
||||
<%= link_to t('shared.unflag'), unflag_debate_path(debate), method: :put, remote: true, id: "unflag-debate-#{ debate.id }" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
1
app/views/debates/_refresh_flag_actions.js.erb
Normal file
1
app/views/debates/_refresh_flag_actions.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@debate) %> .js-flag-actions").html('<%= j render("debates/flag_actions", debate: @debate) %>');
|
||||
@@ -1 +0,0 @@
|
||||
$("#<%= dom_id(@debate) %> .js-flag-as-inappropiate-actions").html('<%= j render("debates/flag_as_inappropiate_actions", debate: @debate) %>');
|
||||
@@ -42,8 +42,8 @@
|
||||
<i class="icon-comments"></i>
|
||||
<%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>
|
||||
<span class="bullet"> • </span>
|
||||
<span class="js-flag-as-inappropiate-actions">
|
||||
<%= render 'debates/flag_as_inappropiate_actions', debate: @debate %>
|
||||
<span class="js-flag-actions">
|
||||
<%= render 'debates/flag_actions', debate: @debate %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<span class="date"><%= l comment.updated_at.to_date %></span>
|
||||
</td>
|
||||
<td><%= comment.body %></td>
|
||||
<td class="text-center"><%= comment.inappropiate_flags_count %></td>
|
||||
<td class="text-center"><%= comment.flags_count %></td>
|
||||
<td>
|
||||
<%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %>
|
||||
</td>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<br>
|
||||
<%= debate.description %>
|
||||
</td>
|
||||
<td class="text-center"><%= debate.inappropiate_flags_count %></td>
|
||||
<td class="text-center"><%= debate.flags_count %></td>
|
||||
<td>
|
||||
<%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %>
|
||||
</td>
|
||||
|
||||
@@ -133,8 +133,8 @@ en:
|
||||
shared:
|
||||
tags_cloud:
|
||||
tags: Topics
|
||||
flag_as_inappropiate: Flag as inappropriate
|
||||
undo_flag_as_inappropiate: Undo flag
|
||||
flag: Flag as inappropriate
|
||||
unflag: Undo flag
|
||||
collective: Collective
|
||||
mailer:
|
||||
comment:
|
||||
|
||||
@@ -133,8 +133,8 @@ es:
|
||||
shared:
|
||||
tags_cloud:
|
||||
tags: Temas
|
||||
flag_as_inappropiate: Denunciar como inapropiado
|
||||
undo_flag_as_inappropiate: Deshacer denuncia
|
||||
flag: Denunciar como inapropiado
|
||||
unflag: Deshacer denuncia
|
||||
collective: Colectivo
|
||||
mailer:
|
||||
comment:
|
||||
|
||||
@@ -28,15 +28,15 @@ Rails.application.routes.draw do
|
||||
resources :debates do
|
||||
member do
|
||||
post :vote
|
||||
put :flag_as_inappropiate
|
||||
put :undo_flag_as_inappropiate
|
||||
put :flag
|
||||
put :unflag
|
||||
end
|
||||
|
||||
resources :comments, only: :create, shallow: true do
|
||||
member do
|
||||
post :vote
|
||||
put :flag_as_inappropiate
|
||||
put :undo_flag_as_inappropiate
|
||||
put :flag
|
||||
put :unflag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,9 +26,9 @@ FactoryGirl.define do
|
||||
archived_at Time.now
|
||||
end
|
||||
|
||||
trait :flagged_as_inappropiate do
|
||||
trait :flagged do
|
||||
after :create do |debate|
|
||||
InappropiateFlag.flag!(FactoryGirl.create(:user), debate)
|
||||
Flag.flag!(FactoryGirl.create(:user), debate)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -55,9 +55,9 @@ FactoryGirl.define do
|
||||
archived_at Time.now
|
||||
end
|
||||
|
||||
trait :flagged_as_inappropiate do
|
||||
trait :flagged do
|
||||
after :create do |debate|
|
||||
InappropiateFlag.flag!(FactoryGirl.create(:user), debate)
|
||||
Flag.flag!(FactoryGirl.create(:user), debate)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,14 +148,14 @@ feature 'Comments' do
|
||||
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
|
||||
end
|
||||
|
||||
expect(InappropiateFlag.flagged?(user, comment)).to be
|
||||
expect(Flag.flagged?(user, comment)).to be
|
||||
end
|
||||
|
||||
scenario "Undoing flagging as inappropriate", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
comment = create(:comment, commentable: debate)
|
||||
InappropiateFlag.flag!(user, comment)
|
||||
Flag.flag!(user, comment)
|
||||
|
||||
login_as(user)
|
||||
visit debate_path(debate)
|
||||
@@ -167,7 +167,7 @@ feature 'Comments' do
|
||||
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
|
||||
end
|
||||
|
||||
expect(InappropiateFlag.flagged?(user, comment)).to_not be
|
||||
expect(Flag.flagged?(user, comment)).to_not be
|
||||
end
|
||||
|
||||
feature "Moderators" do
|
||||
|
||||
@@ -315,7 +315,7 @@ feature 'Debates' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Flagging as inappropiate", :js do
|
||||
scenario "Flagging", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
|
||||
@@ -329,13 +329,13 @@ feature 'Debates' do
|
||||
expect(page).to have_css("#unflag-expand-debate-#{debate.id}")
|
||||
end
|
||||
|
||||
expect(InappropiateFlag.flagged?(user, debate)).to be
|
||||
expect(Flag.flagged?(user, debate)).to be
|
||||
end
|
||||
|
||||
scenario "Undoing flagging as inappropiate", :js do
|
||||
scenario "Unflagging", :js do
|
||||
user = create(:user)
|
||||
debate = create(:debate)
|
||||
InappropiateFlag.flag!(user, debate)
|
||||
Flag.flag!(user, debate)
|
||||
|
||||
login_as(user)
|
||||
visit debate_path(debate)
|
||||
@@ -347,7 +347,7 @@ feature 'Debates' do
|
||||
expect(page).to have_css("#flag-expand-debate-#{debate.id}")
|
||||
end
|
||||
|
||||
expect(InappropiateFlag.flagged?(user, debate)).to_not be
|
||||
expect(Flag.flagged?(user, debate)).to_not be
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -123,9 +123,9 @@ feature 'Moderate Comments' do
|
||||
end
|
||||
|
||||
scenario "Filtering comments" do
|
||||
create(:comment, :flagged_as_inappropiate, body: "Pending comment")
|
||||
create(:comment, :flagged_as_inappropiate, :hidden, body: "Hidden comment")
|
||||
create(:comment, :flagged_as_inappropiate, :archived, body: "Archived comment")
|
||||
create(:comment, :flagged, body: "Pending comment")
|
||||
create(:comment, :flagged, :hidden, body: "Hidden comment")
|
||||
create(:comment, :flagged, :archived, body: "Archived comment")
|
||||
|
||||
visit moderation_comments_path(filter: 'all')
|
||||
expect(page).to have_content('Pending comment')
|
||||
@@ -145,7 +145,7 @@ feature 'Moderate Comments' do
|
||||
|
||||
scenario "Reviewing links remember the pagination setting and the filter" do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times { create(:comment, :flagged_as_inappropiate) }
|
||||
(per_page + 2).times { create(:comment, :flagged) }
|
||||
|
||||
visit moderation_comments_path(filter: 'pending', page: 2)
|
||||
|
||||
@@ -162,7 +162,7 @@ feature 'Moderate Comments' do
|
||||
|
||||
background do
|
||||
debate = create(:debate, title: 'Democracy')
|
||||
@comment = create(:comment, :flagged_as_inappropiate, commentable: debate, body: 'spammy spam')
|
||||
@comment = create(:comment, :flagged, commentable: debate, body: 'spammy spam')
|
||||
visit moderation_comments_path
|
||||
end
|
||||
|
||||
|
||||
@@ -66,9 +66,9 @@ feature 'Moderate debates' do
|
||||
end
|
||||
|
||||
scenario "Filtering debates" do
|
||||
create(:debate, :flagged_as_inappropiate, title: "Pending debate")
|
||||
create(:debate, :flagged_as_inappropiate, :hidden, title: "Hidden debate")
|
||||
create(:debate, :flagged_as_inappropiate, :archived, title: "Archived debate")
|
||||
create(:debate, :flagged, title: "Pending debate")
|
||||
create(:debate, :flagged, :hidden, title: "Hidden debate")
|
||||
create(:debate, :flagged, :archived, title: "Archived debate")
|
||||
|
||||
visit moderation_debates_path(filter: 'all')
|
||||
expect(page).to have_content('Pending debate')
|
||||
@@ -88,7 +88,7 @@ feature 'Moderate debates' do
|
||||
|
||||
scenario "Reviewing links remember the pagination setting and the filter" do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times { create(:debate, :flagged_as_inappropiate) }
|
||||
(per_page + 2).times { create(:debate, :flagged) }
|
||||
|
||||
visit moderation_debates_path(filter: 'pending', page: 2)
|
||||
|
||||
@@ -104,7 +104,7 @@ feature 'Moderate debates' do
|
||||
feature 'A flagged debate exists' do
|
||||
|
||||
background do
|
||||
@debate = create(:debate, :flagged_as_inappropiate, title: 'spammy spam', description: 'buy buy buy')
|
||||
@debate = create(:debate, :flagged, title: 'spammy spam', description: 'buy buy buy')
|
||||
visit moderation_debates_path
|
||||
end
|
||||
|
||||
|
||||
@@ -31,38 +31,38 @@ describe Ability do
|
||||
it { should_not be_able_to(:comment_as_administrator, debate) }
|
||||
it { should_not be_able_to(:comment_as_moderator, debate) }
|
||||
|
||||
describe 'flagging content as inappropiate' do
|
||||
it { should be_able_to(:flag_as_inappropiate, debate) }
|
||||
it { should_not be_able_to(:undo_flag_as_inappropiate, debate) }
|
||||
it { should be_able_to(:flag_as_inappropiate, comment) }
|
||||
it { should_not be_able_to(:undo_flag_as_inappropiate, comment) }
|
||||
describe 'flagging content' do
|
||||
it { should be_able_to(:flag, debate) }
|
||||
it { should_not be_able_to(:unflag, debate) }
|
||||
it { should be_able_to(:flag, comment) }
|
||||
it { should_not be_able_to(:unflag, comment) }
|
||||
|
||||
describe "own comments" do
|
||||
let(:own_comment) { create(:comment, author: user) }
|
||||
|
||||
it { should_not be_able_to(:flag_as_inappropiate, own_comment) }
|
||||
it { should_not be_able_to(:undo_flag_as_inappropiate, own_comment) }
|
||||
it { should_not be_able_to(:flag, own_comment) }
|
||||
it { should_not be_able_to(:unflag, own_comment) }
|
||||
end
|
||||
|
||||
describe "own debates" do
|
||||
let(:own_debate) { create(:debate, author: user) }
|
||||
|
||||
it { should_not be_able_to(:flag_as_inappropiate, own_debate) }
|
||||
it { should_not be_able_to(:undo_flag_as_inappropiate, own_debate) }
|
||||
it { should_not be_able_to(:flag, own_debate) }
|
||||
it { should_not be_able_to(:unflag, own_debate) }
|
||||
end
|
||||
|
||||
describe "already-flagged comments" do
|
||||
before(:each) { InappropiateFlag.flag!(user, comment) }
|
||||
before(:each) { Flag.flag!(user, comment) }
|
||||
|
||||
it { should_not be_able_to(:flag_as_inappropiate, comment) }
|
||||
it { should be_able_to(:undo_flag_as_inappropiate, comment) }
|
||||
it { should_not be_able_to(:flag, comment) }
|
||||
it { should be_able_to(:unflag, comment) }
|
||||
end
|
||||
|
||||
describe "already-flagged debates" do
|
||||
before(:each) { InappropiateFlag.flag!(user, debate) }
|
||||
before(:each) { Flag.flag!(user, debate) }
|
||||
|
||||
it { should_not be_able_to(:flag_as_inappropiate, debate) }
|
||||
it { should be_able_to(:undo_flag_as_inappropiate, debate) }
|
||||
it { should_not be_able_to(:flag, debate) }
|
||||
it { should be_able_to(:unflag, debate) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe InappropiateFlag do
|
||||
describe Flag do
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:comment) { create(:comment) }
|
||||
@@ -8,43 +8,35 @@ describe InappropiateFlag do
|
||||
describe '.flag!' do
|
||||
|
||||
it 'creates a flag when there is none' do
|
||||
expect { described_class.flag!(user, comment) }.to change{ InappropiateFlag.count }.by(1)
|
||||
expect(InappropiateFlag.last.user).to eq(user)
|
||||
expect(InappropiateFlag.last.flaggable).to eq(comment)
|
||||
expect { described_class.flag!(user, comment) }.to change{ Flag.count }.by(1)
|
||||
expect(Flag.last.user).to eq(user)
|
||||
expect(Flag.last.flaggable).to eq(comment)
|
||||
end
|
||||
|
||||
it 'raises an error if the flag has already been created' do
|
||||
described_class.flag!(user, comment)
|
||||
expect { described_class.flag!(user, comment) }.to raise_error(InappropiateFlag::AlreadyFlaggedError)
|
||||
expect { described_class.flag!(user, comment) }.to raise_error(Flag::AlreadyFlaggedError)
|
||||
end
|
||||
|
||||
it 'increases the flag count' do
|
||||
expect { described_class.flag!(user, comment) }.to change{ comment.reload.inappropiate_flags_count }.by(1)
|
||||
end
|
||||
|
||||
it 'updates the flagged_as date' do
|
||||
expect { described_class.flag!(user, comment) }.to change{ comment.reload.flagged_as_inappropiate_at }
|
||||
expect { described_class.flag!(user, comment) }.to change{ comment.reload.flags_count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.unflag!' do
|
||||
it 'raises an error if the flag does not exist' do
|
||||
expect { described_class.unflag!(user, comment) }.to raise_error(InappropiateFlag::NotFlaggedError)
|
||||
expect { described_class.unflag!(user, comment) }.to raise_error(Flag::NotFlaggedError)
|
||||
end
|
||||
|
||||
describe 'when the flag already exists' do
|
||||
before(:each) { described_class.flag!(user, comment) }
|
||||
|
||||
it 'removes an existing flag' do
|
||||
expect { described_class.unflag!(user, comment) }.to change{ InappropiateFlag.count }.by(-1)
|
||||
expect { described_class.unflag!(user, comment) }.to change{ Flag.count }.by(-1)
|
||||
end
|
||||
|
||||
it 'decreases the flag count' do
|
||||
expect { described_class.unflag!(user, comment) }.to change{ comment.reload.inappropiate_flags_count }.by(-1)
|
||||
end
|
||||
|
||||
it 'does not update the flagged_as date' do
|
||||
expect { described_class.unflag!(user, comment) }.to_not change{ comment.flagged_as_inappropiate_at }
|
||||
expect { described_class.unflag!(user, comment) }.to change{ comment.reload.flags_count }.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user