annotate test/functional/search_controller_test.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@119 1 require File.expand_path('../../test_helper', __FILE__)
Chris@0 2 require 'search_controller'
Chris@0 3
Chris@0 4 # Re-raise errors caught by the controller.
Chris@0 5 class SearchController; def rescue_action(e) raise e end; end
Chris@0 6
Chris@0 7 class SearchControllerTest < ActionController::TestCase
Chris@0 8 fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
Chris@0 9 :issues, :trackers, :issue_statuses,
Chris@0 10 :custom_fields, :custom_values,
Chris@0 11 :repositories, :changesets
Chris@441 12
Chris@0 13 def setup
Chris@0 14 @controller = SearchController.new
Chris@0 15 @request = ActionController::TestRequest.new
Chris@0 16 @response = ActionController::TestResponse.new
Chris@0 17 User.current = nil
Chris@0 18 end
Chris@441 19
Chris@0 20 def test_search_for_projects
Chris@0 21 get :index
Chris@0 22 assert_response :success
Chris@0 23 assert_template 'index'
Chris@0 24
Chris@0 25 get :index, :q => "cook"
Chris@0 26 assert_response :success
Chris@0 27 assert_template 'index'
Chris@0 28 assert assigns(:results).include?(Project.find(1))
Chris@0 29 end
Chris@441 30
Chris@0 31 def test_search_all_projects
Chris@507 32 get :index, :q => 'recipe subproject commit', :all_words => ''
Chris@0 33 assert_response :success
Chris@0 34 assert_template 'index'
Chris@441 35
Chris@0 36 assert assigns(:results).include?(Issue.find(2))
Chris@0 37 assert assigns(:results).include?(Issue.find(5))
Chris@0 38 assert assigns(:results).include?(Changeset.find(101))
Chris@0 39 assert_tag :dt, :attributes => { :class => /issue/ },
Chris@0 40 :child => { :tag => 'a', :content => /Add ingredients categories/ },
Chris@0 41 :sibling => { :tag => 'dd', :content => /should be classified by categories/ }
Chris@441 42
Chris@0 43 assert assigns(:results_by_type).is_a?(Hash)
Chris@0 44 assert_equal 5, assigns(:results_by_type)['changesets']
Chris@0 45 assert_tag :a, :content => 'Changesets (5)'
Chris@0 46 end
Chris@441 47
Chris@0 48 def test_search_issues
Chris@0 49 get :index, :q => 'issue', :issues => 1
Chris@0 50 assert_response :success
Chris@0 51 assert_template 'index'
Chris@441 52
Chris@507 53 assert_equal true, assigns(:all_words)
Chris@507 54 assert_equal false, assigns(:titles_only)
Chris@0 55 assert assigns(:results).include?(Issue.find(8))
Chris@0 56 assert assigns(:results).include?(Issue.find(5))
Chris@0 57 assert_tag :dt, :attributes => { :class => /issue closed/ },
Chris@0 58 :child => { :tag => 'a', :content => /Closed/ }
Chris@0 59 end
Chris@441 60
Chris@0 61 def test_search_project_and_subprojects
Chris@507 62 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
Chris@0 63 assert_response :success
Chris@0 64 assert_template 'index'
Chris@0 65 assert assigns(:results).include?(Issue.find(1))
Chris@0 66 assert assigns(:results).include?(Issue.find(5))
Chris@0 67 end
Chris@0 68
Chris@0 69 def test_search_without_searchable_custom_fields
Chris@0 70 CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
Chris@441 71
Chris@0 72 get :index, :id => 1
Chris@0 73 assert_response :success
Chris@0 74 assert_template 'index'
Chris@0 75 assert_not_nil assigns(:project)
Chris@441 76
Chris@0 77 get :index, :id => 1, :q => "can"
Chris@0 78 assert_response :success
Chris@0 79 assert_template 'index'
Chris@0 80 end
Chris@441 81
Chris@0 82 def test_search_with_searchable_custom_fields
Chris@0 83 get :index, :id => 1, :q => "stringforcustomfield"
Chris@0 84 assert_response :success
Chris@0 85 results = assigns(:results)
Chris@0 86 assert_not_nil results
Chris@0 87 assert_equal 1, results.size
Chris@119 88 assert results.include?(Issue.find(7))
Chris@0 89 end
Chris@441 90
Chris@0 91 def test_search_all_words
Chris@0 92 # 'all words' is on by default
Chris@507 93 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
Chris@507 94 assert_equal true, assigns(:all_words)
Chris@0 95 results = assigns(:results)
Chris@0 96 assert_not_nil results
Chris@0 97 assert_equal 1, results.size
Chris@0 98 assert results.include?(Issue.find(3))
Chris@0 99 end
Chris@441 100
Chris@0 101 def test_search_one_of_the_words
Chris@507 102 get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
Chris@507 103 assert_equal false, assigns(:all_words)
Chris@0 104 results = assigns(:results)
Chris@0 105 assert_not_nil results
Chris@0 106 assert_equal 3, results.size
Chris@0 107 assert results.include?(Issue.find(3))
Chris@0 108 end
Chris@0 109
Chris@0 110 def test_search_titles_only_without_result
Chris@507 111 get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
Chris@0 112 results = assigns(:results)
Chris@0 113 assert_not_nil results
Chris@0 114 assert_equal 0, results.size
Chris@0 115 end
Chris@0 116
Chris@0 117 def test_search_titles_only
Chris@507 118 get :index, :id => 1, :q => 'recipe', :titles_only => '1'
Chris@507 119 assert_equal true, assigns(:titles_only)
Chris@0 120 results = assigns(:results)
Chris@0 121 assert_not_nil results
Chris@0 122 assert_equal 2, results.size
Chris@0 123 end
Chris@441 124
Chris@507 125 def test_search_content
Chris@507 126 Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1")
Chris@909 127
Chris@507 128 get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''
Chris@507 129 assert_equal false, assigns(:titles_only)
Chris@507 130 results = assigns(:results)
Chris@507 131 assert_not_nil results
Chris@507 132 assert_equal 1, results.size
Chris@507 133 end
Chris@507 134
Chris@0 135 def test_search_with_invalid_project_id
Chris@0 136 get :index, :id => 195, :q => 'recipe'
Chris@0 137 assert_response 404
Chris@0 138 assert_nil assigns(:results)
Chris@0 139 end
Chris@0 140
Chris@0 141 def test_quick_jump_to_issue
Chris@0 142 # issue of a public project
Chris@0 143 get :index, :q => "3"
chris@37 144 assert_redirected_to '/issues/3'
Chris@441 145
Chris@0 146 # issue of a private project
Chris@0 147 get :index, :q => "4"
Chris@0 148 assert_response :success
Chris@0 149 assert_template 'index'
Chris@0 150 end
Chris@0 151
Chris@0 152 def test_large_integer
Chris@0 153 get :index, :q => '4615713488'
Chris@0 154 assert_response :success
Chris@0 155 assert_template 'index'
Chris@0 156 end
Chris@441 157
Chris@0 158 def test_tokens_with_quotes
Chris@0 159 get :index, :id => 1, :q => '"good bye" hello "bye bye"'
Chris@0 160 assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
Chris@0 161 end
Chris@0 162 end