Commit b7a84368cc772ef3c4a11e44ff77f0a043dead67
1 parent
bff0977b
Exists in
master
and in
28 other branches
ActionItem38: being able to remove friends
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1529 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
49 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/friends_controller.rb
... | ... | @@ -17,4 +17,12 @@ class FriendsController < MyProfileController |
17 | 17 | end |
18 | 18 | end |
19 | 19 | |
20 | + def remove | |
21 | + @friend = profile.friends.find(params[:id]) | |
22 | + if request.post? && params[:confirmation] | |
23 | + profile.remove_friend(@friend) | |
24 | + redirect_to :action => 'index' | |
25 | + end | |
26 | + end | |
27 | + | |
20 | 28 | end | ... | ... |
app/views/friends/index.rhtml
... | ... | @@ -2,7 +2,11 @@ |
2 | 2 | |
3 | 3 | <ul class='profile-list'> |
4 | 4 | <% @friends.each do |friend| %> |
5 | - <li><%= profile_image_link(friend)%></li> | |
5 | + <li> | |
6 | + <%= profile_image_link(friend)%> | |
7 | + <br/> | |
8 | + <%= link_to '(remove)', :action => 'remove', :id => friend.id %> | |
9 | + </li> | |
6 | 10 | <% end %> |
7 | 11 | </ul> |
8 | 12 | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h1><%= _('Removing friend: %s') % @friend.name %></h1> | |
2 | + | |
3 | +<p> | |
4 | +<%= _('Are you sure you want to remove %s from your friends list?') % @friend.name %> | |
5 | +</p> | |
6 | + | |
7 | +<p> | |
8 | +<em> | |
9 | +<%= _('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 %> | |
10 | +</em> | |
11 | +</p> | |
12 | + | |
13 | +<% form_tag do %> | |
14 | + <%= hidden_field_tag(:confirmation, 1) %> | |
15 | + | |
16 | + <%= submit_button(:ok, _("Yes, I want to remove %s from my friend list") % @friend.name) %> | |
17 | + <%= button(:cancel, _("No, I don't want"), :action => 'index') %> | |
18 | +<% end %> | ... | ... |
test/functional/friends_controller_test.rb
... | ... | @@ -42,4 +42,22 @@ class FriendsControllerTest < Test::Unit::TestCase |
42 | 42 | end |
43 | 43 | end |
44 | 44 | |
45 | + should 'confirm removal of friend' do | |
46 | + profile.add_friend(friend) | |
47 | + | |
48 | + get :remove, :id => friend.id | |
49 | + assert_response :success | |
50 | + assert_template 'remove' | |
51 | + ok("must load the friend being removed") { friend == assigns(:friend) } | |
52 | + end | |
53 | + | |
54 | + should 'actually remove friend' do | |
55 | + profile.add_friend(friend) | |
56 | + | |
57 | + assert_difference Friendship, :count, -1 do | |
58 | + post :remove, :id => friend.id, :confirmation => '1' | |
59 | + assert_redirected_to :action => 'index' | |
60 | + end | |
61 | + end | |
62 | + | |
45 | 63 | end | ... | ... |