To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / .svn / text-base / wiki_content_test.rb.svn-base @ 441:cbce1fd3b1b7

History | View | Annotate | Download (3.01 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 441:cbce1fd3b1b7 Chris
#
9 0:513646585e45 Chris
# 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 441:cbce1fd3b1b7 Chris
#
14 0:513646585e45 Chris
# 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
18 119:8661b858af72 Chris
require File.expand_path('../../test_helper', __FILE__)
19 0:513646585e45 Chris
20
class WikiContentTest < ActiveSupport::TestCase
21
  fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :users
22
23
  def setup
24
    @wiki = Wiki.find(1)
25
    @page = @wiki.pages.first
26
  end
27 441:cbce1fd3b1b7 Chris
28 0:513646585e45 Chris
  def test_create
29 441:cbce1fd3b1b7 Chris
    page = WikiPage.new(:wiki => @wiki, :title => "Page")
30 0:513646585e45 Chris
    page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
31
    assert page.save
32
    page.reload
33 441:cbce1fd3b1b7 Chris
34 0:513646585e45 Chris
    content = page.content
35
    assert_kind_of WikiContent, content
36
    assert_equal 1, content.version
37
    assert_equal 1, content.versions.length
38
    assert_equal "Content text", content.text
39
    assert_equal "My comment", content.comments
40
    assert_equal User.find(1), content.author
41
    assert_equal content.text, content.versions.last.text
42
  end
43 441:cbce1fd3b1b7 Chris
44 0:513646585e45 Chris
  def test_create_should_send_email_notification
45
    Setting.notified_events = ['wiki_content_added']
46
    ActionMailer::Base.deliveries.clear
47 441:cbce1fd3b1b7 Chris
    page = WikiPage.new(:wiki => @wiki, :title => "A new page")
48 0:513646585e45 Chris
    page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
49
    assert page.save
50 441:cbce1fd3b1b7 Chris
51 0:513646585e45 Chris
    assert_equal 1, ActionMailer::Base.deliveries.size
52
  end
53
54
  def test_update
55
    content = @page.content
56
    version_count = content.version
57
    content.text = "My new content"
58
    assert content.save
59
    content.reload
60
    assert_equal version_count+1, content.version
61
    assert_equal version_count+1, content.versions.length
62
  end
63 441:cbce1fd3b1b7 Chris
64 0:513646585e45 Chris
  def test_update_should_send_email_notification
65
    Setting.notified_events = ['wiki_content_updated']
66
    ActionMailer::Base.deliveries.clear
67
    content = @page.content
68
    content.text = "My new content"
69
    assert content.save
70 441:cbce1fd3b1b7 Chris
71 0:513646585e45 Chris
    assert_equal 1, ActionMailer::Base.deliveries.size
72
  end
73 441:cbce1fd3b1b7 Chris
74 0:513646585e45 Chris
  def test_fetch_history
75
    assert !@page.content.versions.empty?
76
    @page.content.versions.each do |version|
77
      assert_kind_of String, version.text
78
    end
79
  end
80 441:cbce1fd3b1b7 Chris
81 0:513646585e45 Chris
  def test_large_text_should_not_be_truncated_to_64k
82 441:cbce1fd3b1b7 Chris
    page = WikiPage.new(:wiki => @wiki, :title => "Big page")
83 0:513646585e45 Chris
    page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
84
    assert page.save
85
    page.reload
86
    assert_equal 500.kilobyte, page.content.text.size
87
  end
88
end