diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index ba0f8f7d..172c5d11 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -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 diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index 66ed1766..70c4e7c2 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -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 diff --git a/app/controllers/inbox_controller.rb b/app/controllers/inbox_controller.rb index e551b0bc..26d4113c 100644 --- a/app/controllers/inbox_controller.rb +++ b/app/controllers/inbox_controller.rb @@ -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| diff --git a/app/models/answer.rb b/app/models/answer.rb index f13880f9..5abd6d5a 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -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? diff --git a/app/models/inbox_filter.rb b/app/models/inbox_filter.rb index bf213d9d..ab812fa7 100644 --- a/app/models/inbox_filter.rb +++ b/app/models/inbox_filter.rb @@ -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) diff --git a/app/models/question.rb b/app/models/question.rb index 84f5faf6..85d24ad1 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -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 diff --git a/app/models/user/inbox_methods.rb b/app/models/user/inbox_methods.rb index 54dd89ef..e6dca73b 100644 --- a/app/models/user/inbox_methods.rb +++ b/app/models/user/inbox_methods.rb @@ -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 diff --git a/app/workers/question_worker.rb b/app/workers/question_worker.rb index 69ee8091..304bd2d3 100644 --- a/app/workers/question_worker.rb +++ b/app/workers/question_worker.rb @@ -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 diff --git a/app/workers/scheduler/inbox_cleanup_scheduler.rb b/app/workers/scheduler/inbox_cleanup_scheduler.rb index 77948ab0..6f436ecf 100644 --- a/app/workers/scheduler/inbox_cleanup_scheduler.rb +++ b/app/workers/scheduler/inbox_cleanup_scheduler.rb @@ -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 diff --git a/app/workers/send_to_inbox_job.rb b/app/workers/send_to_inbox_job.rb index 6b8eec8a..aa640763 100644 --- a/app/workers/send_to_inbox_job.rb +++ b/app/workers/send_to_inbox_job.rb @@ -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 diff --git a/lib/use_case/question/create.rb b/lib/use_case/question/create.rb index 17987a1d..0a9a2db0 100644 --- a/lib/use_case/question/create.rb +++ b/lib/use_case/question/create.rb @@ -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) { diff --git a/spec/controllers/ajax/answer_controller_spec.rb b/spec/controllers/ajax/answer_controller_spec.rb index fd6b50ca..5e0455c9 100644 --- a/spec/controllers/ajax/answer_controller_spec.rb +++ b/spec/controllers/ajax/answer_controller_spec.rb @@ -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 diff --git a/spec/controllers/ajax/inbox_controller_spec.rb b/spec/controllers/ajax/inbox_controller_spec.rb index 3b50c43d..64e669cb 100644 --- a/spec/controllers/ajax/inbox_controller_spec.rb +++ b/spec/controllers/ajax/inbox_controller_spec.rb @@ -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" diff --git a/spec/controllers/anonymous_block_controller_spec.rb b/spec/controllers/anonymous_block_controller_spec.rb index a1619a51..b024651c 100644 --- a/spec/controllers/anonymous_block_controller_spec.rb +++ b/spec/controllers/anonymous_block_controller_spec.rb @@ -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 diff --git a/spec/controllers/inbox_controller_spec.rb b/spec/controllers/inbox_controller_spec.rb index 5b7eae63..3ebefd1b 100644 --- a/spec/controllers/inbox_controller_spec.rb +++ b/spec/controllers/inbox_controller_spec.rb @@ -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 diff --git a/spec/controllers/moderation/inbox_controller_spec.rb b/spec/controllers/moderation/inbox_controller_spec.rb index 0cf89d2d..70b8f7ed 100644 --- a/spec/controllers/moderation/inbox_controller_spec.rb +++ b/spec/controllers/moderation/inbox_controller_spec.rb @@ -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 diff --git a/spec/models/answer_spec.rb b/spec/models/answer_spec.rb index bca0c829..f09759a9 100644 --- a/spec/models/answer_spec.rb +++ b/spec/models/answer_spec.rb @@ -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 diff --git a/spec/models/user/inbox_methods_spec.rb b/spec/models/user/inbox_methods_spec.rb index efa7d16e..d5d4a086 100644 --- a/spec/models/user/inbox_methods_spec.rb +++ b/spec/models/user/inbox_methods_spec.rb @@ -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) diff --git a/spec/views/inbox/_entry.html.haml_spec.rb b/spec/views/inbox/_entry.html.haml_spec.rb index c525284f..7524173f 100644 --- a/spec/views/inbox/_entry.html.haml_spec.rb +++ b/spec/views/inbox/_entry.html.haml_spec.rb @@ -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 } diff --git a/spec/views/inbox/show.html.haml_spec.rb b/spec/views/inbox/show.html.haml_spec.rb index 19a3a13e..522b123a 100644 --- a/spec/views/inbox/show.html.haml_spec.rb +++ b/spec/views/inbox/show.html.haml_spec.rb @@ -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] diff --git a/spec/views/inbox/show.turbo_stream.haml_spec.rb b/spec/views/inbox/show.turbo_stream.haml_spec.rb index f7a49245..2fd30175 100644 --- a/spec/views/inbox/show.turbo_stream.haml_spec.rb +++ b/spec/views/inbox/show.turbo_stream.haml_spec.rb @@ -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] diff --git a/spec/workers/question_worker_spec.rb b/spec/workers/question_worker_spec.rb index 0795e55b..7961b884 100644 --- a/spec/workers/question_worker_spec.rb +++ b/spec/workers/question_worker_spec.rb @@ -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) ) diff --git a/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb b/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb index 81763b6c..92f335bc 100644 --- a/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb +++ b/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb @@ -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), ) diff --git a/spec/workers/send_to_inbox_job_spec.rb b/spec/workers/send_to_inbox_job_spec.rb index 237ca75d..f549b694 100644 --- a/spec/workers/send_to_inbox_job_spec.rb +++ b/spec/workers/send_to_inbox_job_spec.rb @@ -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