Commit 9e90cb78a8f37df5984b2862f2e1646c58702522

Authored by Braulio Bhavamitra
2 parents abbed37f 3e3dcb24

Merge branch 'limit-tag-search' into 'master'

Put limit on tag search

See merge request !553
app/controllers/my_profile/cms_controller.rb
@@ -6,7 +6,7 @@ class CmsController < MyProfileController @@ -6,7 +6,7 @@ class CmsController < MyProfileController
6 6
7 def search_tags 7 def search_tags
8 arg = params[:term].downcase 8 arg = params[:term].downcase
9 - result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) 9 + result = ActsAsTaggableOn::Tag.where('name ILIKE ?', "%#{arg}%").limit(10)
10 render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' 10 render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json'
11 end 11 end
12 12
test/functional/cms_controller_test.rb
@@ -1891,8 +1891,8 @@ class CmsControllerTest < ActionController::TestCase @@ -1891,8 +1891,8 @@ class CmsControllerTest < ActionController::TestCase
1891 end 1891 end
1892 1892
1893 should 'return tags found' do 1893 should 'return tags found' do
1894 - tag = mock; tag.stubs(:name).returns('linux')  
1895 - ActsAsTaggableOn::Tag.stubs(:find).returns([tag]) 1894 + a = profile.articles.create(:name => 'blablabla')
  1895 + a.tags.create! name: 'linux'
1896 get :search_tags, :profile => profile.identifier, :term => 'linux' 1896 get :search_tags, :profile => profile.identifier, :term => 'linux'
1897 assert_equal '[{"label":"linux","value":"linux"}]', @response.body 1897 assert_equal '[{"label":"linux","value":"linux"}]', @response.body
1898 end 1898 end