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:
kikito
2015-08-27 10:48:49 +02:00
parent a3e983f154
commit 909dfb4ce3
29 changed files with 107 additions and 115 deletions

View File

@@ -22,14 +22,14 @@ class CommentsController < ApplicationController
respond_with @comment respond_with @comment
end end
def flag_as_inappropiate def flag
InappropiateFlag.flag!(current_user, @comment) Flag.flag!(current_user, @comment)
respond_with @comment, template: 'comments/_refresh_flag_as_inappropiate_actions' respond_with @comment, template: 'comments/_refresh_flag_actions'
end end
def undo_flag_as_inappropiate def unflag
InappropiateFlag.unflag!(current_user, @comment) Flag.unflag!(current_user, @comment)
respond_with @comment, template: 'comments/_refresh_flag_as_inappropiate_actions' respond_with @comment, template: 'comments/_refresh_flag_actions'
end end
private private

View File

@@ -51,14 +51,14 @@ class DebatesController < ApplicationController
set_debate_votes(@debate) set_debate_votes(@debate)
end end
def flag_as_inappropiate def flag
InappropiateFlag.flag!(current_user, @debate) Flag.flag!(current_user, @debate)
respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions' respond_with @debate, template: 'debates/_refresh_flag_actions'
end end
def undo_flag_as_inappropiate def unflag
InappropiateFlag.unflag!(current_user, @debate) Flag.unflag!(current_user, @debate)
respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions' respond_with @debate, template: 'debates/_refresh_flag_actions'
end end
private private

View File

@@ -27,7 +27,7 @@ class Moderation::CommentsController < Moderation::BaseController
private private
def load_comments 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 end
def set_valid_filters def set_valid_filters

View File

@@ -27,7 +27,7 @@ class Moderation::DebatesController < Moderation::BaseController
private private
def load_debates 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 end
def set_valid_filters def set_valid_filters

View File

@@ -22,20 +22,20 @@ class Ability
can :create, Comment can :create, Comment
can :create, Debate can :create, Debate
can :flag_as_inappropiate, Comment do |comment| can :flag, Comment do |comment|
comment.author_id != user.id && !InappropiateFlag.flagged?(user, comment) comment.author_id != user.id && !Flag.flagged?(user, comment)
end end
can :undo_flag_as_inappropiate, Comment do |comment| can :unflag, Comment do |comment|
comment.author_id != user.id && InappropiateFlag.flagged?(user, comment) comment.author_id != user.id && Flag.flagged?(user, comment)
end end
can :flag_as_inappropiate, Debate do |debate| can :flag, Debate do |debate|
debate.author_id != user.id && !InappropiateFlag.flagged?(user, debate) debate.author_id != user.id && !Flag.flagged?(user, debate)
end end
can :undo_flag_as_inappropiate, Debate do |debate| can :unflag, Debate do |debate|
debate.author_id != user.id && InappropiateFlag.flagged?(user, debate) debate.author_id != user.id && Flag.flagged?(user, debate)
end end
unless user.organization? unless user.organization?

View File

@@ -12,14 +12,14 @@ class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true, counter_cache: true belongs_to :commentable, polymorphic: true, counter_cache: true
belongs_to :user, -> { with_hidden } belongs_to :user, -> { with_hidden }
has_many :inappropiate_flags, :as => :flaggable has_many :flags, :as => :flaggable
scope :recent, -> { order(id: :desc) } 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 :pending, -> { where(archived_at: nil, hidden_at: nil) }
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") } 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) } scope :for_render, -> { with_hidden.includes(user: :organization) }

View File

@@ -12,7 +12,7 @@ class Debate < ActiveRecord::Base
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' 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 :title, presence: true
validates :description, presence: true validates :description, presence: true
@@ -23,10 +23,10 @@ class Debate < ActiveRecord::Base
before_validation :sanitize_description before_validation :sanitize_description
before_validation :sanitize_tag_list 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 :pending, -> { where(archived_at: nil, hidden_at: nil) }
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") } 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) } scope :for_render, -> { includes(:tags) }
# Ahoy setup # Ahoy setup

