From d33b1f6b29651c7e8a021ab37f8659054df4881f Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 19 Jun 2019 16:56:31 +0200 Subject: [PATCH] Pass the models, not the ids, when dealing with friendships --- app/controllers/users_controller.rb | 2 +- app/models/user.rb | 2 +- test/controllers/users_controller_test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d8e8f6d3a..1ec9ab8d8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -417,7 +417,7 @@ class UsersController < ApplicationController if @friend if request.post? if current_user.is_friends_with?(@friend) - Friendship.where(:user_id => current_user.id, :friend_user_id => @friend.id).delete_all + Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all flash[:notice] = t "users.remove_friend.success", :name => @friend.display_name else flash[:error] = t "users.remove_friend.not_a_friend", :name => @friend.display_name diff --git a/app/models/user.rb b/app/models/user.rb index 284efe34e..1d0089599 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -224,7 +224,7 @@ class User < ActiveRecord::Base end def is_friends_with?(new_friend) - friendships.where(:friend_user_id => new_friend.id).exists? + friendships.where(:befriendee => new_friend).exists? end ## diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 9b7e0408d..298eb9d6d 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1244,7 +1244,7 @@ class UsersControllerTest < ActionController::TestCase # Get users to work with user = create(:user) friend = create(:user) - create(:friendship, :user_id => user.id, :friend_user_id => friend.id) + create(:friendship, :befriender => user, :befriendee => friend) # Check that the users are friends assert Friendship.where(:user_id => user.id, :friend_user_id => friend.id).first -- 2.43.2