Commit fa17646bfe9fc2dc837edef3150b921170c170c8
1 parent
d9020ffa
Exists in
master
and in
29 other branches
Fix filter by template for plugins
Showing
3 changed files
with
33 additions
and
1 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -179,6 +179,7 @@ class ApplicationController < ActionController::Base |
179 | 179 | include SearchTermHelper |
180 | 180 | |
181 | 181 | def find_by_contents(asset, context, scope, query, paginate_options={:page => 1}, options={}) |
182 | + scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | |
182 | 183 | search = plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) |
183 | 184 | register_search_term(query, scope.count, search[:results].count, context, asset) |
184 | 185 | search | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -556,7 +556,6 @@ class Noosfero::Plugin |
556 | 556 | # own use in specific views |
557 | 557 | def find_by_contents(asset, scope, query, paginate_options={}, options={}) |
558 | 558 | scope = scope.like_search(query, options) unless query.blank? |
559 | - scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | |
560 | 559 | scope = scope.send(options[:filter]) unless options[:filter].blank? |
561 | 560 | {:results => scope.paginate(paginate_options)} |
562 | 561 | end | ... | ... |
plugins/pg_search/test/functional/search_controller_test.rb
0 → 100644
... | ... | @@ -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 | ... | ... |