Rename all occurences of associative inbox entry access

This commit is contained in:
Andreas Nedbal 2024-01-27 13:04:29 +01:00 committed by Andreas Nedbal
parent ba7ba359b4
commit 658cb0442b
12 changed files with 39 additions and 39 deletions

View File

@ -44,8 +44,8 @@ class Ajax::InboxController < AjaxController
def remove_all_author def remove_all_author
begin 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.inboxes.joins(:question) @inbox = current_user.inbox_entries.joins(:question)
.where(questions: { user_id: @target_user.id, author_is_anonymous: false }) .where(questions: { user_id: @target_user.id, author_is_anonymous: false })
@inbox.each { |i| i.remove } @inbox.each { |i| i.remove }
rescue => e rescue => e
Sentry.capture_exception(e) Sentry.capture_exception(e)

View File

@ -20,8 +20,8 @@ class AnonymousBlockController < ApplicationController
target_user: question.user target_user: question.user
) )
inbox_id = question.inboxes.first&.id inbox_id = question.inbox_entries.first&.id
question.inboxes.first&.destroy question.inbox_entries.first&.destroy
respond_to do |format| respond_to do |format|
format.turbo_stream do format.turbo_stream do

View File

@ -8,7 +8,7 @@ class Moderation::InboxController < ApplicationController
@inboxes = @user.cursored_inbox(last_id: params[:last_id]) @inboxes = @user.cursored_inbox(last_id: params[:last_id])
@inbox_last_id = @inboxes.map(&:id).min @inbox_last_id = @inboxes.map(&:id).min
@more_data_available = !@user.cursored_inbox(last_id: @inbox_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_inbox(last_id: @inbox_last_id, size: 1).count.zero?
@inbox_count = @user.inboxes.count @inbox_count = @user.inbox_entries.count
respond_to do |format| respond_to do |format|
format.html format.html

View File

@ -24,7 +24,7 @@ class InboxFilter
def results def results
return InboxEntry.none unless valid_params? return InboxEntry.none unless valid_params?
scope = @user.inboxes scope = @user.inbox_entries
.includes(:question, user: :profile) .includes(:question, user: :profile)
.order(:created_at) .order(:created_at)
.reverse_order .reverse_order
@ -45,10 +45,10 @@ class InboxFilter
def scope_for(key, value) def scope_for(key, value)
case key.to_s case key.to_s
when "author" when "author"
@user.inboxes.joins(question: [:user]) @user.inbox_entries.joins(question: [:user])
.where(questions: { users: { screen_name: value }, author_is_anonymous: false }) .where(questions: { users: { screen_name: value }, author_is_anonymous: false })
when "anonymous" when "anonymous"
@user.inboxes.joins(:question) @user.inbox_entries.joins(:question)
.where(questions: { author_is_anonymous: true }) .where(questions: { author_is_anonymous: true })
end end
end end

View File

@ -5,9 +5,9 @@ module User::InboxMethods
define_cursor_paginator :cursored_inbox, :ordered_inbox define_cursor_paginator :cursored_inbox, :ordered_inbox
# @return [ActiveRecord::Relation<Inbox>] the user's inbox entries # @return [ActiveRecord::Relation<InboxEntry>] the user's inbox entries
def ordered_inbox def ordered_inbox
inboxes inbox_entries
.includes(:question, user: :profile) .includes(:question, user: :profile)
.order(:created_at) .order(:created_at)
.reverse_order .reverse_order

View File

@ -53,8 +53,8 @@ class User
def unfollow_and_remove(target_user) def unfollow_and_remove(target_user)
unfollow(target_user) if following?(target_user) unfollow(target_user) if following?(target_user)
target_user.unfollow(self) if target_user.following?(self) target_user.unfollow(self) if target_user.following?(self)
target_user.inboxes.joins(:question).where(question: { user_id: id }).destroy_all target_user.inbox_entries.joins(:question).where(question: { user_id: id }).destroy_all
inboxes.joins(:question).where(questions: { user_id: target_user.id, author_is_anonymous: false }).destroy_all inbox_entries.joins(:question).where(questions: { user_id: target_user.id, author_is_anonymous: false }).destroy_all
ListMember.joins(:list).where(list: { user_id: target_user.id }, user_id: id).destroy_all ListMember.joins(:list).where(list: { user_id: target_user.id }, user_id: id).destroy_all
end end

View File

@ -34,7 +34,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
end end
it "removes the inbox entry" do it "removes the inbox entry" do
expect { subject }.to(change { user.inboxes.count }.by(-1)) expect { subject }.to(change { user.inbox_entries.count }.by(-1))
expect { InboxEntry.find(inbox_entry.id) }.to raise_error(ActiveRecord::RecordNotFound) expect { InboxEntry.find(inbox_entry.id) }.to raise_error(ActiveRecord::RecordNotFound)
end end
@ -52,8 +52,8 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
end end
it "does not remove the inbox entry" do it "does not remove the inbox entry" do
expect { subject }.not_to(change { Inbox.count }) expect { subject }.not_to(change { InboxEntry.count })
expect { Inbox.find(inbox_entry.id) }.not_to raise_error expect { InboxEntry.find(inbox_entry.id) }.not_to raise_error
end end
include_examples "returns the expected response" include_examples "returns the expected response"
@ -107,8 +107,8 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
context "when user has some inbox entries" do context "when user has some inbox entries" do
let(:some_other_user) { FactoryBot.create(:user) } let(:some_other_user) { FactoryBot.create(:user) }
before do before do
10.times { FactoryBot.create(:inbox, user: user) } 10.times { FactoryBot.create(:inbox_entry, user: user) }
10.times { FactoryBot.create(:inbox, user: some_other_user) } 10.times { FactoryBot.create(:inbox_entry, user: some_other_user) }
end end
it "deletes all the entries from the user's inbox" do it "deletes all the entries from the user's inbox" do
@ -162,13 +162,13 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
normal_question = FactoryBot.create(:question, user: some_other_user, author_is_anonymous: false) 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) anon_question = FactoryBot.create(:question, user: some_other_user, author_is_anonymous: true)
10.times { FactoryBot.create(:inbox, user: user) } 10.times { FactoryBot.create(:inbox_entry, user: user) }
3.times { FactoryBot.create(:inbox, user: user, question: normal_question) } 3.times { FactoryBot.create(:inbox_entry, user: user, question: normal_question) }
2.times { FactoryBot.create(:inbox, user: user, question: anon_question) } 2.times { FactoryBot.create(:inbox_entry, user: user, question: anon_question) }
end end
it "deletes all the entries asked by some other user which are not anonymous from the user's inbox" do it "deletes all the entries asked by some other user which are not anonymous from the user's inbox" do
expect { subject }.to(change { user.inboxes.count }.from(15).to(12)) expect { subject }.to(change { user.inbox_entries.count }.from(15).to(12))
end end
include_examples "returns the expected response" include_examples "returns the expected response"

