Rename all occurences of `Inbox` class to `InboxEntry`

This commit is contained in:
Andreas Nedbal 2024-01-27 13:02:58 +01:00 committed by Andreas Nedbal
parent af9cbcdb11
commit 06b2421f2c
24 changed files with 46 additions and 46 deletions

View File

@ -13,7 +13,7 @@ class Ajax::AnswerController < AjaxController
inbox = (params[:inbox] == "true")
if inbox
inbox_entry = Inbox.find(params[:id])
inbox_entry = InboxEntry.find(params[:id])
unless current_user == inbox_entry.user
@response[:status] = :fail
@ -59,7 +59,7 @@ class Ajax::AnswerController < AjaxController
return
end
Inbox.create!(user: answer.user, question: answer.question, new: true, returning: true) if answer.user == current_user
InboxEntry.create!(user: answer.user, question: answer.question, new: true, returning: true) if answer.user == current_user
answer.destroy
@response[:status] = :okay

View File

@ -2,7 +2,7 @@ class Ajax::InboxController < AjaxController
def remove
params.require :id
inbox = Inbox.find(params[:id])
inbox = InboxEntry.find(params[:id])
unless current_user == inbox.user
@response[:status] = :fail
@ -28,7 +28,7 @@ class Ajax::InboxController < AjaxController
raise unless user_signed_in?
begin
Inbox.where(user: current_user).each { |i| i.remove }
InboxEntry.where(user: current_user).each { |i| i.remove }
rescue => e
Sentry.capture_exception(e)
@response[:status] = :err

View File

@ -23,7 +23,7 @@ class InboxController < ApplicationController
author_identifier: "justask",
user: current_user)
inbox = Inbox.create!(user: current_user, question_id: question.id, new: true)
inbox = InboxEntry.create!(user: current_user, question_id: question.id, new: true)
increment_metric
respond_to do |format|

View File

@ -36,7 +36,7 @@ class Answer < ApplicationRecord
SHORT_ANSWER_MAX_LENGTH = 640
after_create do
Inbox.where(user: self.user, question: self.question).destroy_all
InboxEntry.where(user: self.user, question: self.question).destroy_all
user.touch :inbox_updated_at # rubocop:disable Rails/SkipsModelValidations
Notification.notify self.question.user, self unless self.question.user == self.user or self.question.user.nil?

View File

@ -22,7 +22,7 @@ class InboxFilter
end
def results
return Inbox.none unless valid_params?
return InboxEntry.none unless valid_params?
scope = @user.inboxes
.includes(:question, user: :profile)

View File

@ -26,7 +26,7 @@ class Question < ApplicationRecord
def can_be_removed?
return false if self.answers.count > 0
return false if Inbox.where(question: self).count > 1
return false if InboxEntry.where(question: self).count > 1
true
end

View File

@ -15,7 +15,7 @@ module User::InboxMethods
def unread_inbox_count
Rails.cache.fetch(inbox_cache_key, expires_in: 12.hours) do
count = Inbox.where(new: true, user_id: id).count(:id)
count = InboxEntry.where(new: true, user_id: id).count(:id)
# Returning +nil+ here in order to not display a counter
# at all when there isn't anything in the user's inbox

View File

@ -16,7 +16,7 @@ class QuestionWorker
user.followers.each do |f|
next if skip_inbox?(f, question, user)
inbox = Inbox.create(user_id: f.id, question_id:, new: true)
inbox = InboxEntry.create(user_id: f.id, question_id:, new: true)
f.push_notification(webpush_app, inbox) if webpush_app
end
rescue StandardError => e

View File

@ -6,7 +6,7 @@ class Scheduler::InboxCleanupScheduler
sidekiq_options retry: false
def perform
orphaned_entries = Inbox.where(question_id: nil).includes(:user)
orphaned_entries = InboxEntry.where(question_id: nil).includes(:user)
orphaned_entries.each do |inbox|
logger.info "Deleting orphaned inbox entry #{inbox.id} from user #{inbox.user.id}"
inbox.destroy

View File

@ -14,7 +14,7 @@ class SendToInboxJob
return if skip_inbox?(follower, question)
inbox = Inbox.create(user_id: follower.id, question_id:, new: true)
inbox = InboxEntry.create(user_id: follower.id, question_id:, new: true)
follower.push_notification(webpush_app, inbox) if webpush_app
end

View File

