[Git][noosfero/noosfero][master] 5 commits: fix sql error when using the pg_search plugin
Leandro Nunes
gitlab at mg.gitlab.com
Tue Jul 26 15:10:31 BRT 2016
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
19ffa2d9 by Marcelo Júnior at 2016-07-22T17:46:29+00:00
fix sql error when using the pg_search plugin
- - - - -
cb418a44 by Marcelo Júnior at 2016-07-22T21:08:03+00:00
add functional test
- - - - -
7da2070a by Marcelo Júnior at 2016-07-22T21:13:24+00:00
rename test
- - - - -
4c3699b7 by Leandro Nunes dos Santos at 2016-07-26T14:18:58-03:00
should not return duplicated value in community list
- - - - -
ba10c953 by Leandro Nunes at 2016-07-26T18:09:53+00:00
Merge branch 'pg_search_fix' into 'master'
fix sql error when using the pg_search plugin
See merge request !985
- - - - -
2 changed files:
- app/controllers/my_profile/cms_controller.rb
- + plugins/pg_search/test/functional/cms_controller_test.rb
Changes:
=====================================
app/controllers/my_profile/cms_controller.rb
=====================================
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -255,7 +255,8 @@ class CmsController < MyProfileController
end
def search_communities_to_publish
- 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
+ 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
def publish
=====================================
plugins/pg_search/test/functional/cms_controller_test.rb
=====================================
--- /dev/null
+++ b/plugins/pg_search/test/functional/cms_controller_test.rb
@@ -0,0 +1,41 @@
+require "test_helper"
+
+class CmsControllerTest < ActionController::TestCase
+
+ should 'list 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
+
+ assert_nothing_raised do
+ get :search_communities_to_publish, :profile => profile.identifier, :q => 'Testing'
+ end
+
+ 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
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/d86bcb8f826b4dd67d1ba18485a2c84b717735fd...ba10c95306d5a42e7fa6dcb58d3066ab06c88448
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160726/e057bcf6/attachment-0001.html>
More information about the Noosfero-dev
mailing list