From 2f038eedf7a1e98ac6884fe87c662055a4e89f4f Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Mon, 29 Aug 2016 15:15:12 +0000 Subject: [PATCH] Fixes functional tests --- app/controllers/my_profile/followers_controller.rb | 4 ++-- app/controllers/public/profile_controller.rb | 1 + test/functional/followers_controller_test.rb | 6 +++--- test/functional/profile_controller_test.rb | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/my_profile/followers_controller.rb b/app/controllers/my_profile/followers_controller.rb index daaeafe..5a3f68c 100644 --- a/app/controllers/my_profile/followers_controller.rb +++ b/app/controllers/my_profile/followers_controller.rb @@ -4,11 +4,11 @@ class FollowersController < MyProfileController before_action :accept_only_post, :only => [:update_category] def index - @followed_people = profile.followed_profiles.order(:type) + @followed_people = profile.followed_profiles.sort_by(&:type) @profile_types = {_('All profiles') => nil}.merge(Circle.profile_types).to_a if params['filter'].present? - @followed_people = @followed_people.where(:type => params['filter']) + @followed_people = @followed_people.select{|c| c.type == params['filter']} @active_filter = params['filter'] end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 3649942..440a8f4 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -167,6 +167,7 @@ class ProfileController < PublicController if profile.followed_by?(current_person) render :text => _("You are already following %s.") % profile.name, :status => 400 else + params[:circles] ||= [] 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) diff --git a/test/functional/followers_controller_test.rb b/test/functional/followers_controller_test.rb index f53d3b7..8adf51b 100644 --- a/test/functional/followers_controller_test.rb +++ b/test/functional/followers_controller_test.rb @@ -10,7 +10,7 @@ class FollowersControllerTest < ActionController::TestCase login_as(@profile.identifier) person = fast_create(Person) circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person') - fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) + ProfileFollower.create(:profile => person, :circle => circle) get :index, :profile => @profile.identifier assert_includes assigns(:followed_people), person @@ -22,8 +22,8 @@ class FollowersControllerTest < ActionController::TestCase community = fast_create(Community) circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person') circle2 = Circle.create!(:owner=> @profile, :name => "Teams", :profile_type => 'Community') - fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) - fast_create(ProfileFollower, :profile_id => community.id, :circle_id => circle2.id) + ProfileFollower.create(:profile => person, :circle => circle) + ProfileFollower.create(:profile => community, :circle => circle2) get :index, :profile => @profile.identifier, :filter => "Community" assert_equal assigns(:followed_people), [community] diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 73bcadf..e53fc26 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -2030,10 +2030,10 @@ class ProfileControllerTest < ActionController::TestCase person = fast_create(Person) circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person') - fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) + ProfileFollower.create(:profile => person, :circle => circle) assert_no_difference 'ProfileFollower.count' do - post :follow, :profile => person.identifier, :follow => { :circles => {"Zombies" => circle.id} } + post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id} end assert_response 400 end -- libgit2 0.21.2