View File

@@ -1,7 +1,7 @@
class InappropiateFlag < ActiveRecord::Base class Flag < ActiveRecord::Base
belongs_to :user 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| scope(:by_user_and_flaggable, lambda do |user, flaggable|
where(user_id: user.id, where(user_id: user.id,
@@ -12,13 +12,13 @@ class InappropiateFlag < ActiveRecord::Base
class AlreadyFlaggedError < StandardError class AlreadyFlaggedError < StandardError
def initialize def initialize
super "The flaggable was already flagged as inappropiate by this user" super "The flaggable was already flagged by this user"
end end
end end
class NotFlaggedError < StandardError class NotFlaggedError < StandardError
def initialize def initialize
super "The flaggable was not flagged as inappropiate by this user" super "The flaggable was not flagged by this user"
end end
end end

View File

@@ -14,7 +14,7 @@ class User < ActiveRecord::Base
has_one :administrator has_one :administrator
has_one :moderator has_one :moderator
has_one :organization has_one :organization
has_many :inappropiate_flags has_many :flags
has_many :identities, dependent: :destroy has_many :identities, dependent: :destroy
validates :username, presence: true, unless: :organization? validates :username, presence: true, unless: :organization?

View File

@@ -1,5 +1,5 @@
<span class="js-flag-as-inappropiate-actions"> <span class="js-flag-actions">
<%= render 'comments/flag_as_inappropiate_actions', comment: comment %> <%= render 'comments/flag_actions', comment: comment %>
</span> </span>
<span class='js-moderation-actions'> <span class='js-moderation-actions'>

View File

@@ -1,23 +1,23 @@
<% if can? :flag_as_inappropiate, comment %> <% if can? :flag, comment %>
<span class="divider">&nbsp;|&nbsp;</span> <span class="divider">&nbsp;|&nbsp;</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') %>">
&nbsp;<i class="icon-flag flag-disable"></i>&nbsp;&nbsp; &nbsp;<i class="icon-flag flag-disable"></i>&nbsp;&nbsp;
</a> </a>
<ul id="flag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1"> <ul id="flag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
<li> <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> </li>
</ul> </ul>
<% end %> <% end %>
<% if can? :undo_flag_as_inappropiate, comment %> <% if can? :unflag, comment %>
<span class="divider">&nbsp;|&nbsp;</span> <span class="divider">&nbsp;|&nbsp;</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') %>">
&nbsp;<i class="icon-flag flag-active"></i>&nbsp;&nbsp; &nbsp;<i class="icon-flag flag-active"></i>&nbsp;&nbsp;
</a> </a>
<ul id="unflag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1"> <ul id="unflag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
<li> <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> </li>
</ul> </ul>
<% end %> <% end %>

View File

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

View File

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

View File

@@ -1,21 +1,21 @@
<% if can? :flag_as_inappropiate, debate %> <% 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_as_inappropiate') %>"> <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') %>">
&nbsp;<i class="icon-flag flag-disable"></i>&nbsp;&nbsp; &nbsp;<i class="icon-flag flag-disable"></i>&nbsp;&nbsp;
</a> </a>
<ul id="flag-drop-debate-<%= debate.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1"> <ul id="flag-drop-debate-<%= debate.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
<li> <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> </li>
</ul> </ul>
<% end %> <% end %>
<% if can? :undo_flag_as_inappropiate, debate %> <% 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.undo_flag_as_inappropiate') %>"> <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') %>">
&nbsp;<i class="icon-flag flag-active"></i>&nbsp;&nbsp; &nbsp;<i class="icon-flag flag-active"></i>&nbsp;&nbsp;
</a> </a>
<ul id="unflag-drop-debate-<%= debate.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1"> <ul id="unflag-drop-debate-<%= debate.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
<li> <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> </li>
</ul> </ul>
<% end %> <% end %>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@debate) %> .js-flag-actions").html('<%= j render("debates/flag_actions", debate: @debate) %>');

