Commit 07377fe2efa10181a51057bd60f4911e119c8b5f
1 parent
4e02ff77
Exists in
master
and in
28 other branches
ActionItem36: adding controller for managing friends
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1464 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
71 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,13 @@ |
1 | +class FriendsController < MyProfileController | |
2 | + | |
3 | + def add | |
4 | + @friend = Person.find(params[:id]) | |
5 | + if request.post? && params[:confirmation] | |
6 | + AddFriend.create!(:person => user, :friend => @friend) | |
7 | + | |
8 | + # FIXME shouldn't redirect to the friend's page? | |
9 | + redirect_to :action => 'index' | |
10 | + end | |
11 | + end | |
12 | + | |
13 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<h1><%= _('Adding %s as a friend') % @friend.name %></h1> | |
2 | + | |
3 | +<p> | |
4 | +<%= _('Are you sure you want to add %s as your friend?') % @friend.name %> | |
5 | +</p> | |
6 | + | |
7 | +<p> | |
8 | +<em> | |
9 | +<%= _('Note that %s will need to accept being added as your friend.') % @friend.name %> | |
10 | +</em> | |
11 | +</p> | |
12 | + | |
13 | +<% form_tag do %> | |
14 | + <%= hidden_field_tag(:confirmation, 1) %> | |
15 | + <%= submit_button(:ok, _("Yes, I want to add %s as my friend") % @friend.name) %> | |
16 | + <%= button(:cancel, _("No, I don't want"), :action => 'index') %> | |
17 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'friends_controller' | |
3 | + | |
4 | +class FriendsController; def rescue_action(e) raise e end; end | |
5 | + | |
6 | +class FriendsControllerTest < Test::Unit::TestCase | |
7 | + | |
8 | + include NoosferoTest | |
9 | + | |
10 | + def self.extra_parameters | |
11 | + { :profile => 'testuser' } | |
12 | + end | |
13 | + | |
14 | + def setup | |
15 | + @controller = FriendsController.new | |
16 | + @request = ActionController::TestRequest.new | |
17 | + @response = ActionController::TestResponse.new | |
18 | + | |
19 | + self.profile = create_user('testuser').person | |
20 | + self.friend = create_user('thefriend').person | |
21 | + end | |
22 | + attr_accessor :profile, :friend | |
23 | + | |
24 | + should 'confirm addition of new friend' do | |
25 | + get :add, :id => friend.id | |
26 | + | |
27 | + assert_response :success | |
28 | + assert_template 'add' | |
29 | + | |
30 | + ok("must load the friend being added to display") { friend == assigns(:friend) } | |
31 | + | |
32 | + end | |
33 | + | |
34 | + should 'actually add friend' do | |
35 | + assert_difference AddFriend, :count do | |
36 | + post :add, :id => friend.id, :confirmation => '1' | |
37 | + assert_response :redirect | |
38 | + end | |
39 | + end | |
40 | + | |
41 | +end | ... | ... |