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.

journal_test.rb 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 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 JournalTest < ActiveSupport::TestCase
  19. fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :member_roles
  20. def setup
  21. @journal = Journal.find 1
  22. end
  23. def test_journalized_is_an_issue
  24. issue = @journal.issue
  25. assert_kind_of Issue, issue
  26. assert_equal 1, issue.id
  27. end
  28. def test_new_status
  29. status = @journal.new_status
  30. assert_not_nil status
  31. assert_kind_of IssueStatus, status
  32. assert_equal 2, status.id
  33. end
  34. def test_create_should_send_email_notification
  35. ActionMailer::Base.deliveries.clear
  36. issue = Issue.find(:first)
  37. user = User.find(:first)
  38. journal = issue.init_journal(user, issue)
  39. assert journal.save
  40. assert_equal 1, ActionMailer::Base.deliveries.size
  41. end
  42. def test_visible_scope_for_anonymous
  43. # Anonymous user should see issues of public projects only
  44. journals = Journal.visible(User.anonymous).all
  45. assert journals.any?
  46. assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
  47. # Anonymous user should not see issues without permission
  48. Role.anonymous.remove_permission!(:view_issues)
  49. journals = Journal.visible(User.anonymous).all
  50. assert journals.empty?
  51. end
  52. def test_visible_scope_for_user
  53. user = User.find(9)
  54. assert user.projects.empty?
  55. # Non member user should see issues of public projects only
  56. journals = Journal.visible(user).all
  57. assert journals.any?
  58. assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
  59. # Non member user should not see issues without permission
  60. Role.non_member.remove_permission!(:view_issues)
  61. user.reload
  62. journals = Journal.visible(user).all
  63. assert journals.empty?
  64. # User should see issues of projects for which he has view_issues permissions only
  65. Member.create!(:principal => user, :project_id => 1, :role_ids => [1])
  66. user.reload
  67. journals = Journal.visible(user).all
  68. assert journals.any?
  69. assert_nil journals.detect {|journal| journal.issue.project_id != 1}
  70. end
  71. def test_visible_scope_for_admin
  72. user = User.find(1)
  73. user.members.each(&:destroy)
  74. assert user.projects.empty?
  75. journals = Journal.visible(user).all
  76. assert journals.any?
  77. # Admin should see issues on private projects that he does not belong to
  78. assert journals.detect {|journal| !journal.issue.project.is_public?}
  79. end
  80. end