Appease the dog overlords

This commit is contained in:
Andreas Nedbal 2022-12-29 05:17:04 +01:00 committed by Andreas Nedbal
parent 7afff7884e
commit 6a03d3587a
4 changed files with 53 additions and 55 deletions

View File

@ -11,11 +11,11 @@ class Notification < ApplicationRecord
define_cursor_paginator :cursored_for_type, :for_type
def for(recipient, **kwargs)
where(kwargs.merge!(recipient: recipient)).order(:created_at).reverse_order
where(kwargs.merge!(recipient:)).order(:created_at).reverse_order
end
def for_type(recipient, type, **kwargs)
where(kwargs.merge!(recipient: recipient)).where(type: type).order(:created_at).reverse_order
where(kwargs.merge!(recipient:)).where(type:).order(:created_at).reverse_order
end
def notify(recipient, target)
@ -34,7 +34,7 @@ class Notification < ApplicationRecord
notif_type = target.notification_type
return nil unless notif_type
notif = Notification.find_by(recipient: recipient, target: target)
notif = Notification.find_by(recipient:, target:)
notif&.destroy
end
@ -43,8 +43,8 @@ class Notification < ApplicationRecord
def make_notification(recipient, target, notification_type)
return if get_notification_owner(target).present? && recipient.muting?(get_notification_owner(target))
n = notification_type.new(target: target,
recipient: recipient,
n = notification_type.new(target:,
recipient:,
new: true)
n.save!
n
@ -57,8 +57,6 @@ class Notification < ApplicationRecord
target.user
elsif target.try(:source) && target.source.is_a?(User)
target.source
else
nil
end
end
end

View File

@ -10,14 +10,14 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
describe "#create" do
let(:params) do
{
id: id,
answer: answer,
id:,
answer:,
share: shared_services&.to_json,
inbox: inbox
inbox:
}.compact
end
subject { post(:create, params: params) }
subject { post(:create, params:) }
context "when user is signed in" do
shared_examples "creates the answer" do
@ -73,7 +73,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: question).id }
let(:id) { FactoryBot.create(:inbox, user: inbox_user, question:).id }
let(:inbox) { true }
context "when the inbox entry belongs to the user" do
@ -125,7 +125,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
it_behaves_like "fails when answer content is empty"
it "does not create a notification for the question author" do
expect{ subject }.to change { question.user.notifications.count }.by(0)
expect { subject }.to change { question.user.notifications.count }.by(0)
end
end
end
@ -237,7 +237,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
describe "#destroy" do
let(:answer_user) { user }
let(:question) { FactoryBot.create(:question) }
let(:answer) { FactoryBot.create(:answer, user: answer_user, question: question) }
let(:answer) { FactoryBot.create(:answer, user: answer_user, question:) }
let(:answer_id) { answer.id }
let(:params) do
@ -246,7 +246,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
}
end
subject { delete(:destroy, params: params) }
subject { delete(:destroy, params:) }
context "when user is signed in" do
shared_examples "deletes the answer" do

View File

@ -10,11 +10,11 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:params) do
{
answer: answer_id,
comment: comment
comment:
}.compact
end
subject { post(:create, params: params) }
subject { post(:create, params:) }
context "when user is signed in" do
shared_examples "creates the comment" do
@ -119,7 +119,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
include_examples "creates the comment"
it "does not create a notification for the author" do
expect{ subject }.to change { answer.user.notifications.count }.by(0)
expect { subject }.to change { answer.user.notifications.count }.by(0)
end
end
end
@ -175,7 +175,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:answer_user) { FactoryBot.create(:user) }
let(:answer) { FactoryBot.create(:answer, user: answer_user) }
let(:comment_user) { user }
let(:comment) { FactoryBot.create(:comment, user: comment_user, answer: answer) }
let(:comment) { FactoryBot.create(:comment, user: comment_user, answer:) }
let(:comment_id) { comment.id }
let(:params) do
@ -184,7 +184,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
}
end
subject { delete(:destroy, params: params) }
subject { delete(:destroy, params:) }
context "when user is signed in" do
shared_examples "deletes the comment" do