From 6693864fbc41a14e143c9c231384811bbaa983b4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Fri, 19 Aug 2022 04:25:33 +0200 Subject: [PATCH] Move `belongs_to_current_user?` to UserController --- app/controllers/user_controller.rb | 4 ++++ app/helpers/user_helper.rb | 4 ---- spec/helpers/user_helper_spec.rb | 27 --------------------------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 8287c90c..888321e6 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -63,4 +63,8 @@ class UserController < ApplicationController format.js { render layout: false } end end + + private + + def belongs_to_current_user? = @user == current_user end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index 903017a5..b0532faf 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -21,10 +21,6 @@ module UserHelper current_user&.mod? && session[:moderation_view] == true end - def belongs_to_current_user? - @user == current_user - end - private def profile_link(user) diff --git a/spec/helpers/user_helper_spec.rb b/spec/helpers/user_helper_spec.rb index 397d641b..1187070a 100644 --- a/spec/helpers/user_helper_spec.rb +++ b/spec/helpers/user_helper_spec.rb @@ -149,31 +149,4 @@ describe UserHelper, type: :helper do end end end - - describe "#belongs_to_current_user?" do - context "user is logged in" do - let(:user) { FactoryBot.create(:user) } - - before do - sign_in user - @user = user - end - - it "returns the correct value" do - expect(helper.belongs_to_current_user?).to eq(true) - end - end - - context "user is not logged in" do - let(:user) { FactoryBot.create(:user) } - - before do - @user = user - end - - it "returns the correct value" do - expect(helper.belongs_to_current_user?).to eq(false) - end - end - end end