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.

auto_completes_controller_test.rb 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 AutoCompletesControllerTest < ActionController::TestCase
  19. fixtures :projects, :issues, :issue_statuses,
  20. :enumerations, :users, :issue_categories,
  21. :trackers,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules,
  27. :journals, :journal_details
  28. def test_issues_should_not_be_case_sensitive
  29. get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
  30. assert_response :success
  31. assert_not_nil assigns(:issues)
  32. assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
  33. end
  34. def test_issues_should_accept_term_param
  35. get :issues, :project_id => 'ecookbook', :term => 'ReCiPe'
  36. assert_response :success
  37. assert_not_nil assigns(:issues)
  38. assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
  39. end
  40. def test_issues_should_return_issue_with_given_id
  41. get :issues, :project_id => 'subproject1', :q => '13'
  42. assert_response :success
  43. assert_not_nil assigns(:issues)
  44. assert assigns(:issues).include?(Issue.find(13))
  45. end
  46. def test_issues_should_return_issue_with_given_id_preceded_with_hash
  47. get :issues, :project_id => 'subproject1', :q => '#13'
  48. assert_response :success
  49. assert_not_nil assigns(:issues)
  50. assert assigns(:issues).include?(Issue.find(13))
  51. end
  52. def test_auto_complete_with_scope_all_should_search_other_projects
  53. get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
  54. assert_response :success
  55. assert_not_nil assigns(:issues)
  56. assert assigns(:issues).include?(Issue.find(13))
  57. end
  58. def test_auto_complete_without_project_should_search_all_projects
  59. get :issues, :q => '13'
  60. assert_response :success
  61. assert_not_nil assigns(:issues)
  62. assert assigns(:issues).include?(Issue.find(13))
  63. end
  64. def test_auto_complete_without_scope_all_should_not_search_other_projects
  65. get :issues, :project_id => 'ecookbook', :q => '13'
  66. assert_response :success
  67. assert_equal [], assigns(:issues)
  68. end
  69. def test_issues_should_return_json
  70. get :issues, :project_id => 'subproject1', :q => '13'
  71. assert_response :success
  72. json = ActiveSupport::JSON.decode(response.body)
  73. assert_kind_of Array, json
  74. issue = json.first
  75. assert_kind_of Hash, issue
  76. assert_equal 13, issue['id']
  77. assert_equal 13, issue['value']
  78. assert_equal 'Bug #13: Subproject issue two', issue['label']
  79. end
  80. end