Fix rubocop nits
This commit is contained in:
parent
245f862bb2
commit
62ba205d3e
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Ajax::InboxController < AjaxController
|
||||
def remove
|
||||
params.require :id
|
||||
|
@ -28,7 +30,7 @@ class Ajax::InboxController < AjaxController
|
|||
raise unless user_signed_in?
|
||||
|
||||
begin
|
||||
InboxEntry.where(user: current_user).each { |i| i.remove }
|
||||
InboxEntry.where(user: current_user).find_each(&:remove)
|
||||
rescue => e
|
||||
Sentry.capture_exception(e)
|
||||
@response[:status] = :err
|
||||
|
@ -43,10 +45,10 @@ class Ajax::InboxController < AjaxController
|
|||
|
||||
def remove_all_author
|
||||
begin
|
||||
@target_user = User.where('LOWER(screen_name) = ?', params[:author].downcase).first!
|
||||
@target_user = User.where("LOWER(screen_name) = ?", params[:author].downcase).first!
|
||||
@inbox = current_user.inbox_entries.joins(:question)
|
||||
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
||||
@inbox.each { |i| i.remove }
|
||||
@inbox.each(&:remove)
|
||||
rescue => e
|
||||
Sentry.capture_exception(e)
|
||||
@response[:status] = :err
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Question < ApplicationRecord
|
||||
include Question::AnswerMethods
|
||||
|
||||
|
@ -11,7 +13,7 @@ class Question < ApplicationRecord
|
|||
SHORT_QUESTION_MAX_LENGTH = 512
|
||||
|
||||
before_destroy do
|
||||
rep = Report.where(target_id: self.id, type: 'Reports::Question')
|
||||
rep = Report.where(target_id: self.id, type: "Reports::Question")
|
||||
rep.each do |r|
|
||||
unless r.nil?
|
||||
r.deleted = true
|
||||
|
@ -25,8 +27,9 @@ class Question < ApplicationRecord
|
|||
end
|
||||
|
||||
def can_be_removed?
|
||||
return false if self.answers.count > 0
|
||||
return false if self.answers.count.positive?
|
||||
return false if InboxEntry.where(question: self).count > 1
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RenameInboxesToInboxEntries < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
rename_table :inboxes, :inbox_entries
|
||||
|
|
|
@ -7,11 +7,11 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
describe "#remove" do
|
||||
let(:params) do
|
||||
{
|
||||
id: inbox_entry_id
|
||||
id: inbox_entry_id,
|
||||
}
|
||||
end
|
||||
|
||||
subject { delete(:remove, params: params) }
|
||||
subject { delete(:remove, params:) }
|
||||
|
||||
context "when user is signed in" do
|
||||
before(:each) { sign_in(user) }
|
||||
|
@ -29,7 +29,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => false,
|
||||
"status" => "fail",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -66,7 +66,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => false,
|
||||
"status" => "not_found",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -80,7 +80,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => false,
|
||||
"status" => "not_found",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -98,7 +98,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -107,7 +107,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
context "when user has some inbox entries" do
|
||||
let(:some_other_user) { FactoryBot.create(:user) }
|
||||
before do
|
||||
10.times { FactoryBot.create(:inbox_entry, user: user) }
|
||||
10.times { FactoryBot.create(:inbox_entry, user:) }
|
||||
10.times { FactoryBot.create(:inbox_entry, user: some_other_user) }
|
||||
end
|
||||
|
||||
|
@ -124,7 +124,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => false,
|
||||
"status" => "err",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -135,11 +135,11 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
describe "#remove_all_author" do
|
||||
let(:params) do
|
||||
{
|
||||
author: author
|
||||
author:,
|
||||
}
|
||||
end
|
||||
|
||||
subject { delete(:remove_all_author, params: params) }
|
||||
subject { delete(:remove_all_author, params:) }
|
||||
|
||||
context "when user is signed in" do
|
||||
before(:each) { sign_in(user) }
|
||||
|
@ -149,7 +149,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -162,9 +162,9 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
normal_question = FactoryBot.create(:question, user: some_other_user, author_is_anonymous: false)
|
||||
anon_question = FactoryBot.create(:question, user: some_other_user, author_is_anonymous: true)
|
||||
|
||||
10.times { FactoryBot.create(:inbox_entry, user: user) }
|
||||
3.times { FactoryBot.create(:inbox_entry, user: user, question: normal_question) }
|
||||
2.times { FactoryBot.create(:inbox_entry, user: user, question: anon_question) }
|
||||
10.times { FactoryBot.create(:inbox_entry, user:) }
|
||||
3.times { FactoryBot.create(:inbox_entry, user:, question: normal_question) }
|
||||
2.times { FactoryBot.create(:inbox_entry, user:, question: anon_question) }
|
||||
end
|
||||
|
||||
it "deletes all the entries asked by some other user which are not anonymous from the user's inbox" do
|
||||
|
@ -180,7 +180,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => false,
|
||||
"status" => "err",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -194,7 +194,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"success" => false,
|
||||
"status" => "err",
|
||||
"message" => anything
|
||||
"message" => anything,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue