From 4c3699b78e4d5ce0b5425f567ad37b86a3cd4270 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 26 Jul 2016 14:18:58 -0300 Subject: [PATCH] should not return duplicated value in community list --- app/controllers/my_profile/cms_controller.rb | 2 +- plugins/pg_search/test/functional/cms_controller_test.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 478817c..0f76059 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -255,7 +255,7 @@ class CmsController < MyProfileController end def search_communities_to_publish - scope = user.memberships.distinct(false).group([:id,:name]) + scope = user.memberships.distinct(false).group("profiles.id") render :text => find_by_contents(:profiles, environment, scope, params['q'], {:page => 1}, {:fields => ['name']})[:results].map {|community| {:id => community.id, :name => community.name} }.to_json end diff --git a/plugins/pg_search/test/functional/cms_controller_test.rb b/plugins/pg_search/test/functional/cms_controller_test.rb index 3f1a55c..064c76a 100644 --- a/plugins/pg_search/test/functional/cms_controller_test.rb +++ b/plugins/pg_search/test/functional/cms_controller_test.rb @@ -21,4 +21,21 @@ class CmsControllerTest < ActionController::TestCase assert_match /Testing community 1/, @response.body assert_match /Testing community 2/, @response.body end + + should 'not duplicated a community in list of communities available to spread' do + env = Environment.default + env.enable_plugin(PgSearchPlugin) + profile = create_user('profile').person + login_as(profile.identifier) + + c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => env) + c1.add_member profile + c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => env) + c2.add_member profile + c2.add_admin profile + + get :search_communities_to_publish, :profile => profile.identifier, :q => 'Testing' + assert_equivalent [c1.id, c2.id], JSON.parse(@response.body).map{|c|c['id']} + end + end -- libgit2 0.21.2