Commit e5b81bcfc0dc72d5116f246ad20f5bad1fcca964

Authored by Gabriel Silva
Committed by Larissa Reis
1 parent 63f25af1

Filters request type in profile_controller

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
app/controllers/public/profile_controller.rb
@@ -5,6 +5,7 @@ class ProfileController &lt; PublicController @@ -5,6 +5,7 @@ class ProfileController &lt; PublicController
5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] 5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail]
6 before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail, :follow, :unfollow] 6 before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail, :follow, :unfollow]
7 before_filter :allow_followers?, :only => [:follow, :unfollow] 7 before_filter :allow_followers?, :only => [:follow, :unfollow]
  8 + before_filter :accept_only_post, :only => [:follow, :unfollow]
8 9
9 helper TagsHelper 10 helper TagsHelper
10 helper ActionTrackerHelper 11 helper ActionTrackerHelper
@@ -161,20 +162,16 @@ class ProfileController &lt; PublicController @@ -161,20 +162,16 @@ class ProfileController &lt; PublicController
161 end 162 end
162 163
163 def follow 164 def follow
164 - if request.post?  
165 - if profile.followed_by?(current_person)  
166 - render :text => _("You are already following %s.") % profile.name, :status => 400 165 + if profile.followed_by?(current_person)
  166 + render :text => _("You are already following %s.") % profile.name, :status => 400
  167 + else
  168 + selected_circles = params[:circles].map{ |circle_name, circle_id| Circle.find_by(:id => circle_id) }.select{ |c| c.present? }
  169 + if selected_circles.present?
  170 + current_person.follow(profile, selected_circles)
  171 + render :text => _("You are now following %s") % profile.name, :status => 200
167 else 172 else
168 - selected_circles = params[:circles].map{|circle_name, circle_id| Circle.find_by(:id => circle_id)}.select{|c|not c.nil?}  
169 - if selected_circles.present?  
170 - current_person.follow(profile, selected_circles)  
171 - render :text => _("You are now following %s") % profile.name, :status => 200  
172 - else  
173 - render :text => _("Select at least one circle to follow %s.") % profile.name, :status => 400  
174 - end 173 + render :text => _("Select at least one circle to follow %s.") % profile.name, :status => 400
175 end 174 end
176 - else  
177 - render_not_found  
178 end 175 end
179 end 176 end
180 177
test/functional/profile_controller_test.rb
@@ -2006,7 +2006,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2006,7 +2006,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2006 2006
2007 should "not unfollow user if not logged" do 2007 should "not unfollow user if not logged" do
2008 person = fast_create(Person) 2008 person = fast_create(Person)
2009 - get :unfollow, :profile => person.identifier 2009 + post :unfollow, :profile => person.identifier
2010 2010
2011 assert_redirected_to :controller => 'account', :action => 'login' 2011 assert_redirected_to :controller => 'account', :action => 'login'
2012 end 2012 end
@@ -2020,7 +2020,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2020,7 +2020,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2020 2020
2021 assert_not_nil follower 2021 assert_not_nil follower
2022 2022
2023 - get :unfollow, :profile => person.identifier 2023 + post :unfollow, :profile => person.identifier
2024 follower = ProfileFollower.find_by(:profile_id => person.id, :circle_id => circle.id) 2024 follower = ProfileFollower.find_by(:profile_id => person.id, :circle_id => circle.id)
2025 assert_nil follower 2025 assert_nil follower
2026 end 2026 end
@@ -2030,7 +2030,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2030,7 +2030,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2030 person = fast_create(Person) 2030 person = fast_create(Person)
2031 2031
2032 assert_no_difference 'ProfileFollower.count' do 2032 assert_no_difference 'ProfileFollower.count' do
2033 - get :unfollow, :profile => person.identifier 2033 + post :unfollow, :profile => person.identifier
2034 end 2034 end
2035 end 2035 end
2036 2036
@@ -2041,7 +2041,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2041,7 +2041,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2041 circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person') 2041 circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person')
2042 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 2042 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
2043 2043
2044 - get :unfollow, :profile => person.identifier, :redirect_to => "/some/url" 2044 + post :unfollow, :profile => person.identifier, :redirect_to => "/some/url"
2045 assert_redirected_to "/some/url" 2045 assert_redirected_to "/some/url"
2046 end 2046 end
2047 2047