Modify the way Friends are added

This commit is contained in:
nertc 2025-01-14 11:32:54 +04:00
parent 1732325768
commit 2b7a48029b
14 changed files with 77 additions and 77 deletions

View file

@ -5,24 +5,24 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# test all routes which lead to this controller
def test_routes
assert_routing(
{ :path => "/user/username/make_friend", :method => :get },
{ :controller => "friendships", :action => "make_friend", :display_name => "username" }
{ :path => "/user/username/follow", :method => :get },
{ :controller => "friendships", :action => "follow", :display_name => "username" }
)
assert_routing(
{ :path => "/user/username/make_friend", :method => :post },
{ :controller => "friendships", :action => "make_friend", :display_name => "username" }
{ :path => "/user/username/follow", :method => :post },
{ :controller => "friendships", :action => "follow", :display_name => "username" }
)
assert_routing(
{ :path => "/user/username/remove_friend", :method => :get },
{ :controller => "friendships", :action => "remove_friend", :display_name => "username" }
{ :path => "/user/username/unfollow", :method => :get },
{ :controller => "friendships", :action => "unfollow", :display_name => "username" }
)
assert_routing(
{ :path => "/user/username/remove_friend", :method => :post },
{ :controller => "friendships", :action => "remove_friend", :display_name => "username" }
{ :path => "/user/username/unfollow", :method => :post },
{ :controller => "friendships", :action => "unfollow", :display_name => "username" }
)
end
def test_make_friend
def test_follow
# Get users to work with
user = create(:user)
friend = create(:user)
@ -44,7 +44,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# When logged in a GET should get a confirmation page
get make_friend_path(friend)
assert_response :success
assert_template :make_friend
assert_template :follow
assert_select "form" do
assert_select "input[type='hidden'][name='referer']", 0
assert_select "input[type='submit']", 1
@ -58,7 +58,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
end
end
assert_redirected_to user_path(friend)
assert_match(/is now your friend/, flash[:notice])
assert_match(/You are now following/, flash[:notice])
assert Friendship.find_by(:befriender => user, :befriendee => friend)
email = ActionMailer::Base.deliveries.first
assert_equal 1, email.to.count
@ -72,11 +72,11 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
end
end
assert_redirected_to user_path(friend)
assert_match(/You are already friends with/, flash[:warning])
assert_match(/You already follow/, flash[:warning])
assert Friendship.find_by(:befriender => user, :befriendee => friend)
end
def test_make_friend_with_referer
def test_follow_with_referer
# Get users to work with
user = create(:user)
friend = create(:user)
@ -88,7 +88,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# The GET should preserve any referer
get make_friend_path(friend), :params => { :referer => "/test" }
assert_response :success
assert_template :make_friend
assert_template :follow
assert_select "form" do
assert_select "input[type='hidden'][name='referer'][value='/test']", 1
assert_select "input[type='submit']", 1
@ -102,7 +102,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
end
end
assert_redirected_to "/test"
assert_match(/is now your friend/, flash[:notice])
assert_match(/You are now following/, flash[:notice])
assert Friendship.find_by(:befriender => user, :befriendee => friend)
email = ActionMailer::Base.deliveries.first
assert_equal 1, email.to.count
@ -110,7 +110,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
ActionMailer::Base.deliveries.clear
end
def test_make_friend_unknown_user
def test_follow_unknown_user
# Should error when a bogus user is specified
session_for(create(:user))
get make_friend_path("No Such User")
@ -118,7 +118,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
assert_template :no_such_user
end
def test_remove_friend
def test_unfollow
# Get users to work with
user = create(:user)
friend = create(:user)
@ -141,7 +141,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# When logged in a GET should get a confirmation page
get remove_friend_path(friend)
assert_response :success
assert_template :remove_friend
assert_template :unfollow
assert_select "form" do
assert_select "input[type='hidden'][name='referer']", 0
assert_select "input[type='submit']", 1
@ -151,17 +151,17 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# When logged in a POST should remove the friendship
post remove_friend_path(friend)
assert_redirected_to user_path(friend)
assert_match(/was removed from your friends/, flash[:notice])
assert_match(/You successfully unfollowed/, flash[:notice])
assert_nil Friendship.find_by(:befriender => user, :befriendee => friend)
# A second POST should report that the friendship does not exist
post remove_friend_path(friend)
assert_redirected_to user_path(friend)
assert_match(/is not one of your friends/, flash[:error])
assert_match(/You are not following/, flash[:error])
assert_nil Friendship.find_by(:befriender => user, :befriendee => friend)
end
def test_remove_friend_with_referer
def test_unfollow_with_referer
# Get users to work with
user = create(:user)
friend = create(:user)
@ -174,7 +174,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# The GET should preserve any referer
get remove_friend_path(friend), :params => { :referer => "/test" }
assert_response :success
assert_template :remove_friend
assert_template :unfollow
assert_select "form" do
assert_select "input[type='hidden'][name='referer'][value='/test']", 1
assert_select "input[type='submit']", 1
@ -184,11 +184,11 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
# When logged in a POST should remove the friendship and refer
post remove_friend_path(friend), :params => { :referer => "/test" }
assert_redirected_to "/test"
assert_match(/was removed from your friends/, flash[:notice])
assert_match(/You successfully unfollowed/, flash[:notice])
assert_nil Friendship.find_by(:befriender => user, :befriendee => friend)
end
def test_remove_friend_unknown_user
def test_unfollow_unknown_user
# Should error when a bogus user is specified
session_for(create(:user))
get remove_friend_path("No Such User")

View file

@ -56,7 +56,7 @@ class Oauth2AuthorizedApplicationsControllerTest < ActionDispatch::IntegrationTe
assert_select "li", :count => 3
assert_select "li", :text => "Read user preferences"
assert_select "li", :text => "Modify user preferences"
assert_select "li", :text => "Create diary entries, comments and make friends"
assert_select "li", :text => "Create diary entries and comments"
end
end

View file

@ -1,12 +1,12 @@
require "application_system_test_case"
class DashboardSystemTest < ApplicationSystemTestCase
test "show no users if have no friends" do
test "show no users if have no followings" do
user = create(:user)
sign_in_as(user)
visit dashboard_path
assert_text "You have not added any friends yet."
assert_text "You have not followed any user yet."
end
test "show users if have friends" do
@ -17,9 +17,9 @@ class DashboardSystemTest < ApplicationSystemTestCase
sign_in_as(user)
visit dashboard_path
assert_no_text "You have not added any friends yet."
assert_no_text "You have not followed any user yet."
friends_heading = find :element, "h2", :text => "My friends"
friends_heading = find :element, "h2", :text => "Followings"
others_heading = find :element, "h2", :text => "Other nearby users"
assert_link friend_user.display_name, :below => friends_heading, :above => others_heading

View file

@ -8,11 +8,11 @@ class FriendshipsTest < ApplicationSystemTestCase
with_settings(:max_friends_per_hour => 0) do
visit user_path(befriendee)
assert_link "Add Friend"
assert_link "Follow"
click_on "Add Friend"
assert_text "You have friended a lot of users recently"
assert_link "Add Friend"
click_on "Follow"
assert_text "You have followed a lot of users recently"
assert_link "Follow"
end
end
end