View File

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

View File

@@ -42,8 +42,8 @@
<i class="icon-comments"></i>&nbsp; <i class="icon-comments"></i>&nbsp;
<%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %> <%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>
<span class="bullet">&nbsp;&bullet;&nbsp;</span> <span class="bullet">&nbsp;&bullet;&nbsp;</span>
<span class="js-flag-as-inappropiate-actions"> <span class="js-flag-actions">
<%= render 'debates/flag_as_inappropiate_actions', debate: @debate %> <%= render 'debates/flag_actions', debate: @debate %>
</span> </span>
</div> </div>

View File

@@ -35,7 +35,7 @@
<span class="date"><%= l comment.updated_at.to_date %></span> <span class="date"><%= l comment.updated_at.to_date %></span>
</td> </td>
<td><%= comment.body %></td> <td><%= comment.body %></td>
<td class="text-center"><%= comment.inappropiate_flags_count %></td> <td class="text-center"><%= comment.flags_count %></td>
<td> <td>
<%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %> <%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %>
</td> </td>

View File

@@ -34,7 +34,7 @@
<br> <br>
<%= debate.description %> <%= debate.description %>
</td> </td>
<td class="text-center"><%= debate.inappropiate_flags_count %></td> <td class="text-center"><%= debate.flags_count %></td>
<td> <td>
<%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %> <%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %>
</td> </td>

View File

@@ -133,8 +133,8 @@ en:
shared: shared:
tags_cloud: tags_cloud:
tags: Topics tags: Topics
flag_as_inappropiate: Flag as inappropriate flag: Flag as inappropriate
undo_flag_as_inappropiate: Undo flag unflag: Undo flag
collective: Collective collective: Collective
mailer: mailer:
comment: comment:

View File

@@ -133,8 +133,8 @@ es:
shared: shared:
tags_cloud: tags_cloud:
tags: Temas tags: Temas
flag_as_inappropiate: Denunciar como inapropiado flag: Denunciar como inapropiado
undo_flag_as_inappropiate: Deshacer denuncia unflag: Deshacer denuncia
collective: Colectivo collective: Colectivo
mailer: mailer:
comment: comment:

View File

@@ -28,15 +28,15 @@ Rails.application.routes.draw do
resources :debates do resources :debates do
member do member do
post :vote post :vote
put :flag_as_inappropiate put :flag
put :undo_flag_as_inappropiate put :unflag
end end
resources :comments, only: :create, shallow: true do resources :comments, only: :create, shallow: true do
member do member do
post :vote post :vote
put :flag_as_inappropiate put :flag
put :undo_flag_as_inappropiate put :unflag
end end
end end
end end

View File

@@ -26,9 +26,9 @@ FactoryGirl.define do
archived_at Time.now archived_at Time.now
end end
trait :flagged_as_inappropiate do trait :flagged do
after :create do |debate| after :create do |debate|
InappropiateFlag.flag!(FactoryGirl.create(:user), debate) Flag.flag!(FactoryGirl.create(:user), debate)
end end
end end
end end
@@ -55,9 +55,9 @@ FactoryGirl.define do
archived_at Time.now archived_at Time.now
end end
trait :flagged_as_inappropiate do trait :flagged do
after :create do |debate| after :create do |debate|
InappropiateFlag.flag!(FactoryGirl.create(:user), debate) Flag.flag!(FactoryGirl.create(:user), debate)
end end
end end
end end

View File

