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_version_test.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class WikiContentVersionTest < ActiveSupport::TestCase
  20. fixtures :projects, :users, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
  21. def setup
  22. User.current = nil
  23. end
  24. def test_should_respond_to_attachments
  25. v = WikiContentVersion.find(2)
  26. assert v.respond_to?(:attachments)
  27. end
  28. def test_destroy
  29. v = WikiContentVersion.find(2)
  30. assert_difference 'WikiContentVersion.count', -1 do
  31. v.destroy
  32. end
  33. end
  34. def test_destroy_last_version_should_revert_content
  35. v = WikiContentVersion.find(3)
  36. assert_no_difference 'WikiPage.count' do
  37. assert_no_difference 'WikiContent.count' do
  38. assert_difference 'WikiContentVersion.count', -1 do
  39. assert v.destroy
  40. end
  41. end
  42. end
  43. c = WikiContent.find(1)
  44. v = c.versions.last
  45. assert_equal 2, c.version
  46. assert_equal v.version, c.version
  47. assert_equal v.comments, c.comments
  48. assert_equal v.text, c.text
  49. assert_equal v.author, c.author
  50. assert_equal v.updated_on, c.updated_on
  51. end
  52. def test_destroy_all_versions_should_delete_page
  53. WikiContentVersion.find(1).destroy
  54. WikiContentVersion.find(2).destroy
  55. v = WikiContentVersion.find(3)
  56. assert_difference 'WikiPage.count', -1 do
  57. assert_difference 'WikiContent.count', -1 do
  58. assert_difference 'WikiContentVersion.count', -1 do
  59. assert v.destroy
  60. end
  61. end
  62. end
  63. assert_nil WikiPage.find_by_id(1)
  64. end
  65. end