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.

issue_scopes_test.rb 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class IssueScopesTest < ActiveSupport::TestCase
  20. fixtures :projects, :users, :members, :member_roles, :roles,
  21. :groups_users,
  22. :trackers, :projects_trackers,
  23. :enabled_modules,
  24. :versions, :issue_statuses, :issue_categories, :enumerations,
  25. :issues,
  26. :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values
  27. def setup
  28. User.current = nil
  29. end
  30. def test_cross_project_scope_without_project_should_return_all_issues
  31. ids = Issue.cross_project_scope(nil).pluck(:id).sort
  32. assert_equal Issue.pluck(:id).sort, ids
  33. end
  34. def test_cross_project_scope_with_project_should_return_project_issues
  35. project = Project.find(1)
  36. ids = Issue.cross_project_scope(project).pluck(:id).sort
  37. assert_equal project.issues.pluck(:id).sort, ids
  38. end
  39. def test_cross_project_scope_with_all_scope_should_return_all_issues
  40. project = Project.find(1)
  41. ids = Issue.cross_project_scope(project, 'all').pluck(:id).sort
  42. assert_equal Issue.pluck(:id).sort, ids
  43. end
  44. def test_cross_project_scope_with_system_scope_should_return_all_issues
  45. project = Project.find(1)
  46. ids = Issue.cross_project_scope(project, 'system').pluck(:id).sort
  47. assert_equal Issue.pluck(:id).sort, ids
  48. end
  49. def test_cross_project_scope_with_tree_scope_should_return_tree_issues
  50. project = Project.find(5)
  51. ids = Issue.cross_project_scope(project, 'tree').pluck(:id).sort
  52. assert_equal project.root.self_and_descendants.map{|p| p.issues.pluck(:id)}.flatten.sort, ids
  53. end
  54. def test_cross_project_scope_with_hierarchy_scope_should_return_hierarchy_issues
  55. project = Project.find(5)
  56. ids = Issue.cross_project_scope(project, 'hierarchy').pluck(:id).sort
  57. assert_equal (project.self_and_descendants + project.ancestors).map{|p| p.issues.pluck(:id)}.flatten.sort, ids
  58. end
  59. def test_cross_project_scope_with_descendants_scope_should_return_descendants_issues
  60. project = Project.find(5)
  61. ids = Issue.cross_project_scope(project, 'descendants').pluck(:id).sort
  62. assert_equal project.self_and_descendants.map{|p| p.issues.pluck(:id)}.flatten.sort, ids
  63. end
  64. end