@@ -148,14 +148,14 @@ feature 'Comments' do
expect(page).to have_css("#unflag-expand-comment-#{comment.id}") expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end end
expect(InappropiateFlag.flagged?(user, comment)).to be expect(Flag.flagged?(user, comment)).to be
end end
scenario "Undoing flagging as inappropriate", :js do scenario "Undoing flagging as inappropriate", :js do
user = create(:user) user = create(:user)
debate = create(:debate) debate = create(:debate)
comment = create(:comment, commentable: debate) comment = create(:comment, commentable: debate)
InappropiateFlag.flag!(user, comment) Flag.flag!(user, comment)
login_as(user) login_as(user)
visit debate_path(debate) visit debate_path(debate)
@@ -167,7 +167,7 @@ feature 'Comments' do
expect(page).to have_css("#flag-expand-comment-#{comment.id}") expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end end
expect(InappropiateFlag.flagged?(user, comment)).to_not be expect(Flag.flagged?(user, comment)).to_not be
end end
feature "Moderators" do feature "Moderators" do

View File

@@ -315,7 +315,7 @@ feature 'Debates' do
end end
end end
scenario "Flagging as inappropiate", :js do scenario "Flagging", :js do
user = create(:user) user = create(:user)
debate = create(:debate) debate = create(:debate)
@@ -329,13 +329,13 @@ feature 'Debates' do
expect(page).to have_css("#unflag-expand-debate-#{debate.id}") expect(page).to have_css("#unflag-expand-debate-#{debate.id}")
end end
expect(InappropiateFlag.flagged?(user, debate)).to be expect(Flag.flagged?(user, debate)).to be
end end
scenario "Undoing flagging as inappropiate", :js do scenario "Unflagging", :js do
user = create(:user) user = create(:user)
debate = create(:debate) debate = create(:debate)
InappropiateFlag.flag!(user, debate) Flag.flag!(user, debate)
login_as(user) login_as(user)
visit debate_path(debate) visit debate_path(debate)
@@ -347,7 +347,7 @@ feature 'Debates' do
expect(page).to have_css("#flag-expand-debate-#{debate.id}") expect(page).to have_css("#flag-expand-debate-#{debate.id}")
end end
expect(InappropiateFlag.flagged?(user, debate)).to_not be expect(Flag.flagged?(user, debate)).to_not be
end end
end end

View File

@@ -123,9 +123,9 @@ feature 'Moderate Comments' do
end end
scenario "Filtering comments" do scenario "Filtering comments" do
create(:comment, :flagged_as_inappropiate, body: "Pending comment") create(:comment, :flagged, body: "Pending comment")
create(:comment, :flagged_as_inappropiate, :hidden, body: "Hidden comment") create(:comment, :flagged, :hidden, body: "Hidden comment")
create(:comment, :flagged_as_inappropiate, :archived, body: "Archived comment") create(:comment, :flagged, :archived, body: "Archived comment")
visit moderation_comments_path(filter: 'all') visit moderation_comments_path(filter: 'all')
expect(page).to have_content('Pending comment') 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 scenario "Reviewing links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page 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) visit moderation_comments_path(filter: 'pending', page: 2)
@@ -162,7 +162,7 @@ feature 'Moderate Comments' do
background do background do
debate = create(:debate, title: 'Democracy') 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 visit moderation_comments_path
end end

View File

@@ -66,9 +66,9 @@ feature 'Moderate debates' do
end end
scenario "Filtering debates" do scenario "Filtering debates" do
create(:debate, :flagged_as_inappropiate, title: "Pending debate") create(:debate, :flagged, title: "Pending debate")
create(:debate, :flagged_as_inappropiate, :hidden, title: "Hidden debate") create(:debate, :flagged, :hidden, title: "Hidden debate")
create(:debate, :flagged_as_inappropiate, :archived, title: "Archived debate") create(:debate, :flagged, :archived, title: "Archived debate")
visit moderation_debates_path(filter: 'all') visit moderation_debates_path(filter: 'all')
expect(page).to have_content('Pending debate') 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 scenario "Reviewing links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page 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) visit moderation_debates_path(filter: 'pending', page: 2)
@@ -104,7 +104,7 @@ feature 'Moderate debates' do
feature 'A flagged debate exists' do feature 'A flagged debate exists' do
background 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 visit moderation_debates_path
end end

