diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb new file mode 100644 index 0000000..325c94c --- /dev/null +++ b/app/controllers/my_profile/friends_controller.rb @@ -0,0 +1,13 @@ +class FriendsController < MyProfileController + + def add + @friend = Person.find(params[:id]) + if request.post? && params[:confirmation] + AddFriend.create!(:person => user, :friend => @friend) + + # FIXME shouldn't redirect to the friend's page? + redirect_to :action => 'index' + end + end + +end diff --git a/app/views/friends/add.rhtml b/app/views/friends/add.rhtml new file mode 100644 index 0000000..caa7b6b --- /dev/null +++ b/app/views/friends/add.rhtml @@ -0,0 +1,17 @@ +
+<%= _('Are you sure you want to add %s as your friend?') % @friend.name %> +
+ ++ +<%= _('Note that %s will need to accept being added as your friend.') % @friend.name %> + +
+ +<% form_tag do %> + <%= hidden_field_tag(:confirmation, 1) %> + <%= submit_button(:ok, _("Yes, I want to add %s as my friend") % @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 new file mode 100644 index 0000000..b9ee7a1 --- /dev/null +++ b/test/functional/friends_controller_test.rb @@ -0,0 +1,41 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'friends_controller' + +class FriendsController; def rescue_action(e) raise e end; end + +class FriendsControllerTest < Test::Unit::TestCase + + include NoosferoTest + + def self.extra_parameters + { :profile => 'testuser' } + end + + def setup + @controller = FriendsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + self.profile = create_user('testuser').person + self.friend = create_user('thefriend').person + end + attr_accessor :profile, :friend + + should 'confirm addition of new friend' do + get :add, :id => friend.id + + assert_response :success + assert_template 'add' + + ok("must load the friend being added to display") { friend == assigns(:friend) } + + end + + should 'actually add friend' do + assert_difference AddFriend, :count do + post :add, :id => friend.id, :confirmation => '1' + assert_response :redirect + end + end + +end -- libgit2 0.21.2