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_content_test.rb 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 WikiContentTest < ActiveSupport::TestCase
  19. fixtures :projects, :enabled_modules,
  20. :users, :members, :member_roles, :roles,
  21. :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
  22. def setup
  23. @wiki = Wiki.find(1)
  24. @page = @wiki.pages.first
  25. end
  26. def test_create
  27. page = WikiPage.new(:wiki => @wiki, :title => "Page")
  28. page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
  29. assert page.save
  30. page.reload
  31. content = page.content
  32. assert_kind_of WikiContent, content
  33. assert_equal 1, content.version
  34. assert_equal 1, content.versions.length
  35. assert_equal "Content text", content.text
  36. assert_equal "My comment", content.comments
  37. assert_equal User.find(1), content.author
  38. assert_equal content.text, content.versions.last.text
  39. end
  40. def test_create_should_send_email_notification
  41. ActionMailer::Base.deliveries.clear
  42. page = WikiPage.new(:wiki => @wiki, :title => "A new page")
  43. page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
  44. with_settings :notified_events => %w(wiki_content_added) do
  45. assert page.save
  46. end
  47. assert_equal 1, ActionMailer::Base.deliveries.size
  48. end
  49. def test_update_should_be_versioned
  50. content = @page.content
  51. version_count = content.version
  52. content.text = "My new content"
  53. assert_difference 'WikiContent::Version.count' do
  54. assert content.save
  55. end
  56. content.reload
  57. assert_equal version_count+1, content.version
  58. assert_equal version_count+1, content.versions.length
  59. version = WikiContent::Version.first(:order => 'id DESC')
  60. assert_equal @page.id, version.page_id
  61. assert_equal '', version.compression
  62. assert_equal "My new content", version.data
  63. assert_equal "My new content", version.text
  64. end
  65. def test_update_with_gzipped_history
  66. with_settings :wiki_compression => 'gzip' do
  67. content = @page.content
  68. content.text = "My new content"
  69. assert_difference 'WikiContent::Version.count' do
  70. assert content.save
  71. end
  72. end
  73. version = WikiContent::Version.first(:order => 'id DESC')
  74. assert_equal @page.id, version.page_id
  75. assert_equal 'gzip', version.compression
  76. assert_not_equal "My new content", version.data
  77. assert_equal "My new content", version.text
  78. end
  79. def test_update_should_send_email_notification
  80. ActionMailer::Base.deliveries.clear
  81. content = @page.content
  82. content.text = "My new content"
  83. with_settings :notified_events => %w(wiki_content_updated) do
  84. assert content.save
  85. end
  86. assert_equal 1, ActionMailer::Base.deliveries.size
  87. end
  88. def test_fetch_history
  89. assert !@page.content.versions.empty?
  90. @page.content.versions.each do |version|
  91. assert_kind_of String, version.text
  92. end
  93. end
  94. def test_large_text_should_not_be_truncated_to_64k
  95. page = WikiPage.new(:wiki => @wiki, :title => "Big page")
  96. page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
  97. assert page.save
  98. page.reload
  99. assert_equal 500.kilobyte, page.content.text.size
  100. end
  101. def test_current_version
  102. content = WikiContent.find(11)
  103. assert_equal true, content.current_version?
  104. assert_equal true, content.versions.first(:order => 'version DESC').current_version?
  105. assert_equal false, content.versions.first(:order => 'version ASC').current_version?
  106. end
  107. def test_previous_for_first_version_should_return_nil
  108. content = WikiContent::Version.find_by_page_id_and_version(1, 1)
  109. assert_nil content.previous
  110. end
  111. def test_previous_for_version_should_return_previous_version
  112. content = WikiContent::Version.find_by_page_id_and_version(1, 3)
  113. assert_not_nil content.previous
  114. assert_equal 2, content.previous.version
  115. end
  116. def test_previous_for_version_with_gap_should_return_previous_available_version
  117. WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
  118. content = WikiContent::Version.find_by_page_id_and_version(1, 3)
  119. assert_not_nil content.previous
  120. assert_equal 1, content.previous.version
  121. end
  122. def test_next_for_last_version_should_return_nil
  123. content = WikiContent::Version.find_by_page_id_and_version(1, 3)
  124. assert_nil content.next
  125. end
  126. def test_next_for_version_should_return_next_version
  127. content = WikiContent::Version.find_by_page_id_and_version(1, 1)
  128. assert_not_nil content.next
  129. assert_equal 2, content.next.version
  130. end
  131. def test_next_for_version_with_gap_should_return_next_available_version
  132. WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
  133. content = WikiContent::Version.find_by_page_id_and_version(1, 1)
  134. assert_not_nil content.next
  135. assert_equal 3, content.next.version
  136. end
  137. end