View File

@@ -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_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) } it { should_not be_able_to(:comment_as_moderator, debate) }
describe 'flagging content as inappropiate' do describe 'flagging content' do
it { should be_able_to(:flag_as_inappropiate, debate) } it { should be_able_to(:flag, debate) }
it { should_not be_able_to(:undo_flag_as_inappropiate, debate) } it { should_not be_able_to(:unflag, debate) }
it { should be_able_to(:flag_as_inappropiate, comment) } it { should be_able_to(:flag, comment) }
it { should_not be_able_to(:undo_flag_as_inappropiate, comment) } it { should_not be_able_to(:unflag, comment) }
describe "own comments" do describe "own comments" do
let(:own_comment) { create(:comment, author: user) } let(:own_comment) { create(:comment, author: user) }
it { should_not be_able_to(:flag_as_inappropiate, own_comment) } it { should_not be_able_to(:flag, own_comment) }
it { should_not be_able_to(:undo_flag_as_inappropiate, own_comment) } it { should_not be_able_to(:unflag, own_comment) }
end end
describe "own debates" do describe "own debates" do
let(:own_debate) { create(:debate, author: user) } let(:own_debate) { create(:debate, author: user) }
it { should_not be_able_to(:flag_as_inappropiate, own_debate) } it { should_not be_able_to(:flag, own_debate) }
it { should_not be_able_to(:undo_flag_as_inappropiate, own_debate) } it { should_not be_able_to(:unflag, own_debate) }
end end
describe "already-flagged comments" do 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_not be_able_to(:flag, comment) }
it { should be_able_to(:undo_flag_as_inappropiate, comment) } it { should be_able_to(:unflag, comment) }
end end
describe "already-flagged debates" do 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_not be_able_to(:flag, debate) }
it { should be_able_to(:undo_flag_as_inappropiate, debate) } it { should be_able_to(:unflag, debate) }
end end
end end

View File

@@ -1,6 +1,6 @@
require 'rails_helper' require 'rails_helper'
describe InappropiateFlag do describe Flag do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:comment) { create(:comment) } let(:comment) { create(:comment) }
@@ -8,43 +8,35 @@ describe InappropiateFlag do
describe '.flag!' do describe '.flag!' do
it 'creates a flag when there is none' do it 'creates a flag when there is none' do
expect { described_class.flag!(user, comment) }.to change{ InappropiateFlag.count }.by(1) expect { described_class.flag!(user, comment) }.to change{ Flag.count }.by(1)
expect(InappropiateFlag.last.user).to eq(user) expect(Flag.last.user).to eq(user)
expect(InappropiateFlag.last.flaggable).to eq(comment) expect(Flag.last.flaggable).to eq(comment)
end end
it 'raises an error if the flag has already been created' do it 'raises an error if the flag has already been created' do
described_class.flag!(user, comment) 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 end
it 'increases the flag count' do it 'increases the flag count' do
expect { described_class.flag!(user, comment) }.to change{ comment.reload.inappropiate_flags_count }.by(1) expect { described_class.flag!(user, comment) }.to change{ comment.reload.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 }
end end
end end
describe '.unflag!' do describe '.unflag!' do
it 'raises an error if the flag does not exist' 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 end
describe 'when the flag already exists' do describe 'when the flag already exists' do
before(:each) { described_class.flag!(user, comment) } before(:each) { described_class.flag!(user, comment) }
it 'removes an existing flag' do 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 end
it 'decreases the flag count' do it 'decreases the flag count' do
expect { described_class.unflag!(user, comment) }.to change{ comment.reload.inappropiate_flags_count }.by(-1) expect { described_class.unflag!(user, comment) }.to change{ comment.reload.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 }
end end
end end