Commit 4c3699b78e4d5ce0b5425f567ad37b86a3cd4270

Authored by Leandro Santos
1 parent 7da2070a
Exists in fix_sign_up_form

should not return duplicated value in community list

app/controllers/my_profile/cms_controller.rb
... ... @@ -255,7 +255,7 @@ class CmsController < MyProfileController
255 255 end
256 256  
257 257 def search_communities_to_publish
258   - scope = user.memberships.distinct(false).group([:id,:name])
  258 + scope = user.memberships.distinct(false).group("profiles.id")
259 259 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
260 260 end
261 261  
... ...
plugins/pg_search/test/functional/cms_controller_test.rb
... ... @@ -21,4 +21,21 @@ class CmsControllerTest < ActionController::TestCase
21 21 assert_match /Testing community 1/, @response.body
22 22 assert_match /Testing community 2/, @response.body
23 23 end
  24 +
  25 + should 'not duplicated a community in list of communities available to spread' do
  26 + env = Environment.default
  27 + env.enable_plugin(PgSearchPlugin)
  28 + profile = create_user('profile').person
  29 + login_as(profile.identifier)
  30 +
  31 + c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => env)
  32 + c1.add_member profile
  33 + c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => env)
  34 + c2.add_member profile
  35 + c2.add_admin profile
  36 +
  37 + get :search_communities_to_publish, :profile => profile.identifier, :q => 'Testing'
  38 + assert_equivalent [c1.id, c2.id], JSON.parse(@response.body).map{|c|c['id']}
  39 + end
  40 +
24 41 end
... ...