From e5b81bcfc0dc72d5116f246ad20f5bad1fcca964 Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Mon, 18 Jul 2016 13:28:57 -0300 Subject: [PATCH] Filters request type in profile_controller --- app/controllers/public/profile_controller.rb | 21 +++++++++------------ test/functional/profile_controller_test.rb | 8 ++++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index da8784a..fca23a7 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -5,6 +5,7 @@ class ProfileController < PublicController before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] 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] before_filter :allow_followers?, :only => [:follow, :unfollow] + before_filter :accept_only_post, :only => [:follow, :unfollow] helper TagsHelper helper ActionTrackerHelper @@ -161,20 +162,16 @@ class ProfileController < PublicController end def follow - if request.post? - if profile.followed_by?(current_person) - render :text => _("You are already following %s.") % profile.name, :status => 400 + if profile.followed_by?(current_person) + render :text => _("You are already following %s.") % profile.name, :status => 400 + else + selected_circles = params[:circles].map{ |circle_name, circle_id| Circle.find_by(:id => circle_id) }.select{ |c| c.present? } + if selected_circles.present? + current_person.follow(profile, selected_circles) + render :text => _("You are now following %s") % profile.name, :status => 200 else - selected_circles = params[:circles].map{|circle_name, circle_id| Circle.find_by(:id => circle_id)}.select{|c|not c.nil?} - if selected_circles.present? - current_person.follow(profile, selected_circles) - render :text => _("You are now following %s") % profile.name, :status => 200 - else - render :text => _("Select at least one circle to follow %s.") % profile.name, :status => 400 - end + render :text => _("Select at least one circle to follow %s.") % profile.name, :status => 400 end - else - render_not_found end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 808b063..8f3e389 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -2006,7 +2006,7 @@ class ProfileControllerTest < ActionController::TestCase should "not unfollow user if not logged" do person = fast_create(Person) - get :unfollow, :profile => person.identifier + post :unfollow, :profile => person.identifier assert_redirected_to :controller => 'account', :action => 'login' end @@ -2020,7 +2020,7 @@ class ProfileControllerTest < ActionController::TestCase assert_not_nil follower - get :unfollow, :profile => person.identifier + post :unfollow, :profile => person.identifier follower = ProfileFollower.find_by(:profile_id => person.id, :circle_id => circle.id) assert_nil follower end @@ -2030,7 +2030,7 @@ class ProfileControllerTest < ActionController::TestCase person = fast_create(Person) assert_no_difference 'ProfileFollower.count' do - get :unfollow, :profile => person.identifier + post :unfollow, :profile => person.identifier end end @@ -2041,7 +2041,7 @@ class ProfileControllerTest < ActionController::TestCase circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person') fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) - get :unfollow, :profile => person.identifier, :redirect_to => "/some/url" + post :unfollow, :profile => person.identifier, :redirect_to => "/some/url" assert_redirected_to "/some/url" end -- libgit2 0.21.2