diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2bb0835..be0c9fb 100644 --- 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 diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 59710f4..a98643e 100644 --- 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 diff --git a/plugins/pg_search/test/functional/search_controller_test.rb b/plugins/pg_search/test/functional/search_controller_test.rb new file mode 100644 index 0000000..0cd9077 --- /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 -- libgit2 0.21.2