Commit 556bf994d9fc4f9a6047c41c77a1bc4bc21b0f0a

Authored by Leandro Santos
Committed by Antonio Terceiro
1 parent 98125033

Now is possibile to users remove its profile activities.

(ActionItem1303)
app/controllers/public/profile_controller.rb
... ... @@ -5,7 +5,6 @@ class ProfileController < PublicController
5 5 before_filter :store_before_join, :only => [:join]
6 6 before_filter :login_required, :only => [:join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities]
7 7  
8   -
9 8 helper TagsHelper
10 9  
11 10 def index
... ... @@ -172,8 +171,8 @@ class ProfileController < PublicController
172 171  
173 172 def remove_activity
174 173 begin
175   - activity = current_user.person.tracked_actions.find(params[:activity_id])
176   - ActionTrackerNotification.find(:first, :conditions => {:profile_id => current_user.person, :action_tracker_id => activity}).destroy
  174 + activity = current_person.tracked_actions.find(params[:activity_id])
  175 + activity.destroy
177 176 render :text => _('Activity successfully removed.')
178 177 rescue
179 178 render :text => _('You could not remove this activity')
... ...
test/functional/profile_controller_test.rb
... ... @@ -778,10 +778,11 @@ class ProfileControllerTest < Test::Unit::TestCase
778 778  
779 779 should "not remove an scrap of another user" do
780 780 login_as(profile.identifier)
781   - person = fast_create(Person)
782   - scrap = fast_create(Scrap, :receiver_id => person.id)
  781 + p1 = fast_create(Person)
  782 + p2 = fast_create(Person)
  783 + scrap = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id)
783 784 count = Scrap.count
784   - post :remove_scrap, :profile => person.identifier, :scrap_id => scrap.id
  785 + post :remove_scrap, :profile => p2.identifier, :scrap_id => scrap.id
785 786 assert_equal count, Scrap.count
786 787 end
787 788  
... ... @@ -962,6 +963,7 @@ class ProfileControllerTest < Test::Unit::TestCase
962 963 a3 = ActionTracker::Record.last
963 964  
964 965 login_as(profile.identifier)
  966 + ActionTracker::Record.delete_all
965 967 get :index, :profile => p1.identifier
966 968 assert_equal [], assigns(:network_activities)
967 969 assert_response :success
... ... @@ -1070,19 +1072,18 @@ class ProfileControllerTest < Test::Unit::TestCase
1070 1072 should "the owner of activity could remove it" do
1071 1073 login_as(profile.identifier)
1072 1074 at = fast_create(ActionTracker::Record, :user_id => profile.id)
1073   - atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id)
1074   - assert_difference ActionTrackerNotification, :count, -1 do
  1075 + assert_difference ActionTracker::Record, :count, -1 do
1075 1076 post :remove_activity, :profile => profile.identifier, :activity_id => at.id
1076 1077 end
1077 1078 end
1078 1079  
1079   - should "not remove others activities" do
  1080 + should "remove the network activities dependent an ActionTracker::Record" do
1080 1081 login_as(profile.identifier)
1081 1082 person = fast_create(Person)
1082 1083 at = fast_create(ActionTracker::Record, :user_id => profile.id)
1083 1084 atn = fast_create(ActionTrackerNotification, :profile_id => person.id, :action_tracker_id => at.id)
1084 1085 count = ActionTrackerNotification
1085   - assert_difference ActionTrackerNotification, :count, 0 do
  1086 + assert_difference ActionTrackerNotification, :count, -1 do
1086 1087 post :remove_activity, :profile => profile.identifier, :activity_id => at.id
1087 1088 end
1088 1089 end
... ... @@ -1098,11 +1099,11 @@ class ProfileControllerTest < Test::Unit::TestCase
1098 1099  
1099 1100 should "not remove an activity of another user" do
1100 1101 login_as(profile.identifier)
1101   - person = fast_create(Person)
1102   - at = fast_create(ActionTracker::Record, :user_id => profile.id)
1103   - atn = fast_create(ActionTrackerNotification, :profile_id => person.id, :action_tracker_id => at.id)
  1102 + p1 = fast_create(Person)
  1103 + at = fast_create(ActionTracker::Record, :user_id => p1.id)
  1104 + atn = fast_create(ActionTrackerNotification, :profile_id => p1.id, :action_tracker_id => at.id)
1104 1105 count = ActionTrackerNotification.count
1105   - post :remove_activity, :profile => person.identifier, :activity_id => at.id
  1106 + post :remove_activity, :profile => profile.identifier, :activity_id => at.id
1106 1107 assert_equal count, ActionTrackerNotification.count
1107 1108 end
1108 1109  
... ...