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.3KB

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_select 'result', 0
  43. end
  44. test "GET /search.xml with query strings should return results" do
  45. issue = Issue.generate!(:subject => 'searchapi')
  46. get '/search.xml', :q => 'searchapi', :all_words => ''
  47. assert_response :success
  48. assert_select 'results[type=array]' do
  49. assert_select 'result', 1
  50. assert_select 'result' do
  51. assert_select 'id', :text => issue.id.to_s
  52. assert_select 'title', :text => "Bug ##{issue.id} (New): searchapi"
  53. assert_select 'type', :text => 'issue'
  54. assert_select 'url', :text => "http://www.example.com/issues/#{issue.id}"
  55. assert_select 'description', :text => ''
  56. assert_select 'datetime'
  57. end
  58. end
  59. end
  60. test "GET /search.xml should paginate" do
  61. issue = (0..10).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse.map(&:id)
  62. get '/search.json', :q => 'search_with_limited_results', :limit => 4
  63. json = ActiveSupport::JSON.decode(response.body)
  64. assert_equal 11, json['total_count']
  65. assert_equal 0, json['offset']
  66. assert_equal 4, json['limit']
  67. assert_equal issue[0..3], json['results'].map {|r| r['id']}
  68. get '/search.json', :q => 'search_with_limited_results', :offset => 8, :limit => 4
  69. json = ActiveSupport::JSON.decode(response.body)
  70. assert_equal 11, json['total_count']
  71. assert_equal 8, json['offset']
  72. assert_equal 4, json['limit']
  73. assert_equal issue[8..10], json['results'].map {|r| r['id']}
  74. end
  75. end