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
begin
@target_user = User.where('LOWER(screen_name) = ?', params[:author].downcase).first!
@inbox = current_user.inboxes.joins(:question)
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
@inbox = current_user.inbox_entries.joins(:question)
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
@inbox.each { |i| i.remove }
rescue => e
Sentry.capture_exception(e)

View file

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

View file

@ -8,7 +8,7 @@ class Moderation::InboxController < ApplicationController
@inboxes = @user.cursored_inbox(last_id: params[:last_id])
@inbox_last_id = @inboxes.map(&:id).min
@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|
format.html

View file

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

View file

@ -5,9 +5,9 @@ module User::InboxMethods
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
inboxes
inbox_entries
.includes(:question, user: :profile)
.order(:created_at)
.reverse_order

View file

@ -53,8 +53,8 @@ class User
def unfollow_and_remove(target_user)
unfollow(target_user) if following?(target_user)
target_user.unfollow(self) if target_user.following?(self)
target_user.inboxes.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
target_user.inbox_entries.joins(:question).where(question: { user_id: id }).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
end

View file

@ -34,7 +34,7 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
end
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)
end
@ -52,8 +52,8 @@ describe Ajax::InboxController, :ajax_controller, type: :controller do
end
it "does not remove the inbox entry" do
expect { subject }.not_to(change { Inbox.count })
expect { Inbox.find(inbox_entry.id) }.not_to raise_error
expect { subject }.not_to(change { InboxEntry.count })
expect { InboxEntry.find(inbox_entry.id) }.not_to raise_error
end
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
let(:some_other_user) { FactoryBot.create(:user) }
before do
10.times { FactoryBot.create(:inbox, user: user) }
10.times { FactoryBot.create(:inbox, user: some_other_user) }
10.times { FactoryBot.create(:inbox_entry, user: user) }
10.times { FactoryBot.create(:inbox_entry, user: some_other_user) }
end
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)
anon_question = FactoryBot.create(:question, user: some_other_user, author_is_anonymous: true)
10.times { FactoryBot.create(:inbox, user: user) }
3.times { FactoryBot.create(:inbox, user: user, question: normal_question) }
2.times { FactoryBot.create(:inbox, user: user, question: anon_question) }
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) }
end
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
include_examples "returns the expected response"

View file

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

View file

@ -131,7 +131,7 @@ describe InboxController, type: :controller do
let!(:unrelated_user) { FactoryBot.create(:user) }
let!(:generic_inbox_entry1) do
Inbox.create(
InboxEntry.create(
user:,
question: FactoryBot.create(
:question,
@ -140,7 +140,7 @@ describe InboxController, type: :controller do
),
)
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 } }
@ -163,7 +163,7 @@ describe InboxController, type: :controller do
context "with no non-anonymous questions from the other user in the inbox" do
let!(:anonymous_inbox_entry) do
Inbox.create(
InboxEntry.create(
user:,
question: FactoryBot.create(
: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
let!(:non_anonymous_inbox_entry) do
Inbox.create(
InboxEntry.create(
user:,
question: FactoryBot.create(
:question,
@ -198,7 +198,7 @@ describe InboxController, type: :controller do
)
end
let!(:anonymous_inbox_entry) do
Inbox.create(
InboxEntry.create(
user:,
question: FactoryBot.create(
:question,
@ -227,7 +227,7 @@ describe InboxController, type: :controller do
context "when passed the anonymous param" do
let!(:other_user) { FactoryBot.create(:user) }
let!(:generic_inbox_entry) do
Inbox.create(
InboxEntry.create(
user:,
question: FactoryBot.create(
:question,
@ -239,7 +239,7 @@ describe InboxController, type: :controller do
let!(:inbox_entry_fillers) do
# 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
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
let!(:other_user) { FactoryBot.create(:user) }
let!(:generic_inbox_entry) do
Inbox.create(
InboxEntry.create(
user:,
question: FactoryBot.create(
:question,
@ -270,7 +270,7 @@ describe InboxController, type: :controller do
let!(:inbox_entry_fillers) do
# 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
subject { get :show, params: { anonymous: true, author: "some_name" } }
@ -299,7 +299,7 @@ describe InboxController, type: :controller do
before(:each) { sign_in(user) }
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
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)
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
expect(target_user.inboxes.first).to be_nil
expect(target_user.inbox_entries.first).to be_nil
end
end
end

View file

@ -27,7 +27,7 @@ describe Answer, type: :model do
end
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

View file

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