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

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