Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

wiki_content_test.rb 5.8KB

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