]> git.openstreetmap.org Git - rails.git/commitdiff
Pass the models, not the ids, when dealing with friendships
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 19 Jun 2019 14:56:31 +0000 (16:56 +0200)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 19 Jun 2019 14:56:31 +0000 (16:56 +0200)
app/controllers/users_controller.rb
app/models/user.rb
test/controllers/users_controller_test.rb

index d8e8f6d3a41da6485f2408c01c385e8411ac468b..1ec9ab8d8573412fdaf533a27bbd0b35597061a6 100644 (file)
@@ -417,7 +417,7 @@ class UsersController < ApplicationController
     if @friend
       if request.post?
         if current_user.is_friends_with?(@friend)
     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
           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
index 284efe34e17e55fc5be657ffbd1e4b5362d82308..1d008959905e85a50428c0433c04dbe16799d8a8 100644 (file)
@@ -224,7 +224,7 @@ class User < ActiveRecord::Base
   end
 
   def is_friends_with?(new_friend)
   end
 
   def is_friends_with?(new_friend)
-    friendships.where(:friend_user_id => new_friend.id).exists?
+    friendships.where(:befriendee => new_friend).exists?
   end
 
   ##
   end
 
   ##
index 9b7e0408de99f48f42968c0961daeddf67dc7c90..298eb9d6d4fc71b9527b78de62f8eb5ed06c9b3c 100644 (file)
@@ -1244,7 +1244,7 @@ class UsersControllerTest < ActionController::TestCase
     # Get users to work with
     user = create(:user)
     friend = create(:user)
     # 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
 
     # Check that the users are friends
     assert Friendship.where(:user_id => user.id, :friend_user_id => friend.id).first