##// END OF EJS Templates
remove trailing white space from test/unit/wiki_content_test.rb...
Toshi MARUYAMA -
r11974:53d749eb79ff
parent child
Show More
@@ -1,165 +1,165
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class WikiContentTest < ActiveSupport::TestCase
21 21 fixtures :projects, :enabled_modules,
22 22 :users, :members, :member_roles, :roles,
23 23 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
24 24
25 25 def setup
26 26 @wiki = Wiki.find(1)
27 27 @page = @wiki.pages.first
28 28 end
29 29
30 30 def test_create
31 31 page = WikiPage.new(:wiki => @wiki, :title => "Page")
32 32 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
33 33 assert page.save
34 34 page.reload
35 35
36 36 content = page.content
37 37 assert_kind_of WikiContent, content
38 38 assert_equal 1, content.version
39 39 assert_equal 1, content.versions.length
40 40 assert_equal "Content text", content.text
41 41 assert_equal "My comment", content.comments
42 42 assert_equal User.find(1), content.author
43 43 assert_equal content.text, content.versions.last.text
44 44 end
45 45
46 46 def test_create_should_send_email_notification
47 47 ActionMailer::Base.deliveries.clear
48 48 page = WikiPage.new(:wiki => @wiki, :title => "A new page")
49 49 page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
50 50
51 51 with_settings :default_language => 'en', :notified_events => %w(wiki_content_added) do
52 52 assert page.save
53 53 end
54 54
55 55 assert_equal 1, ActionMailer::Base.deliveries.size
56 56 assert_include 'wiki page has been added', mail_body(ActionMailer::Base.deliveries.last)
57 57 end
58 58
59 59 def test_update_should_be_versioned
60 60 content = @page.content
61 61 version_count = content.version
62 62 content.text = "My new content"
63 63 assert_difference 'WikiContent::Version.count' do
64 64 assert content.save
65 65 end
66 66 content.reload
67 67 assert_equal version_count+1, content.version
68 68 assert_equal version_count+1, content.versions.length
69 69
70 70 version = WikiContent::Version.first(:order => 'id DESC')
71 71 assert_equal @page.id, version.page_id
72 72 assert_equal '', version.compression
73 73 assert_equal "My new content", version.data
74 74 assert_equal "My new content", version.text
75 75 end
76 76
77 77 def test_update_with_gzipped_history
78 78 with_settings :wiki_compression => 'gzip' do
79 79 content = @page.content
80 80 content.text = "My new content"
81 81 assert_difference 'WikiContent::Version.count' do
82 82 assert content.save
83 83 end
84 84 end
85 85
86 86 version = WikiContent::Version.first(:order => 'id DESC')
87 87 assert_equal @page.id, version.page_id
88 88 assert_equal 'gzip', version.compression
89 89 assert_not_equal "My new content", version.data
90 90 assert_equal "My new content", version.text
91 91 end
92 92
93 93 def test_update_should_send_email_notification
94 94 ActionMailer::Base.deliveries.clear
95 95 content = @page.content
96 96 content.text = "My new content"
97 97
98 98 with_settings :notified_events => %w(wiki_content_updated) do
99 99 assert content.save
100 100 end
101 101
102 102 assert_equal 1, ActionMailer::Base.deliveries.size
103 103 assert_include 'wiki page has been updated', mail_body(ActionMailer::Base.deliveries.last)
104 104 end
105 105
106 106 def test_fetch_history
107 107 assert !@page.content.versions.empty?
108 108 @page.content.versions.each do |version|
109 109 assert_kind_of String, version.text
110 110 end
111 111 end
112 112
113 113 def test_large_text_should_not_be_truncated_to_64k
114 114 page = WikiPage.new(:wiki => @wiki, :title => "Big page")
115 115 page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1))
116 116 assert page.save
117 117 page.reload
118 118 assert_equal 500.kilobyte, page.content.text.size
119 119 end
120
120
121 121 def test_current_version
122 122 content = WikiContent.find(11)
123 123 assert_equal true, content.current_version?
124 124 assert_equal true, content.versions.first(:order => 'version DESC').current_version?
125 125 assert_equal false, content.versions.first(:order => 'version ASC').current_version?
126 126 end
127 127
128 128 def test_previous_for_first_version_should_return_nil
129 129 content = WikiContent::Version.find_by_page_id_and_version(1, 1)
130 130 assert_nil content.previous
131 131 end
132 132
133 133 def test_previous_for_version_should_return_previous_version
134 134 content = WikiContent::Version.find_by_page_id_and_version(1, 3)
135 135 assert_not_nil content.previous
136 136 assert_equal 2, content.previous.version
137 137 end
138 138
139 139 def test_previous_for_version_with_gap_should_return_previous_available_version
140 140 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
141 141
142 142 content = WikiContent::Version.find_by_page_id_and_version(1, 3)
143 143 assert_not_nil content.previous
144 144 assert_equal 1, content.previous.version
145 145 end
146 146
147 147 def test_next_for_last_version_should_return_nil
148 148 content = WikiContent::Version.find_by_page_id_and_version(1, 3)
149 149 assert_nil content.next
150 150 end
151 151
152 152 def test_next_for_version_should_return_next_version
153 153 content = WikiContent::Version.find_by_page_id_and_version(1, 1)
154 154 assert_not_nil content.next
155 155 assert_equal 2, content.next.version
156 156 end
157 157
158 158 def test_next_for_version_with_gap_should_return_next_available_version
159 159 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
160 160
161 161 content = WikiContent::Version.find_by_page_id_and_version(1, 1)
162 162 assert_not_nil content.next
163 163 assert_equal 3, content.next.version
164 164 end
165 165 end
General Comments 0
You need to be logged in to leave comments. Login now