From b7a84368cc772ef3c4a11e44ff77f0a043dead67 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 28 Feb 2008 23:55:01 +0000 Subject: [PATCH] ActionItem38: being able to remove friends --- app/controllers/my_profile/friends_controller.rb | 8 ++++++++ app/views/friends/index.rhtml | 6 +++++- app/views/friends/remove.rhtml | 18 ++++++++++++++++++ test/functional/friends_controller_test.rb | 18 ++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/views/friends/remove.rhtml diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb index 8ac1fcd..effcc9c 100644 --- a/app/controllers/my_profile/friends_controller.rb +++ b/app/controllers/my_profile/friends_controller.rb @@ -17,4 +17,12 @@ class FriendsController < MyProfileController end end + def remove + @friend = profile.friends.find(params[:id]) + if request.post? && params[:confirmation] + profile.remove_friend(@friend) + redirect_to :action => 'index' + end + end + end diff --git a/app/views/friends/index.rhtml b/app/views/friends/index.rhtml index 97fd571..2aac4e2 100644 --- a/app/views/friends/index.rhtml +++ b/app/views/friends/index.rhtml @@ -2,7 +2,11 @@ diff --git a/app/views/friends/remove.rhtml b/app/views/friends/remove.rhtml new file mode 100644 index 0000000..e4d3408 --- /dev/null +++ b/app/views/friends/remove.rhtml @@ -0,0 +1,18 @@ +

<%= _('Removing friend: %s') % @friend.name %>

+ +

+<%= _('Are you sure you want to remove %s from your friends list?') % @friend.name %> +

+ +

+ +<%= _('Note that %s will still have you as a friend, unless he/she also wants to remove you from his/her friend list.') % @friend.name %> + +

+ +<% form_tag do %> + <%= hidden_field_tag(:confirmation, 1) %> + + <%= submit_button(:ok, _("Yes, I want to remove %s from my friend list") % @friend.name) %> + <%= button(:cancel, _("No, I don't want"), :action => 'index') %> +<% end %> diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb index 9ce9db8..ac2f2ba 100644 --- a/test/functional/friends_controller_test.rb +++ b/test/functional/friends_controller_test.rb @@ -42,4 +42,22 @@ class FriendsControllerTest < Test::Unit::TestCase end end + should 'confirm removal of friend' do + profile.add_friend(friend) + + get :remove, :id => friend.id + assert_response :success + assert_template 'remove' + ok("must load the friend being removed") { friend == assigns(:friend) } + end + + should 'actually remove friend' do + profile.add_friend(friend) + + assert_difference Friendship, :count, -1 do + post :remove, :id => friend.id, :confirmation => '1' + assert_redirected_to :action => 'index' + end + end + end -- libgit2 0.21.2