@@ -1,165 +1,165 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 | ActionMailer::Base.deliveries.clear |
|
47 | ActionMailer::Base.deliveries.clear | |
48 | page = WikiPage.new(:wiki => @wiki, :title => "A new page") |
|
48 | page = WikiPage.new(:wiki => @wiki, :title => "A new page") | |
49 | page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment") |
|
49 | page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment") | |
50 |
|
50 | |||
51 | with_settings :default_language => 'en', :notified_events => %w(wiki_content_added) do |
|
51 | with_settings :default_language => 'en', :notified_events => %w(wiki_content_added) do | |
52 | assert page.save |
|
52 | assert page.save | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
55 | assert_equal 1, ActionMailer::Base.deliveries.size | |
56 | assert_include 'wiki page has been added', mail_body(ActionMailer::Base.deliveries.last) |
|
56 | assert_include 'wiki page has been added', mail_body(ActionMailer::Base.deliveries.last) | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def test_update_should_be_versioned |
|
59 | def test_update_should_be_versioned | |
60 | content = @page.content |
|
60 | content = @page.content | |
61 | version_count = content.version |
|
61 | version_count = content.version | |
62 | content.text = "My new content" |
|
62 | content.text = "My new content" | |
63 | assert_difference 'WikiContent::Version.count' do |
|
63 | assert_difference 'WikiContent::Version.count' do | |
64 | assert content.save |
|
64 | assert content.save | |
65 | end |
|
65 | end | |
66 | content.reload |
|
66 | content.reload | |
67 | assert_equal version_count+1, content.version |
|
67 | assert_equal version_count+1, content.version | |
68 | assert_equal version_count+1, content.versions.length |
|
68 | assert_equal version_count+1, content.versions.length | |
69 |
|
69 | |||
70 | version = WikiContent::Version.first(:order => 'id DESC') |
|
70 | version = WikiContent::Version.first(:order => 'id DESC') | |
71 | assert_equal @page.id, version.page_id |
|
71 | assert_equal @page.id, version.page_id | |
72 | assert_equal '', version.compression |
|
72 | assert_equal '', version.compression | |
73 | assert_equal "My new content", version.data |
|
73 | assert_equal "My new content", version.data | |
74 | assert_equal "My new content", version.text |
|
74 | assert_equal "My new content", version.text | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_update_with_gzipped_history |
|
77 | def test_update_with_gzipped_history | |
78 | with_settings :wiki_compression => 'gzip' do |
|
78 | with_settings :wiki_compression => 'gzip' do | |
79 | content = @page.content |
|
79 | content = @page.content | |
80 | content.text = "My new content" |
|
80 | content.text = "My new content" | |
81 | assert_difference 'WikiContent::Version.count' do |
|
81 | assert_difference 'WikiContent::Version.count' do | |
82 | assert content.save |
|
82 | assert content.save | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | version = WikiContent::Version.first(:order => 'id DESC') |
|
86 | version = WikiContent::Version.first(:order => 'id DESC') | |
87 | assert_equal @page.id, version.page_id |
|
87 | assert_equal @page.id, version.page_id | |
88 | assert_equal 'gzip', version.compression |
|
88 | assert_equal 'gzip', version.compression | |
89 | assert_not_equal "My new content", version.data |
|
89 | assert_not_equal "My new content", version.data | |
90 | assert_equal "My new content", version.text |
|
90 | assert_equal "My new content", version.text | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_update_should_send_email_notification |
|
93 | def test_update_should_send_email_notification | |
94 | ActionMailer::Base.deliveries.clear |
|
94 | ActionMailer::Base.deliveries.clear | |
95 | content = @page.content |
|
95 | content = @page.content | |
96 | content.text = "My new content" |
|
96 | content.text = "My new content" | |
97 |
|
97 | |||
98 | with_settings :notified_events => %w(wiki_content_updated) do |
|
98 | with_settings :notified_events => %w(wiki_content_updated) do | |
99 | assert content.save |
|
99 | assert content.save | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
102 | assert_equal 1, ActionMailer::Base.deliveries.size | |
103 | assert_include 'wiki page has been updated', mail_body(ActionMailer::Base.deliveries.last) |
|
103 | assert_include 'wiki page has been updated', mail_body(ActionMailer::Base.deliveries.last) | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_fetch_history |
|
106 | def test_fetch_history | |
107 | assert !@page.content.versions.empty? |
|
107 | assert !@page.content.versions.empty? | |
108 | @page.content.versions.each do |version| |
|
108 | @page.content.versions.each do |version| | |
109 | assert_kind_of String, version.text |
|
109 | assert_kind_of String, version.text | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_large_text_should_not_be_truncated_to_64k |
|
113 | def test_large_text_should_not_be_truncated_to_64k | |
114 | page = WikiPage.new(:wiki => @wiki, :title => "Big page") |
|
114 | page = WikiPage.new(:wiki => @wiki, :title => "Big page") | |
115 | page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1)) |
|
115 | page.content = WikiContent.new(:text => "a" * 500.kilobyte, :author => User.find(1)) | |
116 | assert page.save |
|
116 | assert page.save | |
117 | page.reload |
|
117 | page.reload | |
118 | assert_equal 500.kilobyte, page.content.text.size |
|
118 | assert_equal 500.kilobyte, page.content.text.size | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_current_version |
|
121 | def test_current_version | |
122 | content = WikiContent.find(11) |
|
122 | content = WikiContent.find(11) | |
123 | assert_equal true, content.current_version? |
|
123 | assert_equal true, content.current_version? | |
124 | assert_equal true, content.versions.first(:order => 'version DESC').current_version? |
|
124 | assert_equal true, content.versions.first(:order => 'version DESC').current_version? | |
125 | assert_equal false, content.versions.first(:order => 'version ASC').current_version? |
|
125 | assert_equal false, content.versions.first(:order => 'version ASC').current_version? | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_previous_for_first_version_should_return_nil |
|
128 | def test_previous_for_first_version_should_return_nil | |
129 | content = WikiContent::Version.find_by_page_id_and_version(1, 1) |
|
129 | content = WikiContent::Version.find_by_page_id_and_version(1, 1) | |
130 | assert_nil content.previous |
|
130 | assert_nil content.previous | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def test_previous_for_version_should_return_previous_version |
|
133 | def test_previous_for_version_should_return_previous_version | |
134 | content = WikiContent::Version.find_by_page_id_and_version(1, 3) |
|
134 | content = WikiContent::Version.find_by_page_id_and_version(1, 3) | |
135 | assert_not_nil content.previous |
|
135 | assert_not_nil content.previous | |
136 | assert_equal 2, content.previous.version |
|
136 | assert_equal 2, content.previous.version | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | def test_previous_for_version_with_gap_should_return_previous_available_version |
|
139 | def test_previous_for_version_with_gap_should_return_previous_available_version | |
140 | WikiContent::Version.find_by_page_id_and_version(1, 2).destroy |
|
140 | WikiContent::Version.find_by_page_id_and_version(1, 2).destroy | |
141 |
|
141 | |||
142 | content = WikiContent::Version.find_by_page_id_and_version(1, 3) |
|
142 | content = WikiContent::Version.find_by_page_id_and_version(1, 3) | |
143 | assert_not_nil content.previous |
|
143 | assert_not_nil content.previous | |
144 | assert_equal 1, content.previous.version |
|
144 | assert_equal 1, content.previous.version | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_next_for_last_version_should_return_nil |
|
147 | def test_next_for_last_version_should_return_nil | |
148 | content = WikiContent::Version.find_by_page_id_and_version(1, 3) |
|
148 | content = WikiContent::Version.find_by_page_id_and_version(1, 3) | |
149 | assert_nil content.next |
|
149 | assert_nil content.next | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | def test_next_for_version_should_return_next_version |
|
152 | def test_next_for_version_should_return_next_version | |
153 | content = WikiContent::Version.find_by_page_id_and_version(1, 1) |
|
153 | content = WikiContent::Version.find_by_page_id_and_version(1, 1) | |
154 | assert_not_nil content.next |
|
154 | assert_not_nil content.next | |
155 | assert_equal 2, content.next.version |
|
155 | assert_equal 2, content.next.version | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def test_next_for_version_with_gap_should_return_next_available_version |
|
158 | def test_next_for_version_with_gap_should_return_next_available_version | |
159 | WikiContent::Version.find_by_page_id_and_version(1, 2).destroy |
|
159 | WikiContent::Version.find_by_page_id_and_version(1, 2).destroy | |
160 |
|
160 | |||
161 | content = WikiContent::Version.find_by_page_id_and_version(1, 1) |
|
161 | content = WikiContent::Version.find_by_page_id_and_version(1, 1) | |
162 | assert_not_nil content.next |
|
162 | assert_not_nil content.next | |
163 | assert_equal 3, content.next.version |
|
163 | assert_equal 3, content.next.version | |
164 | end |
|
164 | end | |
165 | end |
|
165 | end |
General Comments 0
You need to be logged in to leave comments.
Login now