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 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 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. Setting.notified_events = ['wiki_content_added']
  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. assert page.save
  46. assert_equal 1, ActionMailer::Base.deliveries.size
  47. end
  48. def test_update
  49. content = @page.content
  50. version_count = content.version
  51. content.text = "My new content"
  52. assert content.save
  53. content.reload
  54. assert_equal version_count+1, content.version
  55. assert_equal version_count+1, content.versions.length
  56. end
  57. def test_update_should_send_email_notification
  58. Setting.notified_events = ['wiki_content_updated']
  59. ActionMailer::Base.deliveries.clear
  60. content = @page.content
  61. content.text = "My new content"
  62. assert content.save
  63. assert_equal 1, ActionMailer::Base.deliveries.size
  64. end
  65. def test_fetch_history
  66. assert !@page.content.versions.empty?
  67. @page.content.versions.each do |version|
  68. assert_kind_of String, version.text
  69. end
  70. end
  71. def test_large_text_should_not_be_truncated_to_64k
  72. page = WikiPage.new(:wiki => @wiki, :title => "Big page")
  73. page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
  74. assert page.save
  75. page.reload
  76. assert_equal 500.kilobyte, page.content.text.size
  77. end
  78. def test_current_version
  79. content = WikiContent.find(11)
  80. assert_equal true, content.current_version?
  81. assert_equal true, content.versions.first(:order => 'version DESC').current_version?
  82. assert_equal false, content.versions.first(:order => 'version ASC').current_version?
  83. end
  84. end