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.

document_test.rb 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 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 File.expand_path('../../test_helper', __FILE__)
  19. class DocumentTest < ActiveSupport::TestCase
  20. fixtures :projects, :enumerations, :documents, :attachments,
  21. :enabled_modules,
  22. :users, :email_addresses, :members, :member_roles, :roles,
  23. :groups_users
  24. def setup
  25. User.current = nil
  26. end
  27. def test_create
  28. doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
  29. assert doc.save
  30. end
  31. def test_create_with_long_title
  32. title = 'x'*255
  33. doc = Document.new(:project => Project.find(1), :title => title, :category => DocumentCategory.first)
  34. assert_save doc
  35. assert_equal title, doc.reload.title
  36. end
  37. def test_create_should_send_email_notification
  38. ActionMailer::Base.deliveries.clear
  39. with_settings :notified_events => %w(document_added) do
  40. doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
  41. assert doc.save
  42. end
  43. assert_equal 2, ActionMailer::Base.deliveries.size
  44. end
  45. def test_create_with_default_category
  46. # Sets a default category
  47. e = Enumeration.find_by_name('Technical documentation')
  48. e.update(:is_default => true)
  49. doc = Document.new(:project => Project.find(1), :title => 'New document')
  50. assert_equal e, doc.category
  51. assert doc.save
  52. end
  53. def test_updated_on_with_attachments
  54. d = Document.find(1)
  55. assert d.attachments.any?
  56. assert_equal d.attachments.map(&:created_on).max, d.updated_on
  57. end
  58. def test_updated_on_without_attachments
  59. d = Document.find(2)
  60. assert d.attachments.empty?
  61. assert_equal d.created_on, d.updated_on
  62. end
  63. end