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

View File

@ -10,14 +10,14 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
describe "#create" do describe "#create" do
let(:params) do let(:params) do
{ {
id: id, id:,
answer: answer, answer:,
share: shared_services&.to_json, share: shared_services&.to_json,
inbox: inbox inbox:
}.compact }.compact
end end
subject { post(:create, params: params) } subject { post(:create, params:) }
context "when user is signed in" do context "when user is signed in" do
shared_examples "creates the answer" do shared_examples "creates the answer" do
@ -73,7 +73,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:shared_services) { %w[twitter] } let(:shared_services) { %w[twitter] }
context "when inbox is true" do 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 } let(:inbox) { true }
context "when the inbox entry belongs to the user" do context "when the inbox entry belongs to the user" do
@ -237,7 +237,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
describe "#destroy" do describe "#destroy" do
let(:answer_user) { user } let(:answer_user) { user }
let(:question) { FactoryBot.create(:question) } 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(:answer_id) { answer.id }
let(:params) do let(:params) do
@ -246,7 +246,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
} }
end end
subject { delete(:destroy, params: params) } subject { delete(:destroy, params:) }
context "when user is signed in" do context "when user is signed in" do
shared_examples "deletes the answer" do shared_examples "deletes the answer" do

View File

@ -10,11 +10,11 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:params) do let(:params) do
{ {
answer: answer_id, answer: answer_id,
comment: comment comment:
}.compact }.compact
end end
subject { post(:create, params: params) } subject { post(:create, params:) }
context "when user is signed in" do context "when user is signed in" do
shared_examples "creates the comment" do shared_examples "creates the comment" do
@ -175,7 +175,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:answer_user) { FactoryBot.create(:user) } let(:answer_user) { FactoryBot.create(:user) }
let(:answer) { FactoryBot.create(:answer, user: answer_user) } let(:answer) { FactoryBot.create(:answer, user: answer_user) }
let(:comment_user) { 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(:comment_id) { comment.id }
let(:params) do let(:params) do
@ -184,7 +184,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
} }
end end
subject { delete(:destroy, params: params) } subject { delete(:destroy, params:) }
context "when user is signed in" do context "when user is signed in" do
shared_examples "deletes the comment" do shared_examples "deletes the comment" do