@@ -1,97 +1,121 | |||||
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 :projects, :enabled_modules, |
|
21 | fixtures :projects, :enabled_modules, | |
22 | :users, :members, :member_roles, :roles, |
|
22 | :users, :members, :member_roles, :roles, | |
23 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions |
|
23 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions | |
24 |
|
24 | |||
25 | def setup |
|
25 | def setup | |
26 | @wiki = Wiki.find(1) |
|
26 | @wiki = Wiki.find(1) | |
27 | @page = @wiki.pages.first |
|
27 | @page = @wiki.pages.first | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def test_create |
|
30 | def test_create | |
31 | page = WikiPage.new(:wiki => @wiki, :title => "Page") |
|
31 | page = WikiPage.new(:wiki => @wiki, :title => "Page") | |
32 | 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") | |
33 | assert page.save |
|
33 | assert page.save | |
34 | page.reload |
|
34 | page.reload | |
35 |
|
35 | |||
36 | content = page.content |
|
36 | content = page.content | |
37 | assert_kind_of WikiContent, content |
|
37 | assert_kind_of WikiContent, content | |
38 | assert_equal 1, content.version |
|
38 | assert_equal 1, content.version | |
39 | assert_equal 1, content.versions.length |
|
39 | assert_equal 1, content.versions.length | |
40 | assert_equal "Content text", content.text |
|
40 | assert_equal "Content text", content.text | |
41 | assert_equal "My comment", content.comments |
|
41 | assert_equal "My comment", content.comments | |
42 | assert_equal User.find(1), content.author |
|
42 | assert_equal User.find(1), content.author | |
43 | assert_equal content.text, content.versions.last.text |
|
43 | assert_equal content.text, content.versions.last.text | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_create_should_send_email_notification |
|
46 | def test_create_should_send_email_notification | |
47 | Setting.notified_events = ['wiki_content_added'] |
|
47 | Setting.notified_events = ['wiki_content_added'] | |
48 | ActionMailer::Base.deliveries.clear |
|
48 | ActionMailer::Base.deliveries.clear | |
49 | page = WikiPage.new(:wiki => @wiki, :title => "A new page") |
|
49 | page = WikiPage.new(:wiki => @wiki, :title => "A new page") | |
50 | 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") | |
51 | assert page.save |
|
51 | assert page.save | |
52 |
|
52 | |||
53 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
53 | assert_equal 1, ActionMailer::Base.deliveries.size | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def test_update |
|
56 | def test_update_should_be_versioned | |
57 | content = @page.content |
|
57 | content = @page.content | |
58 | version_count = content.version |
|
58 | version_count = content.version | |
59 | content.text = "My new content" |
|
59 | content.text = "My new content" | |
60 | assert content.save |
|
60 | assert_difference 'WikiContent::Version.count' do | |
|
61 | assert content.save | |||
|
62 | end | |||
61 | content.reload |
|
63 | content.reload | |
62 | assert_equal version_count+1, content.version |
|
64 | assert_equal version_count+1, content.version | |
63 | assert_equal version_count+1, content.versions.length |
|
65 | assert_equal version_count+1, content.versions.length | |
|
66 | ||||
|
67 | version = WikiContent::Version.first(:order => 'id DESC') | |||
|
68 | assert_equal @page.id, version.page_id | |||
|
69 | assert_equal '', version.compression | |||
|
70 | assert_equal "My new content", version.data | |||
|
71 | assert_equal "My new content", version.text | |||
|
72 | end | |||
|
73 | ||||
|
74 | def test_update_with_gzipped_history | |||
|
75 | with_settings :wiki_compression => 'gzip' do | |||
|
76 | content = @page.content | |||
|
77 | content.text = "My new content" | |||
|
78 | assert_difference 'WikiContent::Version.count' do | |||
|
79 | assert content.save | |||
|
80 | end | |||
|
81 | end | |||
|
82 | ||||
|
83 | version = WikiContent::Version.first(:order => 'id DESC') | |||
|
84 | assert_equal @page.id, version.page_id | |||
|
85 | assert_equal 'gzip', version.compression | |||
|
86 | assert_not_equal "My new content", version.data | |||
|
87 | assert_equal "My new content", version.text | |||
64 | end |
|
88 | end | |
65 |
|
89 | |||
66 | def test_update_should_send_email_notification |
|
90 | def test_update_should_send_email_notification | |
67 | Setting.notified_events = ['wiki_content_updated'] |
|
91 | Setting.notified_events = ['wiki_content_updated'] | |
68 | ActionMailer::Base.deliveries.clear |
|
92 | ActionMailer::Base.deliveries.clear | |
69 | content = @page.content |
|
93 | content = @page.content | |
70 | content.text = "My new content" |
|
94 | content.text = "My new content" | |
71 | assert content.save |
|
95 | assert content.save | |
72 |
|
96 | |||
73 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
97 | assert_equal 1, ActionMailer::Base.deliveries.size | |
74 | end |
|
98 | end | |
75 |
|
99 | |||
76 | def test_fetch_history |
|
100 | def test_fetch_history | |
77 | assert !@page.content.versions.empty? |
|
101 | assert !@page.content.versions.empty? | |
78 | @page.content.versions.each do |version| |
|
102 | @page.content.versions.each do |version| | |
79 | assert_kind_of String, version.text |
|
103 | assert_kind_of String, version.text | |
80 | end |
|
104 | end | |
81 | end |
|
105 | end | |
82 |
|
106 | |||
83 | def test_large_text_should_not_be_truncated_to_64k |
|
107 | def test_large_text_should_not_be_truncated_to_64k | |
84 | page = WikiPage.new(:wiki => @wiki, :title => "Big page") |
|
108 | page = WikiPage.new(:wiki => @wiki, :title => "Big page") | |
85 | page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1)) |
|
109 | page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1)) | |
86 | assert page.save |
|
110 | assert page.save | |
87 | page.reload |
|
111 | page.reload | |
88 | assert_equal 500.kilobyte, page.content.text.size |
|
112 | assert_equal 500.kilobyte, page.content.text.size | |
89 | end |
|
113 | end | |
90 |
|
114 | |||
91 | def test_current_version |
|
115 | def test_current_version | |
92 | content = WikiContent.find(11) |
|
116 | content = WikiContent.find(11) | |
93 | assert_equal true, content.current_version? |
|
117 | assert_equal true, content.current_version? | |
94 | assert_equal true, content.versions.first(:order => 'version DESC').current_version? |
|
118 | assert_equal true, content.versions.first(:order => 'version DESC').current_version? | |
95 | assert_equal false, content.versions.first(:order => 'version ASC').current_version? |
|
119 | assert_equal false, content.versions.first(:order => 'version ASC').current_version? | |
96 | end |
|
120 | end | |
97 | end |
|
121 | end |
General Comments 0
You need to be logged in to leave comments.
Login now