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

@ -9,13 +9,13 @@ class User
included do
has_many :active_mute_relationships, class_name: "Relationships::Mute",
foreign_key: "source_id",
dependent: :destroy
foreign_key: "source_id",
dependent: :destroy
has_many :passive_mute_relationships, class_name: "Relationships::Mute",
foreign_key: "target_id",
dependent: :destroy
foreign_key: "target_id",
dependent: :destroy
has_many :muted_users, through: :active_mute_relationships, source: :target
has_many :muted_by_users, through: :passive_mute_relationships, source: :source
has_many :muted_by_users, through: :passive_mute_relationships, source: :source
end
def mute(target_user)

View File

@ -10,14 +10,14 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
describe "#create" do
let(:params) do
{
id: id,
answer: answer,
share: shared_services&.to_json,
inbox: inbox
id:,
answer:,
share: shared_services&.to_json,
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
@ -53,7 +53,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
{
"success" => false,
# caught by rescue_from, so status is not peter_dinklage
"status" => "parameter_error",
"status" => "parameter_error",
"message" => anything
}
end
@ -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
@ -81,7 +81,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything
}
end
@ -96,7 +96,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "fail",
"status" => "fail",
"message" => anything
}
end
@ -111,7 +111,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything
}
end
@ -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
@ -139,9 +139,9 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything,
"render" => anything
"render" => anything
}
end
@ -155,7 +155,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "privacy_stronk",
"status" => "privacy_stronk",
"message" => anything
}
end
@ -207,7 +207,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
{
"success" => false,
# caught by rescue_from, so status is not peter_dinklage
"status" => "parameter_error",
"status" => "parameter_error",
"message" => anything
}
end
@ -225,7 +225,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "err",
"status" => "err",
"message" => anything
}
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,14 +246,14 @@ 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
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything
}
end
@ -270,7 +270,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "nopriv",
"status" => "nopriv",
"message" => anything
}
end
@ -322,7 +322,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => anything,
"status" => anything,
"message" => anything
}
end
@ -335,7 +335,7 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "nopriv",
"status" => "nopriv",
"message" => anything
}
end

View File

@ -9,12 +9,12 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
describe "#create" do
let(:params) do
{
answer: answer_id,
comment: comment
answer: answer_id,
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
@ -45,10 +45,10 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything,
"render" => anything,
"count" => 1
"render" => anything,
"count" => 1
}
end
@ -59,7 +59,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "rec_inv",
"status" => "rec_inv",
"message" => anything
}
end
@ -109,17 +109,17 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything,
"render" => anything,
"count" => 1
"render" => anything,
"count" => 1
}
end
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
@ -130,7 +130,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => anything,
"status" => anything,
"message" => anything
}
end
@ -146,7 +146,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "parameter_error",
"status" => "parameter_error",
"message" => anything
}
end
@ -162,7 +162,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "err",
"status" => "err",
"message" => anything
}
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,16 +184,16 @@ 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
let(:expected_response) do
{
"success" => true,
"status" => "okay",
"status" => "okay",
"message" => anything,
"count" => 0
"count" => 0
}
end
@ -209,7 +209,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "nopriv",
"status" => "nopriv",
"message" => anything
}
end
@ -258,7 +258,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => anything,
"status" => anything,
"message" => anything
}
end
@ -271,7 +271,7 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:expected_response) do
{
"success" => false,
"status" => "nopriv",
"status" => "nopriv",
"message" => anything
}
end