diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 798196ca0..c342b8d10 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index cf6d14f65..6bea23ffd 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -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 diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb index 8a4d3768e..0570ab5d3 100644 --- a/app/controllers/moderation/comments_controller.rb +++ b/app/controllers/moderation/comments_controller.rb @@ -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 diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb index 3492ee423..fdc09b61d 100644 --- a/app/controllers/moderation/debates_controller.rb +++ b/app/controllers/moderation/debates_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index c8ed63d22..7a682de5a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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? diff --git a/app/models/comment.rb b/app/models/comment.rb index bbfeca4f5..9df42b700 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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) } diff --git a/app/models/debate.rb b/app/models/debate.rb index 15590fc60..1c3b63370 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -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 diff --git a/app/models/inappropiate_flag.rb b/app/models/flag.rb similarity index 72% rename from app/models/inappropiate_flag.rb rename to app/models/flag.rb index b60b98618..d2f30d284 100644 --- a/app/models/inappropiate_flag.rb +++ b/app/models/flag.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index d7b77a7e0..27e886b90 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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? diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb index 51a6743e0..c4bb0d072 100644 --- a/app/views/comments/_actions.html.erb +++ b/app/views/comments/_actions.html.erb @@ -1,5 +1,5 @@ - - <%= render 'comments/flag_as_inappropiate_actions', comment: comment %> + + <%= render 'comments/flag_actions', comment: comment %> diff --git a/app/views/comments/_flag_as_inappropiate_actions.html.erb b/app/views/comments/_flag_actions.html.erb similarity index 65% rename from app/views/comments/_flag_as_inappropiate_actions.html.erb rename to app/views/comments/_flag_actions.html.erb index 9fba8b5b2..f1557668c 100644 --- a/app/views/comments/_flag_as_inappropiate_actions.html.erb +++ b/app/views/comments/_flag_actions.html.erb @@ -1,23 +1,23 @@ -<% if can? :flag_as_inappropiate, comment %> +<% if can? :flag, comment %>  |  - <% end %> -<% if can? :undo_flag_as_inappropiate, comment %> +<% if can? :unflag, comment %>  |  - <% end %> diff --git a/app/views/comments/_refresh_flag_actions.js.erb b/app/views/comments/_refresh_flag_actions.js.erb new file mode 100644 index 000000000..01c1dcf76 --- /dev/null +++ b/app/views/comments/_refresh_flag_actions.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@comment) %> .js-flag-actions").html('<%= j render("comments/flag_actions", comment: @comment) %>'); diff --git a/app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb b/app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb deleted file mode 100644 index 58f356f2b..000000000 --- a/app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>'); diff --git a/app/views/debates/_flag_as_inappropiate_actions.html.erb b/app/views/debates/_flag_actions.html.erb similarity index 63% rename from app/views/debates/_flag_as_inappropiate_actions.html.erb rename to app/views/debates/_flag_actions.html.erb index 6c3d34236..07fff9329 100644 --- a/app/views/debates/_flag_as_inappropiate_actions.html.erb +++ b/app/views/debates/_flag_actions.html.erb @@ -1,21 +1,21 @@ -<% if can? :flag_as_inappropiate, debate %> - <% end %> -<% if can? :undo_flag_as_inappropiate, debate %> - <% end %> diff --git a/app/views/debates/_refresh_flag_actions.js.erb b/app/views/debates/_refresh_flag_actions.js.erb new file mode 100644 index 000000000..f511f347f --- /dev/null +++ b/app/views/debates/_refresh_flag_actions.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@debate) %> .js-flag-actions").html('<%= j render("debates/flag_actions", debate: @debate) %>'); diff --git a/app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb b/app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb deleted file mode 100644 index 7be008e35..000000000 --- a/app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#<%= dom_id(@debate) %> .js-flag-as-inappropiate-actions").html('<%= j render("debates/flag_as_inappropiate_actions", debate: @debate) %>'); diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index af25f28b1..8fab71128 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -42,8 +42,8 @@   <%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>  •  - - <%= render 'debates/flag_as_inappropiate_actions', debate: @debate %> + + <%= render 'debates/flag_actions', debate: @debate %> diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb index f4ce8ec67..c4b9d3ee0 100644 --- a/app/views/moderation/comments/index.html.erb +++ b/app/views/moderation/comments/index.html.erb @@ -35,7 +35,7 @@ <%= l comment.updated_at.to_date %> <%= comment.body %> - <%= comment.inappropiate_flags_count %> + <%= comment.flags_count %> <%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %> diff --git a/app/views/moderation/debates/index.html.erb b/app/views/moderation/debates/index.html.erb index ac11d2159..30cd14669 100644 --- a/app/views/moderation/debates/index.html.erb +++ b/app/views/moderation/debates/index.html.erb @@ -34,7 +34,7 @@
<%= debate.description %> - <%= debate.inappropiate_flags_count %> + <%= debate.flags_count %> <%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 322cf585f..03e0f900e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/locales/es.yml b/config/locales/es.yml index 5c21c039e..3ef3a5113 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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: diff --git a/config/routes.rb b/config/routes.rb index 3a75c8634..c6db2acd9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index ded2e20a0..ed77770a4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 58626b02b..0986412bc 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -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 diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 22b689308..2fd114adc 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -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 diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index 2e3d1196e..efc37fc72 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -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 diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb index b1234bb1b..ee9f53b7e 100644 --- a/spec/features/moderation/debates_spec.rb +++ b/spec/features/moderation/debates_spec.rb @@ -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 diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index a7cfd195f..440807603 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -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 diff --git a/spec/models/inappropiate_flag_spec.rb b/spec/models/flag_spec.rb similarity index 65% rename from spec/models/inappropiate_flag_spec.rb rename to spec/models/flag_spec.rb index 0ae831ee0..a5725e7c8 100644 --- a/spec/models/inappropiate_flag_spec.rb +++ b/spec/models/flag_spec.rb @@ -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