From 658cb0442b3d067c8dd786b81c360c45fca829f3 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 27 Jan 2024 13:04:29 +0100 Subject: [PATCH] Rename all occurences of associative inbox entry access --- app/controllers/ajax/inbox_controller.rb | 4 ++-- app/controllers/anonymous_block_controller.rb | 4 ++-- .../moderation/inbox_controller.rb | 2 +- app/models/inbox_filter.rb | 6 +++--- app/models/user/inbox_methods.rb | 4 ++-- app/models/user/relationship/block.rb | 4 ++-- .../controllers/ajax/inbox_controller_spec.rb | 18 ++++++++--------- .../ajax/question_controller_spec.rb | 8 ++++---- spec/controllers/inbox_controller_spec.rb | 20 +++++++++---------- spec/lib/use_case/question/create_spec.rb | 4 ++-- spec/models/answer_spec.rb | 2 +- .../scheduler/inbox_cleanup_scheduler_spec.rb | 2 +- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index 70c4e7c2..2a7c67a4 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -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) diff --git a/app/controllers/anonymous_block_controller.rb b/app/controllers/anonymous_block_controller.rb index a8c9a32f..2d0ce4fc 100644 --- a/app/controllers/anonymous_block_controller.rb +++ b/app/controllers/anonymous_block_controller.rb @@ -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 diff --git a/app/controllers/moderation/inbox_controller.rb b/app/controllers/moderation/inbox_controller.rb index 5cbb8a80..80aa94f5 100644 --- a/app/controllers/moderation/inbox_controller.rb +++ b/app/controllers/moderation/inbox_controller.rb @@ -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 diff --git a/app/models/inbox_filter.rb b/app/models/inbox_filter.rb index ab812fa7..f649bb3e 100644 --- a/app/models/inbox_filter.rb +++ b/app/models/inbox_filter.rb @@ -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 diff --git a/app/models/user/inbox_methods.rb b/app/models/user/inbox_methods.rb index e6dca73b..b5efab58 100644 --- a/app/models/user/inbox_methods.rb +++ b/app/models/user/inbox_methods.rb @@ -5,9 +5,9 @@ module User::InboxMethods define_cursor_paginator :cursored_inbox, :ordered_inbox - # @return [ActiveRecord::Relation] the user's inbox entries + # @return [ActiveRecord::Relation] the user's inbox entries def ordered_inbox - inboxes + inbox_entries .includes(:question, user: :profile) .order(:created_at) .reverse_order diff --git a/app/models/user/relationship/block.rb b/app/models/user/relationship/block.rb index 01cd25ed..03639cf2 100644 --- a/app/models/user/relationship/block.rb +++ b/app/models/user/relationship/block.rb @@ -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 diff --git a/spec/controllers/ajax/inbox_controller_spec.rb b/spec/controllers/ajax/inbox_controller_spec.rb index 64e669cb..074a92ae 100644 --- a/spec/controllers/ajax/inbox_controller_spec.rb +++ b/spec/controllers/ajax/inbox_controller_spec.rb @@ -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" diff --git a/spec/controllers/ajax/question_controller_spec.rb b/spec/controllers/ajax/question_controller_spec.rb index 9575576f..077ace60 100644 --- a/spec/controllers/ajax/question_controller_spec.rb +++ b/spec/controllers/ajax/question_controller_spec.rb @@ -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" diff --git a/spec/controllers/inbox_controller_spec.rb b/spec/controllers/inbox_controller_spec.rb index 3ebefd1b..689a70ae 100644 --- a/spec/controllers/inbox_controller_spec.rb +++ b/spec/controllers/inbox_controller_spec.rb @@ -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 diff --git a/spec/lib/use_case/question/create_spec.rb b/spec/lib/use_case/question/create_spec.rb index a1831771..a31e9073 100644 --- a/spec/lib/use_case/question/create_spec.rb +++ b/spec/lib/use_case/question/create_spec.rb @@ -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 diff --git a/spec/models/answer_spec.rb b/spec/models/answer_spec.rb index f09759a9..7443c54d 100644 --- a/spec/models/answer_spec.rb +++ b/spec/models/answer_spec.rb @@ -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 diff --git a/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb b/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb index 92f335bc..775cdba7 100644 --- a/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb +++ b/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb @@ -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