Commit 0fb41209ada6ccf726b0fd46d767dfb05d808b8a
1 parent
2380546e
Exists in
master
and in
29 other branches
Removing solr from region tests
Also removing region unit tests that are already being done in the functional test.
Showing
4 changed files
with
7 additions
and
35 deletions
Show diff stats
app/controllers/admin/region_validators_controller.rb
... | ... | @@ -33,7 +33,7 @@ class RegionValidatorsController < AdminController |
33 | 33 | def load_region_and_search |
34 | 34 | @region = environment.regions.find(params[:id]) |
35 | 35 | if params[:search] |
36 | - @search = find_by_contents(Organization, params[:search])[:results].docs.reject {|item| @region.validator_ids.include?(item.id) } | |
36 | + @search = find_by_contents(Organization, params[:search])[:results].reject {|item| @region.validator_ids.include?(item.id) } | |
37 | 37 | end |
38 | 38 | end |
39 | 39 | ... | ... |
app/controllers/application_controller.rb
... | ... | @@ -154,11 +154,10 @@ class ApplicationController < ActionController::Base |
154 | 154 | end |
155 | 155 | end |
156 | 156 | |
157 | - def find_by_contents(scope, query, paginate_options={}, options={}) | |
158 | - if query.blank? | |
159 | - scope = scope.send(options[:filter]) if options[:filter] | |
160 | - return {:results => scope.paginate(paginate_options)} | |
161 | - end | |
157 | + def find_by_contents(scope, query, paginate_options={:page => 1}, options={}) | |
158 | + scope = scope.send(options[:filter]) if options[:filter] | |
159 | + return {:results => scope.paginate(paginate_options)} if query.blank? | |
160 | + | |
162 | 161 | @plugins.first(:find_by_contents, scope, query, paginate_options, options) || |
163 | 162 | fallback_find_by_contents(scope, query, paginate_options, options) |
164 | 163 | end |
... | ... | @@ -168,9 +167,9 @@ class ApplicationController < ActionController::Base |
168 | 167 | def fallback_find_by_contents(scope, query, paginate_options, options) |
169 | 168 | fields = scope.base_class::SEARCHABLE_FIELDS.keys.map(&:to_s) & scope.base_class.column_names |
170 | 169 | conditions = fields.map do |field| |
171 | - "#{scope.base_class.table_name}.#{field} LIKE \"%#{query.downcase}%\"" | |
170 | + "lower(#{scope.base_class.table_name}.#{field}) LIKE \"%#{query.downcase.strip}%\"" | |
172 | 171 | end.join(' OR ') |
173 | - {:results => scope.send(options[:filter]).where(conditions).paginate(paginate_options)} | |
172 | + {:results => scope.where(conditions).paginate(paginate_options)} | |
174 | 173 | end |
175 | 174 | |
176 | 175 | end | ... | ... |
test/functional/region_validators_controller_test.rb
... | ... | @@ -46,7 +46,6 @@ class RegionValidatorsControllerTest < ActionController::TestCase |
46 | 46 | end |
47 | 47 | |
48 | 48 | should 'search possible validators by name' do |
49 | - TestSolr.enable | |
50 | 49 | environment = fast_create(Environment, :name => "my environment") |
51 | 50 | give_permission('ze', 'manage_environment_validators', environment) |
52 | 51 | region = Region.new(:name => 'my region') | ... | ... |
test/unit/region_test.rb
... | ... | @@ -16,32 +16,6 @@ class RegionTest < ActiveSupport::TestCase |
16 | 16 | end |
17 | 17 | end |
18 | 18 | |
19 | - should 'be able to search for possible validators by name' do | |
20 | - TestSolr.enable | |
21 | - env = fast_create(Environment) | |
22 | - region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | |
23 | - org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) | |
24 | - org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) | |
25 | - | |
26 | - possible = region.search_possible_validators('organization') | |
27 | - assert possible.include?(org2) | |
28 | - assert_includes possible, org2 | |
29 | - assert_includes possible, org1 | |
30 | - end | |
31 | - | |
32 | - should 'return search results without validators that are already associated to the current region' do | |
33 | - TestSolr.enable | |
34 | - env = fast_create(Environment) | |
35 | - region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | |
36 | - org1 = fast_create(Organization, {:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id}, :search => true) | |
37 | - org2 = fast_create(Organization, {:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id}, :search => true) | |
38 | - region.validators << org1 | |
39 | - | |
40 | - possible = region.search_possible_validators('organization') | |
41 | - assert_includes possible, org2 | |
42 | - assert_not_includes possible, org1 | |
43 | - end | |
44 | - | |
45 | 19 | should 'has validator' do |
46 | 20 | env = fast_create(Environment) |
47 | 21 | region = fast_create(Region, :environment_id => env.id, :name => 'My Region') | ... | ... |