diff test/functional/search_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42
line wrap: on
line diff
--- a/test/functional/search_controller_test.rb	Wed Jun 27 14:54:18 2012 +0100
+++ b/test/functional/search_controller_test.rb	Mon Jan 07 12:01:42 2013 +0000
@@ -6,7 +6,7 @@
 
 class SearchControllerTest < ActionController::TestCase
   fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
-           :issues, :trackers, :issue_statuses,
+           :issues, :trackers, :issue_statuses, :enumerations,
            :custom_fields, :custom_values,
            :repositories, :changesets
 
@@ -58,6 +58,63 @@
                     :child => { :tag => 'a',  :content => /Closed/ }
   end
 
+  def test_search_issues_should_search_notes
+    Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
+
+    get :index, :q => 'searchkeyword', :issues => 1
+    assert_response :success
+    assert_include Issue.find(2), assigns(:results)
+  end
+
+  def test_search_issues_with_multiple_matches_in_journals_should_return_issue_once
+    Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
+    Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
+
+    get :index, :q => 'searchkeyword', :issues => 1
+    assert_response :success
+    assert_include Issue.find(2), assigns(:results)
+    assert_equal 1, assigns(:results).size
+  end
+
+  def test_search_issues_should_search_private_notes_with_permission_only
+    Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
+    @request.session[:user_id] = 2
+
+    Role.find(1).add_permission! :view_private_notes
+    get :index, :q => 'searchkeyword', :issues => 1
+    assert_response :success
+    assert_include Issue.find(2), assigns(:results)
+
+    Role.find(1).remove_permission! :view_private_notes
+    get :index, :q => 'searchkeyword', :issues => 1
+    assert_response :success
+    assert_not_include Issue.find(2), assigns(:results)
+  end
+
+  def test_search_all_projects_with_scope_param
+    get :index, :q => 'issue', :scope => 'all'
+    assert_response :success
+    assert_template 'index'
+    assert assigns(:results).present?
+  end
+
+  def test_search_my_projects
+    @request.session[:user_id] = 2
+    get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
+    assert_response :success
+    assert_template 'index'
+    assert assigns(:results).include?(Issue.find(1))
+    assert !assigns(:results).include?(Issue.find(5))
+  end
+
+  def test_search_my_projects_without_memberships
+    # anonymous user has no memberships
+    get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
+    assert_response :success
+    assert_template 'index'
+    assert assigns(:results).empty?
+  end
+
   def test_search_project_and_subprojects
     get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
     assert_response :success
@@ -132,6 +189,22 @@
     assert_equal 1, results.size
   end
 
+  def test_search_with_offset
+    get :index, :q => 'coo', :offset => '20080806073000'
+    assert_response :success
+    results = assigns(:results)
+    assert results.any?
+    assert results.map(&:event_datetime).max < '20080806T073000'.to_time
+  end
+
+  def test_search_previous_with_offset
+    get :index, :q => 'coo', :offset => '20080806073000', :previous => '1'
+    assert_response :success
+    results = assigns(:results)
+    assert results.any?
+    assert results.map(&:event_datetime).min >= '20080806T073000'.to_time
+  end
+
   def test_search_with_invalid_project_id
     get :index, :id => 195, :q => 'recipe'
     assert_response 404
@@ -159,4 +232,24 @@
     get :index, :id => 1, :q => '"good bye" hello "bye bye"'
     assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
   end
+
+  def test_results_should_be_escaped_once
+    assert Issue.find(1).update_attributes(:subject => '<subject> escaped_once', :description => '<description> escaped_once')
+    get :index, :q => 'escaped_once'
+    assert_response :success
+    assert_select '#search-results' do
+      assert_select 'dt.issue a', :text => /&lt;subject&gt;/
+      assert_select 'dd', :text => /&lt;description&gt;/
+    end
+  end
+
+  def test_keywords_should_be_highlighted
+    assert Issue.find(1).update_attributes(:subject => 'subject highlighted', :description => 'description highlighted')
+    get :index, :q => 'highlighted'
+    assert_response :success
+    assert_select '#search-results' do
+      assert_select 'dt.issue a span.highlight', :text => 'highlighted'
+      assert_select 'dd span.highlight', :text => 'highlighted'
+    end
+  end
 end