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.

wiki_page_test.rb 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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 WikiPageTest < ActiveSupport::TestCase
  19. fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
  20. def setup
  21. @wiki = Wiki.find(1)
  22. @page = @wiki.pages.first
  23. end
  24. def test_create
  25. page = WikiPage.new(:wiki => @wiki)
  26. assert !page.save
  27. assert_equal 1, page.errors.count
  28. page.title = "Page"
  29. assert page.save
  30. page.reload
  31. assert !page.protected?
  32. @wiki.reload
  33. assert @wiki.pages.include?(page)
  34. end
  35. def test_sidebar_should_be_protected_by_default
  36. page = @wiki.find_or_new_page('sidebar')
  37. assert page.new_record?
  38. assert page.protected?
  39. end
  40. def test_find_or_new_page
  41. page = @wiki.find_or_new_page("CookBook documentation")
  42. assert_kind_of WikiPage, page
  43. assert !page.new_record?
  44. page = @wiki.find_or_new_page("Non existing page")
  45. assert_kind_of WikiPage, page
  46. assert page.new_record?
  47. end
  48. def test_parent_title
  49. page = WikiPage.find_by_title('Another_page')
  50. assert_nil page.parent_title
  51. page = WikiPage.find_by_title('Page_with_an_inline_image')
  52. assert_equal 'CookBook documentation', page.parent_title
  53. end
  54. def test_assign_parent
  55. page = WikiPage.find_by_title('Another_page')
  56. page.parent_title = 'CookBook documentation'
  57. assert page.save
  58. page.reload
  59. assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
  60. end
  61. def test_unassign_parent
  62. page = WikiPage.find_by_title('Page_with_an_inline_image')
  63. page.parent_title = ''
  64. assert page.save
  65. page.reload
  66. assert_nil page.parent
  67. end
  68. def test_parent_validation
  69. page = WikiPage.find_by_title('CookBook_documentation')
  70. # A page that doesn't exist
  71. page.parent_title = 'Unknown title'
  72. assert !page.save
  73. assert_include I18n.translate('activerecord.errors.messages.invalid'),
  74. page.errors[:parent_title]
  75. # A child page
  76. page.parent_title = 'Page_with_an_inline_image'
  77. assert !page.save
  78. assert_include I18n.translate('activerecord.errors.messages.circular_dependency'),
  79. page.errors[:parent_title]
  80. # The page itself
  81. page.parent_title = 'CookBook_documentation'
  82. assert !page.save
  83. assert_include I18n.translate('activerecord.errors.messages.circular_dependency'),
  84. page.errors[:parent_title]
  85. page.parent_title = 'Another_page'
  86. assert page.save
  87. end
  88. def test_destroy
  89. page = WikiPage.find(1)
  90. page.destroy
  91. assert_nil WikiPage.find_by_id(1)
  92. # make sure that page content and its history are deleted
  93. assert WikiContent.find_all_by_page_id(1).empty?
  94. assert WikiContent.versioned_class.find_all_by_page_id(1).empty?
  95. end
  96. def test_destroy_should_not_nullify_children
  97. page = WikiPage.find(2)
  98. child_ids = page.child_ids
  99. assert child_ids.any?
  100. page.destroy
  101. assert_nil WikiPage.find_by_id(2)
  102. children = WikiPage.find_all_by_id(child_ids)
  103. assert_equal child_ids.size, children.size
  104. children.each do |child|
  105. assert_nil child.parent_id
  106. end
  107. end
  108. def test_updated_on_eager_load
  109. page = WikiPage.with_updated_on.first(:order => 'id')
  110. assert page.is_a?(WikiPage)
  111. assert_not_nil page.read_attribute(:updated_on)
  112. assert_equal Time.gm(2007, 3, 6, 23, 10, 51), page.content.updated_on
  113. assert_equal page.content.updated_on, page.updated_on
  114. end
  115. end