From 3e3dcb24f082d71c86e5803ea83081732635b758 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Thu, 23 Apr 2015 10:03:09 -0300 Subject: [PATCH] Put limit on tag search --- app/controllers/my_profile/cms_controller.rb | 2 +- test/functional/cms_controller_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 46e62e0..9ff7a92 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -6,7 +6,7 @@ class CmsController < MyProfileController def search_tags arg = params[:term].downcase - result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) + result = ActsAsTaggableOn::Tag.where('name ILIKE ?', "%#{arg}%").limit(10) render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index c797238..6d05356 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1891,8 +1891,8 @@ class CmsControllerTest < ActionController::TestCase end should 'return tags found' do - tag = mock; tag.stubs(:name).returns('linux') - ActsAsTaggableOn::Tag.stubs(:find).returns([tag]) + a = profile.articles.create(:name => 'blablabla') + a.tags.create! name: 'linux' get :search_tags, :profile => profile.identifier, :term => 'linux' assert_equal '[{"label":"linux","value":"linux"}]', @response.body end -- libgit2 0.21.2