Commit 1a711c0c82c8183d83d3adca526aef12547ae66f
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'next' into stable
Showing
3 changed files
with
33 additions
and
1 deletions
Show diff stats
app/controllers/application_controller.rb
| @@ -184,6 +184,7 @@ class ApplicationController < ActionController::Base | @@ -184,6 +184,7 @@ class ApplicationController < ActionController::Base | ||
| 184 | include SearchTermHelper | 184 | include SearchTermHelper |
| 185 | 185 | ||
| 186 | def find_by_contents(asset, context, scope, query, paginate_options={:page => 1}, options={}) | 186 | def find_by_contents(asset, context, scope, query, paginate_options={:page => 1}, options={}) |
| 187 | + scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | ||
| 187 | search = plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) | 188 | search = plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) |
| 188 | register_search_term(query, scope.count, search[:results].count, context, asset) | 189 | register_search_term(query, scope.count, search[:results].count, context, asset) |
| 189 | search | 190 | search |
lib/noosfero/plugin.rb
| @@ -588,7 +588,6 @@ class Noosfero::Plugin | @@ -588,7 +588,6 @@ class Noosfero::Plugin | ||
| 588 | # own use in specific views | 588 | # own use in specific views |
| 589 | def find_by_contents(asset, scope, query, paginate_options={}, options={}) | 589 | def find_by_contents(asset, scope, query, paginate_options={}, options={}) |
| 590 | scope = scope.like_search(query, options) unless query.blank? | 590 | scope = scope.like_search(query, options) unless query.blank? |
| 591 | - scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | ||
| 592 | scope = scope.send(options[:filter]) unless options[:filter].blank? | 591 | scope = scope.send(options[:filter]) unless options[:filter].blank? |
| 593 | {:results => scope.paginate(paginate_options)} | 592 | {:results => scope.paginate(paginate_options)} |
| 594 | end | 593 | end |
plugins/pg_search/test/functional/search_controller_test.rb
0 → 100644
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | +require "test_helper" | ||
| 2 | + | ||
| 3 | +class SearchControllerTest < ActionController::TestCase | ||
| 4 | + | ||
| 5 | + def setup | ||
| 6 | + environment = Environment.default | ||
| 7 | + environment.enable_plugin(PgSearchPlugin) | ||
| 8 | + end | ||
| 9 | + | ||
| 10 | + should 'list all communities' do | ||
| 11 | + plugin = PgSearchPlugin.new | ||
| 12 | + c1 = fast_create(Community, :name => 'Testing community 1') | ||
| 13 | + c2 = fast_create(Community, :name => 'Testing community 3') | ||
| 14 | + c3 = fast_create(Community, :name => 'Testing community 3') | ||
| 15 | + | ||
| 16 | + get :communities | ||
| 17 | + assert_equivalent [c1, c2, c3], assigns(:searches)[:communities][:results] | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | + should 'list communities of a specific template' do | ||
| 21 | + plugin = PgSearchPlugin.new | ||
| 22 | + t1 = fast_create(Community, :is_template => true) | ||
| 23 | + t2 = fast_create(Community, :is_template => true) | ||
| 24 | + c1 = fast_create(Community, :template_id => t1.id, :name => 'Testing community 1') | ||
| 25 | + c2 = fast_create(Community, :template_id => t2.id, :name => 'Testing community 2') | ||
| 26 | + c3 = fast_create(Community, :template_id => t1.id, :name => 'Testing community 3') | ||
| 27 | + c4 = fast_create(Community, :name => 'Testing community 3') | ||
| 28 | + | ||
| 29 | + get :communities, :template_id => t1.id | ||
| 30 | + assert_equivalent [c1, c3], assigns(:searches)[:communities][:results] | ||
| 31 | + end | ||
| 32 | +end |