Commit a2bdbbc6fc39c8d8362cc5370c9f246b1182099e

Authored by Leandro Santos
2 parents b475fd6a ba10c953
Exists in fix_sign_up_form

Merge branch 'master' of gitlab.com:noosfero/noosfero

app/controllers/my_profile/cms_controller.rb
@@ -255,7 +255,8 @@ class CmsController < MyProfileController @@ -255,7 +255,8 @@ class CmsController < MyProfileController
255 end 255 end
256 256
257 def search_communities_to_publish 257 def search_communities_to_publish
258 - render :text => find_by_contents(:profiles, environment, user.memberships, params['q'], {:page => 1}, {:fields => ['name']})[:results].map {|community| {:id => community.id, :name => community.name} }.to_json 258 + scope = user.memberships.distinct(false).group("profiles.id")
  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
259 end 260 end
260 261
261 def publish 262 def publish
plugins/pg_search/test/functional/cms_controller_test.rb 0 → 100644
@@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
  1 +require "test_helper"
  2 +
  3 +class CmsControllerTest < ActionController::TestCase
  4 +
  5 + should 'list communities available to spread' do
  6 + env = Environment.default
  7 + env.enable_plugin(PgSearchPlugin)
  8 + profile = create_user('profile').person
  9 + login_as(profile.identifier)
  10 +
  11 + c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => env)
  12 + c1.add_member profile
  13 + c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => env)
  14 + c2.add_member profile
  15 + c2.add_admin profile
  16 +
  17 + assert_nothing_raised do
  18 + get :search_communities_to_publish, :profile => profile.identifier, :q => 'Testing'
  19 + end
  20 +
  21 + assert_match /Testing community 1/, @response.body
  22 + assert_match /Testing community 2/, @response.body
  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 +
  41 +end