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.8KB

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