[noosfero/noosfero][next] Fix filter by template for plugins
Victor Costa
gitlab at gitlab.com
Thu Mar 26 17:36:10 BRT 2015
Victor Costa pushed to next at Noosfero / noosfero
Commits:
fa17646b by Victor Costa at 2015-03-26T16:44:50Z
Fix filter by template for plugins
- - - - -
3 changed files:
- app/controllers/application_controller.rb
- lib/noosfero/plugin.rb
- + plugins/pg_search/test/functional/search_controller_test.rb
Changes:
=====================================
app/controllers/application_controller.rb
=====================================
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -179,6 +179,7 @@ class ApplicationController < ActionController::Base
include SearchTermHelper
def find_by_contents(asset, context, scope, query, paginate_options={:page => 1}, options={})
+ scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank?
search = plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options)
register_search_term(query, scope.count, search[:results].count, context, asset)
search
=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -556,7 +556,6 @@ class Noosfero::Plugin
# own use in specific views
def find_by_contents(asset, scope, query, paginate_options={}, options={})
scope = scope.like_search(query, options) unless query.blank?
- scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank?
scope = scope.send(options[:filter]) unless options[:filter].blank?
{:results => scope.paginate(paginate_options)}
end
=====================================
plugins/pg_search/test/functional/search_controller_test.rb
=====================================
--- /dev/null
+++ b/plugins/pg_search/test/functional/search_controller_test.rb
@@ -0,0 +1,32 @@
+require "test_helper"
+
+class SearchControllerTest < ActionController::TestCase
+
+ def setup
+ environment = Environment.default
+ environment.enable_plugin(PgSearchPlugin)
+ end
+
+ should 'list all communities' do
+ plugin = PgSearchPlugin.new
+ c1 = fast_create(Community, :name => 'Testing community 1')
+ c2 = fast_create(Community, :name => 'Testing community 3')
+ c3 = fast_create(Community, :name => 'Testing community 3')
+
+ get :communities
+ assert_equivalent [c1, c2, c3], assigns(:searches)[:communities][:results]
+ end
+
+ should 'list communities of a specific template' do
+ plugin = PgSearchPlugin.new
+ t1 = fast_create(Community, :is_template => true)
+ t2 = fast_create(Community, :is_template => true)
+ c1 = fast_create(Community, :template_id => t1.id, :name => 'Testing community 1')
+ c2 = fast_create(Community, :template_id => t2.id, :name => 'Testing community 2')
+ c3 = fast_create(Community, :template_id => t1.id, :name => 'Testing community 3')
+ c4 = fast_create(Community, :name => 'Testing community 3')
+
+ get :communities, :template_id => t1.id
+ assert_equivalent [c1, c3], assigns(:searches)[:communities][:results]
+ end
+end
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/fa17646bfe9fc2dc837edef3150b921170c170c8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150326/10f55744/attachment.html>
More information about the Noosfero-dev
mailing list