View File

@ -14,8 +14,8 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
if check_for_inbox if check_for_inbox
it "adds the question to the target users' inbox" do it "adds the question to the target users' inbox" do
expect { subject }.to(change { target_user.inboxes.count }.by(1)) expect { subject }.to(change { target_user.inbox_entries.count }.by(1))
expect(target_user.inboxes.last.question.content).to eq(question_content) expect(target_user.inbox_entries.last.question.content).to eq(question_content)
end end
end end
@ -29,7 +29,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
if check_for_inbox if check_for_inbox
it "does not add the question to the target users' inbox" do it "does not add the question to the target users' inbox" do
expect { subject }.not_to(change { target_user.inboxes.count }) expect { subject }.not_to(change { target_user.inbox_entries.count })
end end
end end
@ -42,7 +42,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
end end
it "does not add the question to the target users' inbox" do it "does not add the question to the target users' inbox" do
expect { subject }.not_to(change { target_user.inboxes.count }) expect { subject }.not_to(change { target_user.inbox_entries.count })
end end
include_examples "returns the expected response" include_examples "returns the expected response"

View File

@ -131,7 +131,7 @@ describe InboxController, type: :controller do
let!(:unrelated_user) { FactoryBot.create(:user) } let!(:unrelated_user) { FactoryBot.create(:user) }
let!(:generic_inbox_entry1) do let!(:generic_inbox_entry1) do
Inbox.create( InboxEntry.create(
user:, user:,
question: FactoryBot.create( question: FactoryBot.create(
:question, :question,
@ -140,7 +140,7 @@ describe InboxController, type: :controller do
), ),
) )
end end
let!(:generic_inbox_entry2) { Inbox.create(user:, question: FactoryBot.create(:question)) } let!(:generic_inbox_entry2) { InboxEntry.create(user:, question: FactoryBot.create(:question)) }
subject { get :show, params: { author: author_param } } subject { get :show, params: { author: author_param } }
@ -163,7 +163,7 @@ describe InboxController, type: :controller do
context "with no non-anonymous questions from the other user in the inbox" do context "with no non-anonymous questions from the other user in the inbox" do
let!(:anonymous_inbox_entry) do let!(:anonymous_inbox_entry) do
Inbox.create( InboxEntry.create(
user:, user:,
question: FactoryBot.create( question: FactoryBot.create(
:question, :question,
@ -188,7 +188,7 @@ describe InboxController, type: :controller do
context "with both non-anonymous and anonymous questions from the other user in the inbox" do context "with both non-anonymous and anonymous questions from the other user in the inbox" do
let!(:non_anonymous_inbox_entry) do let!(:non_anonymous_inbox_entry) do
Inbox.create( InboxEntry.create(
user:, user:,
question: FactoryBot.create( question: FactoryBot.create(
:question, :question,
@ -198,7 +198,7 @@ describe InboxController, type: :controller do
) )
end end
let!(:anonymous_inbox_entry) do let!(:anonymous_inbox_entry) do
Inbox.create( InboxEntry.create(
user:, user:,
question: FactoryBot.create( question: FactoryBot.create(
:question, :question,
@ -227,7 +227,7 @@ describe InboxController, type: :controller do
context "when passed the anonymous param" do context "when passed the anonymous param" do
let!(:other_user) { FactoryBot.create(:user) } let!(:other_user) { FactoryBot.create(:user) }
let!(:generic_inbox_entry) do let!(:generic_inbox_entry) do
Inbox.create( InboxEntry.create(
user:, user:,
question: FactoryBot.create( question: FactoryBot.create(
:question, :question,
@ -239,7 +239,7 @@ describe InboxController, type: :controller do
let!(:inbox_entry_fillers) do let!(:inbox_entry_fillers) do
# 9 times => 1 entry less than default page size # 9 times => 1 entry less than default page size
9.times.map { Inbox.create(user:, question: FactoryBot.create(:question, author_is_anonymous: true)) } 9.times.map { InboxEntry.create(user:, question: FactoryBot.create(:question, author_is_anonymous: true)) }
end end
subject { get :show, params: { anonymous: true } } subject { get :show, params: { anonymous: true } }
@ -258,7 +258,7 @@ describe InboxController, type: :controller do
context "when passed the anonymous and the author param" do context "when passed the anonymous and the author param" do
let!(:other_user) { FactoryBot.create(:user) } let!(:other_user) { FactoryBot.create(:user) }
let!(:generic_inbox_entry) do let!(:generic_inbox_entry) do
Inbox.create( InboxEntry.create(
user:, user:,
question: FactoryBot.create( question: FactoryBot.create(
:question, :question,
@ -270,7 +270,7 @@ describe InboxController, type: :controller do
let!(:inbox_entry_fillers) do let!(:inbox_entry_fillers) do
# 9 times => 1 entry less than default page size # 9 times => 1 entry less than default page size
9.times.map { Inbox.create(user:, question: FactoryBot.create(:question, author_is_anonymous: true)) } 9.times.map { InboxEntry.create(user:, question: FactoryBot.create(:question, author_is_anonymous: true)) }
end end
subject { get :show, params: { anonymous: true, author: "some_name" } } subject { get :show, params: { anonymous: true, author: "some_name" } }
@ -299,7 +299,7 @@ describe InboxController, type: :controller do
before(:each) { sign_in(user) } before(:each) { sign_in(user) }
it "creates an inbox entry" do it "creates an inbox entry" do
expect { subject }.to(change { user.inboxes.count }.by(1)) expect { subject }.to(change { user.inbox_entries.count }.by(1))
end end
include_examples "touches user timestamp", :inbox_updated_at include_examples "touches user timestamp", :inbox_updated_at

View File

@ -23,9 +23,9 @@ describe UseCase::Question::Create do
expect(question.direct).to eq(true) expect(question.direct).to eq(true)
if should_send_to_inbox if should_send_to_inbox
expect(target_user.inboxes.first.question_id).to eq(question.id) expect(target_user.inbox_entries.first.question_id).to eq(question.id)
else else
expect(target_user.inboxes.first).to be_nil expect(target_user.inbox_entries.first).to be_nil
end end
end end
end end

View File

@ -27,7 +27,7 @@ describe Answer, type: :model do
end end
it "should remove the question from the user's inbox" do it "should remove the question from the user's inbox" do
expect { subject.save }.to change { user.inboxes.count }.by(-1) expect { subject.save }.to change { user.inbox_entries.count }.by(-1)
end end
end end

View File

@ -4,7 +4,7 @@ require "rails_helper"
describe Scheduler::InboxCleanupScheduler do describe Scheduler::InboxCleanupScheduler do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:inbox) { FactoryBot.create(:inbox, user:) } let(:inbox) { FactoryBot.create(:inbox_entry, user:) }
describe "#perform" do describe "#perform" do
before do before do