You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search_test.rb 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../test_helper', __FILE__)
  18. class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base
  19. fixtures :projects, :projects_trackers,
  20. :enabled_modules, :roles, :users, :members, :member_roles,
  21. :issues, :trackers, :issue_statuses, :enumerations,
  22. :workflows,
  23. :custom_fields, :custom_values,
  24. :custom_fields_projects, :custom_fields_trackers,
  25. :repositories, :changesets
  26. test "GET /search.xml should return xml content" do
  27. get '/search.xml'
  28. assert_response :success
  29. assert_equal 'application/xml', @response.content_type
  30. end
  31. test "GET /search.json should return json content" do
  32. get '/search.json'
  33. assert_response :success
  34. assert_equal 'application/json', @response.content_type
  35. json = ActiveSupport::JSON.decode(response.body)
  36. assert_kind_of Hash, json
  37. assert_kind_of Array, json['results']
  38. end
  39. test "GET /search.xml without query strings should return empty results" do
  40. get '/search.xml', :q => '', :all_words => ''
  41. assert_response :success
  42. assert_equal 0, assigns(:results).size
  43. end
  44. test "GET /search.xml with query strings should return results" do
  45. get '/search.xml', :q => 'recipe subproject commit', :all_words => ''
  46. assert_response :success
  47. assert_not_empty(assigns(:results))
  48. assert_select 'results[type=array]' do
  49. assert_select 'result', :count => assigns(:results).count
  50. assigns(:results).size.times.each do |i|
  51. assert_select 'result' do
  52. assert_select 'id', :text => assigns(:results)[i].id.to_s
  53. assert_select 'title', :text => assigns(:results)[i].event_title
  54. assert_select 'type', :text => assigns(:results)[i].event_type
  55. assert_select 'url', :text => url_for(assigns(:results)[i].event_url(:only_path => false))
  56. assert_select 'description', :text => assigns(:results)[i].event_description
  57. assert_select 'datetime'
  58. end
  59. end
  60. end
  61. end
  62. test "GET /search.xml should paginate" do
  63. issue = (0..10).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse.map(&:id)
  64. get '/search.json', :q => 'search_with_limited_results', :limit => 4
  65. json = ActiveSupport::JSON.decode(response.body)
  66. assert_equal 11, json['total_count']
  67. assert_equal 0, json['offset']
  68. assert_equal 4, json['limit']
  69. assert_equal issue[0..3], json['results'].map {|r| r['id']}
  70. get '/search.json', :q => 'search_with_limited_results', :offset => 8, :limit => 4
  71. json = ActiveSupport::JSON.decode(response.body)
  72. assert_equal 11, json['total_count']
  73. assert_equal 8, json['offset']
  74. assert_equal 4, json['limit']
  75. assert_equal issue[8..10], json['results'].map {|r| r['id']}
  76. end
  77. end