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 / .svn / pristine / 5b / 5b2317c90ed81995ffba20202367b84382beccbf.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (3.3 KB)

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

    
18
require File.expand_path('../../test_helper', __FILE__)
19

    
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

    
28
  def test_create
29
    page = WikiPage.new(:wiki => @wiki, :title => "Page")
30
    page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
31
    assert page.save
32
    page.reload
33

    
34
    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

    
44
  def test_create_should_send_email_notification
45
    Setting.notified_events = ['wiki_content_added']
46
    ActionMailer::Base.deliveries.clear
47
    page = WikiPage.new(:wiki => @wiki, :title => "A new page")
48
    page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
49
    assert page.save
50

    
51
    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

    
64
  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

    
71
    assert_equal 1, ActionMailer::Base.deliveries.size
72
  end
73

    
74
  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

    
81
  def test_large_text_should_not_be_truncated_to_64k
82
    page = WikiPage.new(:wiki => @wiki, :title => "Big page")
83
    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
  
89
  def test_current_version
90
    content = WikiContent.find(11)
91
    assert_equal true, content.current_version?
92
    assert_equal true, content.versions.first(:order => 'version DESC').current_version?
93
    assert_equal false, content.versions.first(:order => 'version ASC').current_version?
94
  end
95
end