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"
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
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
##
<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 %>
<%= 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 %>
<%= 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 -%>
</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 %>
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