Commit ba10c95306d5a42e7fa6dcb58d3066ab06c88448
Exists in
fix_sign_up_form
Merge branch 'pg_search_fix' into 'master'
fix sql error when using the pg_search plugin See merge request !985
Showing
2 changed files
with
43 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -255,7 +255,8 @@ class CmsController < MyProfileController |
| 255 | 255 | end |
| 256 | 256 | |
| 257 | 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 | 260 | end |
| 260 | 261 | |
| 261 | 262 | def publish | ... | ... |
plugins/pg_search/test/functional/cms_controller_test.rb
0 → 100644
| ... | ... | @@ -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 | ... | ... |