@ -20,7 +20,7 @@ module UseCase
increment_asked_count
increment_metric
inbox = ::Inbox.create!(user: target_user, question:, new: true)
inbox = ::InboxEntry.create!(user: target_user, question:, new: true)
notify(inbox)
{

View File

@ -65,7 +65,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:shared_services) { %w[twitter] }
context "when inbox is true" do
let(:id) { FactoryBot.create(:inbox, user: inbox_user, question:).id }
let(:id) { FactoryBot.create(:inbox_entry, user: inbox_user, question:).id }
let(:inbox) { true }
context "when the inbox entry belongs to the user" do
@ -325,13 +325,13 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
include_examples "deletes the answer"
it "returns the question back to the user's inbox" do
expect { subject }.to(change { Inbox.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
expect { subject }.to(change { InboxEntry.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
end
it "returns the question back to the user's inbox when the user has anonymous questions disabled" do
user.privacy_allow_anonymous_questions = false
user.save
expect { subject }.to(change { Inbox.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
expect { subject }.to(change { InboxEntry.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
end
it "updates the inbox caching timestamp for the user who answered" do

View File

@ -17,7 +17,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
before(:each) { sign_in(user) }
context "when inbox entry exists" do
let(:inbox_entry) { FactoryBot.create(:inbox, user: inbox_user) }
let(:inbox_entry) { FactoryBot.create(:inbox_entry, user: inbox_user) }
let(:inbox_entry_id) { inbox_entry.id }
# ensure the inbox entry exists
@ -35,7 +35,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
it "removes the inbox entry" do
expect { subject }.to(change { user.inboxes.count }.by(-1))
expect { Inbox.find(inbox_entry.id) }.to raise_error(ActiveRecord::RecordNotFound)
expect { InboxEntry.find(inbox_entry.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
include_examples "returns the expected response"
@ -112,7 +112,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
end
it "deletes all the entries from the user's inbox" do
expect { subject }.to(change { [Inbox.count, user.inboxes.count] }.from([20, 10]).to([10, 0]))
expect { subject }.to(change { [InboxEntry.count, user.inbox_entries.count] }.from([20, 10]).to([10, 0]))
end
include_examples "returns the expected response"

View File

@ -15,7 +15,7 @@ describe AnonymousBlockController, type: :controller do
context "when all required parameters are given" do
let(:question) { FactoryBot.create(:question, author_identifier: "someidentifier") }
let!(:inbox) { FactoryBot.create(:inbox, user:, question:) }
let!(:inbox) { FactoryBot.create(:inbox_entry, user:, question:) }
let(:params) do
{ question: question.id }
end
@ -50,7 +50,7 @@ describe AnonymousBlockController, type: :controller do
context "when blocking a user globally" do
let(:question) { FactoryBot.create(:question, author_identifier: "someidentifier") }
let!(:inbox) { FactoryBot.create(:inbox, user:, question:) }
let!(:inbox) { FactoryBot.create(:inbox_entry, user:, question:) }
let(:params) do
{ question: question.id, global: "true" }
end

View File

@ -46,7 +46,7 @@ describe InboxController, type: :controller do
end
context "when inbox has an amount of questions less than page size" do
let!(:inbox_entry) { Inbox.create(user:, new: true, question: FactoryBot.create(:question)) }
let!(:inbox_entry) { InboxEntry.create(user:, new: true, question: FactoryBot.create(:question)) }
include_examples "sets the expected ivars" do
let(:expected_assigns) do
@ -79,13 +79,13 @@ describe InboxController, type: :controller do
context "when inbox has an amount of questions more than page size" do
let(:inbox_entry_fillers_page1) do
# 9 times => 1 entry less than default page size
9.times.map { Inbox.create(user:, question: FactoryBot.create(:question)) }
9.times.map { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
end
let(:last_inbox_entry_page1) { Inbox.create(user:, question: FactoryBot.create(:question)) }
let(:last_inbox_entry_page1) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry_fillers_page2) do
5.times.map { Inbox.create(user:, question: FactoryBot.create(:question)) }
5.times.map { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
end
let(:last_inbox_entry_page2) { Inbox.create(user:, question: FactoryBot.create(:question)) }
let(:last_inbox_entry_page2) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
before do
# create inbox entries in reverse so pagination works as expected

View File

@ -7,7 +7,7 @@ describe Moderation::InboxController do
subject { get :index, params: params }
let(:target_user) { FactoryBot.create(:user) }
let!(:inboxes) { FactoryBot.create_list(:inbox, 60, user: target_user) }
let!(:inboxes) { FactoryBot.create_list(:inbox_entry, 60, user: target_user) }
let(:params) { { user: target_user.screen_name } }
context "moderator signed in" do

View File

@ -23,7 +23,7 @@ describe Answer, type: :model do
context "user has the question in their inbox" do
before do
Inbox.create(user:, question:, new: true)
InboxEntry.create(user:, question:, new: true)
end
it "should remove the question from the user's inbox" do

View File

@ -18,7 +18,7 @@ describe User::InboxMethods do
context "user has 1 question in their inbox" do
# FactoryBot seems to have issues with setting the +new+ field on inbox entries
# so we can create it manually instead
let!(:inbox) { Inbox.create(question: FactoryBot.create(:question), user:, new: true) }
let!(:inbox) { InboxEntry.create(question: FactoryBot.create(:question), user:, new: true) }
it "should return 1" do
expect(subject).to eq(1)

View File

@ -3,7 +3,7 @@
require "rails_helper"
describe "inbox/_entry.html.haml", type: :view do
let(:inbox_entry) { Inbox.create(user: inbox_user, question:, new:) }
let(:inbox_entry) { InboxEntry.create(user: inbox_user, question:, new:) }
let(:inbox_user) { user }
let(:user) { FactoryBot.create(:user, sharing_enabled:, sharing_custom_url:) }
let(:sharing_enabled) { true }

View File

@ -25,8 +25,8 @@ describe "inbox/show.html.haml", type: :view do
end
context "with some inbox entries" do
let(:inbox_entry1) { Inbox.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry2) { Inbox.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry1) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry2) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
before do
assign :inbox, [inbox_entry2, inbox_entry1]

View File

@ -12,8 +12,8 @@ describe "inbox/show.turbo_stream.haml", type: :view do
subject(:rendered) { render }
context "with some inbox entries" do
let(:inbox_entry1) { Inbox.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry2) { Inbox.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry1) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
let(:inbox_entry2) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
before do
assign :inbox, [inbox_entry2, inbox_entry1]

View File

@ -22,7 +22,7 @@ describe QuestionWorker do
it "places the question in the inbox of the user's followers" do
expect { subject }
.to(
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
change { InboxEntry.where(user_id: user.followers.ids, question_id:, new: true).count }
.from(0)
.to(5)
)
@ -36,7 +36,7 @@ describe QuestionWorker do
expect { subject }
.to(
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
change { InboxEntry.where(user_id: user.followers.ids, question_id:, new: true).count }
.from(0)
.to(4)
)
@ -47,7 +47,7 @@ describe QuestionWorker do
expect { subject }
.to(
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
change { InboxEntry.where(user_id: user.followers.ids, question_id:, new: true).count }
.from(0)
.to(4)
)
@ -58,7 +58,7 @@ describe QuestionWorker do
expect { subject }
.to(
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
change { InboxEntry.where(user_id: user.followers.ids, question_id:, new: true).count }
.from(0)
.to(4)
)
@ -102,7 +102,7 @@ describe QuestionWorker do
expect { subject }
.to(
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
change { InboxEntry.where(user_id: user.followers.ids, question_id:, new: true).count }
.from(0)
.to(1)
)

View File

@ -17,7 +17,7 @@ describe Scheduler::InboxCleanupScheduler do
it "should delete orphaned inbox entries" do
expect { subject }
.to(
change { Inbox.where(question_id: nil).count }
change { InboxEntry.where(question_id: nil).count }
.from(1)
.to(0),
)

View File

@ -21,7 +21,7 @@ describe SendToInboxJob do
it "places the question in the inbox of the user's followers" do
expect { subject }
.to(
change { Inbox.where(user_id: follower_id, question_id:, new: true).count }
change { InboxEntry.where(user_id: follower_id, question_id:, new: true).count }
.from(0)
.to(1),
)
@ -34,21 +34,21 @@ describe SendToInboxJob do
MuteRule.create(user_id: follower_id, muted_phrase: "spicy")
subject
expect(Inbox.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
expect(InboxEntry.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
end
it "respects inbox locks" do
follower.update(privacy_lock_inbox: true)
subject
expect(Inbox.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
expect(InboxEntry.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
end
it "does not send questions to banned users" do
follower.ban
subject
expect(Inbox.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
expect(InboxEntry.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
end
context "receiver has push notifications enabled" do
@ -86,7 +86,7 @@ describe SendToInboxJob do
expect { subject }
.to(
change { Inbox.where(user_id: follower_id, question_id:, new: true).count }
change { InboxEntry.where(user_id: follower_id, question_id:, new: true).count }
.from(0)
.to(1),
)
@ -94,7 +94,7 @@ describe SendToInboxJob do
it "does not send to recipients who do not allow long questions" do
subject
expect(Inbox.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
expect(InboxEntry.where(user_id: follower_id, question_id:, new: true).count).to eq(0)
end
end
end