Rubocop fixes

This commit is contained in:
Daniel O'Connor
2026-04-26 13:09:00 +00:00
parent 3406d9e7bc
commit 8cfef5ce1a
8 changed files with 21 additions and 18 deletions

View File

@@ -12,7 +12,7 @@ class BlocksController < ApplicationController
else
flash[:error] = "Already blocking or error while blocking."
end
redirect_back fallback_location: root_path
redirect_back_or_to(root_path)
end
def destroy

View File

@@ -39,7 +39,7 @@ class MessagesController < ApplicationController
recipient = Member.find(params[:recipient_id])
if recipient.already_blocking?(current_member)
flash[:error] = "You cannot send a message to a member who has blocked you."
redirect_back fallback_location: root_path
redirect_back_or_to(root_path)
return
end
body = params[:body]

View File

@@ -31,8 +31,9 @@ class Comment < ApplicationRecord
def author_is_not_blocked
return unless author
if commentable.author.already_blocking?(author)
errors.add(:base, "You cannot comment on a post of a member who has blocked you.")
end
return unless commentable.author.already_blocking?(author)
errors.add(:base, "You cannot comment on a post of a member who has blocked you.")
end
end

View File

@@ -20,8 +20,9 @@ class Follow < ApplicationRecord
def follower_is_not_blocked
return unless follower
if followed.already_blocking?(follower)
errors.add(:base, "You cannot follow a member who has blocked you.")
end
return unless followed.already_blocking?(follower)
errors.add(:base, "You cannot follow a member who has blocked you.")
end
end

View File

@@ -19,9 +19,10 @@ class Like < ApplicationRecord
def member_is_not_blocked
return unless member
author = likeable_author
if author && author.already_blocking?(member)
errors.add(:base, "You cannot like content of a member who has blocked you.")
end
return unless author&.already_blocking?(member)
errors.add(:base, "You cannot like content of a member who has blocked you.")
end
end

View File

@@ -8,6 +8,6 @@ class CreateBlocks < ActiveRecord::Migration[6.1]
t.timestamps
end
add_index :blocks, [:blocker_id, :blocked_id], unique: true
add_index :blocks, %i(blocker_id blocked_id), unique: true
end
end

View File

@@ -49,9 +49,9 @@ describe ForumsController do
let(:valid_attributes) { { name: "New Forum", description: "A new forum", owner_id: admin.id } }
it "creates a new Forum" do
expect {
expect do
post :create, params: { forum: valid_attributes }
}.to change(Forum, :count).by(1)
end.to change(Forum, :count).by(1)
end
it "redirects to the created forum" do
@@ -81,9 +81,9 @@ describe ForumsController do
describe "DELETE #destroy" do
it "destroys the requested forum" do
forum # ensure forum exists
expect {
expect do
delete :destroy, params: { id: forum.to_param }
}.to change(Forum, :count).by(-1)
end.to change(Forum, :count).by(-1)
end
it "redirects to the forums list" do

View File

@@ -37,9 +37,9 @@ describe "Forums" do
before { sign_in admin }
it "creates a new forum" do
expect {
expect do
post forums_path, params: { forum: { name: "New Request Forum", description: "Desc", owner_id: admin.id } }
}.to change(Forum, :count).by(1)
end.to change(Forum, :count).by(1)
expect(response).to redirect_to(forum_path(Forum.last))
end
end