Rename friends_with to follows
This commit is contained in:
parent
4370fe45ad
commit
bc630bca87
7 changed files with 16 additions and 16 deletions
|
@ -13,14 +13,14 @@ class FollowsController < ApplicationController
|
|||
before_action :lookup_friend
|
||||
|
||||
def show
|
||||
@already_follows = current_user.friends_with?(@friend)
|
||||
@already_follows = current_user.follows?(@friend)
|
||||
end
|
||||
|
||||
def create
|
||||
follow = Follow.new
|
||||
follow.follower = current_user
|
||||
follow.following = @friend
|
||||
if current_user.friends_with?(@friend)
|
||||
if current_user.follows?(@friend)
|
||||
flash[:warning] = t ".already_followed", :name => @friend.display_name
|
||||
elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_friends_per_hour
|
||||
flash[:error] = t ".limit_exceeded"
|
||||
|
@ -37,7 +37,7 @@ class FollowsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if current_user.friends_with?(@friend)
|
||||
if current_user.follows?(@friend)
|
||||
Follow.where(:follower => current_user, :following => @friend).delete_all
|
||||
flash[:notice] = t ".success", :name => @friend.display_name
|
||||
else
|
||||
|
|
|
@ -282,8 +282,8 @@ class User < ApplicationRecord
|
|||
OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon)
|
||||
end
|
||||
|
||||
def friends_with?(new_friend)
|
||||
follows.exists?(:following => new_friend)
|
||||
def follows?(user)
|
||||
follows.exists?(:following => user)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<ul class='clearfix text-body-secondary'>
|
||||
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
||||
<li>
|
||||
<% if current_user.friends_with?(contact) %>
|
||||
<% if current_user.follows?(contact) %>
|
||||
<%= link_to t("users.show.unfollow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :delete %>
|
||||
<% else %>
|
||||
<%= link_to t("users.show.follow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<%= message_body do %>
|
||||
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>
|
||||
|
||||
<% unless @follow.following.friends_with?(@follow.follower) -%>
|
||||
<% unless @follow.following.follows?(@follow.follower) -%>
|
||||
<p><%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %></p>
|
||||
<% end -%>
|
||||
<% end %>
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
<%= t '.see_their_profile', :userurl => @viewurl %>
|
||||
|
||||
<% unless @follow.following.friends_with?(@follow.follower) -%>
|
||||
<% unless @follow.following.follows?(@follow.follower) -%>
|
||||
<%= t '.follow_them', :followurl => @followurl %>
|
||||
<% end -%>
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
</li>
|
||||
<% if current_user %>
|
||||
<li>
|
||||
<% if current_user.friends_with?(@user) %>
|
||||
<% if current_user.follows?(@user) %>
|
||||
<%= link_to t(".unfollow"), follow_path(:display_name => @user.display_name), :method => :delete %>
|
||||
<% else %>
|
||||
<%= link_to t(".follow"), follow_path(:display_name => @user.display_name), :method => :post %>
|
||||
|
|
|
@ -136,18 +136,18 @@ class UserTest < ActiveSupport::TestCase
|
|||
assert_predicate user, :valid?, "user_0 display_name is invalid but it hasn't been changed"
|
||||
end
|
||||
|
||||
def test_friends_with
|
||||
def test_follows
|
||||
alice = create(:user, :active)
|
||||
bob = create(:user, :active)
|
||||
charlie = create(:user, :active)
|
||||
create(:follow, :follower => alice, :following => bob)
|
||||
|
||||
assert alice.friends_with?(bob)
|
||||
assert_not alice.friends_with?(charlie)
|
||||
assert_not bob.friends_with?(alice)
|
||||
assert_not bob.friends_with?(charlie)
|
||||
assert_not charlie.friends_with?(bob)
|
||||
assert_not charlie.friends_with?(alice)
|
||||
assert alice.follows?(bob)
|
||||
assert_not alice.follows?(charlie)
|
||||
assert_not bob.follows?(alice)
|
||||
assert_not bob.follows?(charlie)
|
||||
assert_not charlie.follows?(bob)
|
||||
assert_not charlie.follows?(alice)
|
||||
end
|
||||
|
||||
def test_users_nearby
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue