Pass the models, not the ids, when dealing with friendships
This commit is contained in:
parent
2169c503ef
commit
d33b1f6b29
3 changed files with 3 additions and 3 deletions
|
@ -417,7 +417,7 @@ class UsersController < ApplicationController
|
||||||
if @friend
|
if @friend
|
||||||
if request.post?
|
if request.post?
|
||||||
if current_user.is_friends_with?(@friend)
|
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
|
flash[:notice] = t "users.remove_friend.success", :name => @friend.display_name
|
||||||
else
|
else
|
||||||
flash[:error] = t "users.remove_friend.not_a_friend", :name => @friend.display_name
|
flash[:error] = t "users.remove_friend.not_a_friend", :name => @friend.display_name
|
||||||
|
|
|
@ -224,7 +224,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_friends_with?(new_friend)
|
def is_friends_with?(new_friend)
|
||||||
friendships.where(:friend_user_id => new_friend.id).exists?
|
friendships.where(:befriendee => new_friend).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -1244,7 +1244,7 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
# Get users to work with
|
# Get users to work with
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
friend = 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
|
# Check that the users are friends
|
||||||
assert Friendship.where(:user_id => user.id, :friend_user_id => friend.id).first
|
assert Friendship.where(:user_id => user.id, :friend_user_id => friend.id).first
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue