##// END OF EJS Templates
add missing fixtures to unit wiki_content_test...
Toshi MARUYAMA -
r9116:dd1b2876b1d6
parent child
Show More
@@ -1,95 +1,97
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class WikiContentTest < ActiveSupport::TestCase
20 class WikiContentTest < ActiveSupport::TestCase
21 fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :users
21 fixtures :projects, :enabled_modules,
22 :users, :members, :member_roles, :roles,
23 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
22
24
23 def setup
25 def setup
24 @wiki = Wiki.find(1)
26 @wiki = Wiki.find(1)
25 @page = @wiki.pages.first
27 @page = @wiki.pages.first
26 end
28 end
27
29
28 def test_create
30 def test_create
29 page = WikiPage.new(:wiki => @wiki, :title => "Page")
31 page = WikiPage.new(:wiki => @wiki, :title => "Page")
30 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
32 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
31 assert page.save
33 assert page.save
32 page.reload
34 page.reload
33
35
34 content = page.content
36 content = page.content
35 assert_kind_of WikiContent, content
37 assert_kind_of WikiContent, content
36 assert_equal 1, content.version
38 assert_equal 1, content.version
37 assert_equal 1, content.versions.length
39 assert_equal 1, content.versions.length
38 assert_equal "Content text", content.text
40 assert_equal "Content text", content.text
39 assert_equal "My comment", content.comments
41 assert_equal "My comment", content.comments
40 assert_equal User.find(1), content.author
42 assert_equal User.find(1), content.author
41 assert_equal content.text, content.versions.last.text
43 assert_equal content.text, content.versions.last.text
42 end
44 end
43
45
44 def test_create_should_send_email_notification
46 def test_create_should_send_email_notification
45 Setting.notified_events = ['wiki_content_added']
47 Setting.notified_events = ['wiki_content_added']
46 ActionMailer::Base.deliveries.clear
48 ActionMailer::Base.deliveries.clear
47 page = WikiPage.new(:wiki => @wiki, :title => "A new page")
49 page = WikiPage.new(:wiki => @wiki, :title => "A new page")
48 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
50 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
49 assert page.save
51 assert page.save
50
52
51 assert_equal 1, ActionMailer::Base.deliveries.size
53 assert_equal 1, ActionMailer::Base.deliveries.size
52 end
54 end
53
55
54 def test_update
56 def test_update
55 content = @page.content
57 content = @page.content
56 version_count = content.version
58 version_count = content.version
57 content.text = "My new content"
59 content.text = "My new content"
58 assert content.save
60 assert content.save
59 content.reload
61 content.reload
60 assert_equal version_count+1, content.version
62 assert_equal version_count+1, content.version
61 assert_equal version_count+1, content.versions.length
63 assert_equal version_count+1, content.versions.length
62 end
64 end
63
65
64 def test_update_should_send_email_notification
66 def test_update_should_send_email_notification
65 Setting.notified_events = ['wiki_content_updated']
67 Setting.notified_events = ['wiki_content_updated']
66 ActionMailer::Base.deliveries.clear
68 ActionMailer::Base.deliveries.clear
67 content = @page.content
69 content = @page.content
68 content.text = "My new content"
70 content.text = "My new content"
69 assert content.save
71 assert content.save
70
72
71 assert_equal 1, ActionMailer::Base.deliveries.size
73 assert_equal 1, ActionMailer::Base.deliveries.size
72 end
74 end
73
75
74 def test_fetch_history
76 def test_fetch_history
75 assert !@page.content.versions.empty?
77 assert !@page.content.versions.empty?
76 @page.content.versions.each do |version|
78 @page.content.versions.each do |version|
77 assert_kind_of String, version.text
79 assert_kind_of String, version.text
78 end
80 end
79 end
81 end
80
82
81 def test_large_text_should_not_be_truncated_to_64k
83 def test_large_text_should_not_be_truncated_to_64k
82 page = WikiPage.new(:wiki => @wiki, :title => "Big page")
84 page = WikiPage.new(:wiki => @wiki, :title => "Big page")
83 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
85 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
84 assert page.save
86 assert page.save
85 page.reload
87 page.reload
86 assert_equal 500.kilobyte, page.content.text.size
88 assert_equal 500.kilobyte, page.content.text.size
87 end
89 end
88
90
89 def test_current_version
91 def test_current_version
90 content = WikiContent.find(11)
92 content = WikiContent.find(11)
91 assert_equal true, content.current_version?
93 assert_equal true, content.current_version?
92 assert_equal true, content.versions.first(:order => 'version DESC').current_version?
94 assert_equal true, content.versions.first(:order => 'version DESC').current_version?
93 assert_equal false, content.versions.first(:order => 'version ASC').current_version?
95 assert_equal false, content.versions.first(:order => 'version ASC').current_version?
94 end
96 end
95 end
97 end
General Comments 0
You need to be logged in to leave comments. Login now