@@ -0,0 +1,11 | |||
|
1 | class ChangeWikiContentsCommentsLimitTo1024 < ActiveRecord::Migration | |
|
2 | def self.up | |
|
3 | change_column :wiki_content_versions, :comments, :string, :limit => 1024, :default => '' | |
|
4 | change_column :wiki_contents, :comments, :string, :limit => 1024, :default => '' | |
|
5 | end | |
|
6 | ||
|
7 | def self.down | |
|
8 | change_column :wiki_content_versions, :comments, :string, :limit => 255, :default => '' | |
|
9 | change_column :wiki_contents, :comments, :string, :limit => 255, :default => '' | |
|
10 | end | |
|
11 | end |
@@ -1,168 +1,168 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 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 'zlib' |
|
19 | 19 | |
|
20 | 20 | class WikiContent < ActiveRecord::Base |
|
21 | 21 | self.locking_column = 'version' |
|
22 | 22 | belongs_to :page, :class_name => 'WikiPage' |
|
23 | 23 | belongs_to :author, :class_name => 'User' |
|
24 | 24 | validates_presence_of :text |
|
25 |
validates_length_of :comments, :maximum => |
|
|
25 | validates_length_of :comments, :maximum => 1024, :allow_nil => true | |
|
26 | 26 | attr_protected :id |
|
27 | 27 | |
|
28 | 28 | acts_as_versioned |
|
29 | 29 | |
|
30 | 30 | after_save :send_notification |
|
31 | 31 | |
|
32 | 32 | def visible?(user=User.current) |
|
33 | 33 | page.visible?(user) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def project |
|
37 | 37 | page.project |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def attachments |
|
41 | 41 | page.nil? ? [] : page.attachments |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def notified_users |
|
45 | 45 | project.notified_users.reject {|user| !visible?(user)} |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | # Returns the mail addresses of users that should be notified |
|
49 | 49 | def recipients |
|
50 | 50 | notified_users.collect(&:mail) |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | # Return true if the content is the current page content |
|
54 | 54 | def current_version? |
|
55 | 55 | true |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | class Version |
|
59 | 59 | belongs_to :page, :class_name => '::WikiPage' |
|
60 | 60 | belongs_to :author, :class_name => '::User' |
|
61 | 61 | attr_protected :data |
|
62 | 62 | |
|
63 | 63 | acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, |
|
64 | 64 | :description => :comments, |
|
65 | 65 | :datetime => :updated_on, |
|
66 | 66 | :type => 'wiki-page', |
|
67 | 67 | :group => :page, |
|
68 | 68 | :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}} |
|
69 | 69 | |
|
70 | 70 | acts_as_activity_provider :type => 'wiki_edits', |
|
71 | 71 | :timestamp => "#{WikiContent.versioned_table_name}.updated_on", |
|
72 | 72 | :author_key => "#{WikiContent.versioned_table_name}.author_id", |
|
73 | 73 | :permission => :view_wiki_edits, |
|
74 | 74 | :scope => select("#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
75 | 75 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
76 | 76 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
77 | 77 | "#{WikiContent.versioned_table_name}.id"). |
|
78 | 78 | joins("LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
79 | 79 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + |
|
80 | 80 | "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id") |
|
81 | 81 | |
|
82 | 82 | after_destroy :page_update_after_destroy |
|
83 | 83 | |
|
84 | 84 | def text=(plain) |
|
85 | 85 | case Setting.wiki_compression |
|
86 | 86 | when 'gzip' |
|
87 | 87 | begin |
|
88 | 88 | self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) |
|
89 | 89 | self.compression = 'gzip' |
|
90 | 90 | rescue |
|
91 | 91 | self.data = plain |
|
92 | 92 | self.compression = '' |
|
93 | 93 | end |
|
94 | 94 | else |
|
95 | 95 | self.data = plain |
|
96 | 96 | self.compression = '' |
|
97 | 97 | end |
|
98 | 98 | plain |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def text |
|
102 | 102 | @text ||= begin |
|
103 | 103 | str = case compression |
|
104 | 104 | when 'gzip' |
|
105 | 105 | Zlib::Inflate.inflate(data) |
|
106 | 106 | else |
|
107 | 107 | # uncompressed data |
|
108 | 108 | data |
|
109 | 109 | end |
|
110 | 110 | str.force_encoding("UTF-8") |
|
111 | 111 | str |
|
112 | 112 | end |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def project |
|
116 | 116 | page.project |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | # Return true if the content is the current page content |
|
120 | 120 | def current_version? |
|
121 | 121 | page.content.version == self.version |
|
122 | 122 | end |
|
123 | 123 | |
|
124 | 124 | # Returns the previous version or nil |
|
125 | 125 | def previous |
|
126 | 126 | @previous ||= WikiContent::Version. |
|
127 | 127 | reorder('version DESC'). |
|
128 | 128 | includes(:author). |
|
129 | 129 | where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | # Returns the next version or nil |
|
133 | 133 | def next |
|
134 | 134 | @next ||= WikiContent::Version. |
|
135 | 135 | reorder('version ASC'). |
|
136 | 136 | includes(:author). |
|
137 | 137 | where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | private |
|
141 | 141 | |
|
142 | 142 | # Updates page's content if the latest version is removed |
|
143 | 143 | # or destroys the page if it was the only version |
|
144 | 144 | def page_update_after_destroy |
|
145 | 145 | latest = page.content.versions.reorder("#{self.class.table_name}.version DESC").first |
|
146 | 146 | if latest && page.content.version != latest.version |
|
147 | 147 | raise ActiveRecord::Rollback unless page.content.revert_to!(latest) |
|
148 | 148 | elsif latest.nil? |
|
149 | 149 | raise ActiveRecord::Rollback unless page.destroy |
|
150 | 150 | end |
|
151 | 151 | end |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | private |
|
155 | 155 | |
|
156 | 156 | def send_notification |
|
157 | 157 | # new_record? returns false in after_save callbacks |
|
158 | 158 | if id_changed? |
|
159 | 159 | if Setting.notified_events.include?('wiki_content_added') |
|
160 | 160 | Mailer.wiki_content_added(self).deliver |
|
161 | 161 | end |
|
162 | 162 | elsif text_changed? |
|
163 | 163 | if Setting.notified_events.include?('wiki_content_updated') |
|
164 | 164 | Mailer.wiki_content_updated(self).deliver |
|
165 | 165 | end |
|
166 | 166 | end |
|
167 | 167 | end |
|
168 | 168 | end |
@@ -1,47 +1,47 | |||
|
1 | 1 | <%= wiki_page_breadcrumb(@page) %> |
|
2 | 2 | |
|
3 | 3 | <h2><%= @page.pretty_title %></h2> |
|
4 | 4 | |
|
5 | 5 | <%= form_for @content, :as => :content, |
|
6 | 6 | :url => {:action => 'update', :id => @page.title}, |
|
7 | 7 | :html => {:method => :put, :multipart => true, :id => 'wiki_form'} do |f| %> |
|
8 | 8 | <%= f.hidden_field :version %> |
|
9 | 9 | <% if @section %> |
|
10 | 10 | <%= hidden_field_tag 'section', @section %> |
|
11 | 11 | <%= hidden_field_tag 'section_hash', @section_hash %> |
|
12 | 12 | <% end %> |
|
13 | 13 | <%= error_messages_for 'content' %> |
|
14 | 14 | |
|
15 | 15 | <div class="box tabular"> |
|
16 | 16 | <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, |
|
17 | 17 | :class => 'wiki-edit', :accesskey => accesskey(:edit) %> |
|
18 | 18 | |
|
19 | 19 | <% if @page.safe_attribute_names.include?('parent_id') && @wiki.pages.any? %> |
|
20 | 20 | <%= fields_for @page do |fp| %> |
|
21 | 21 | <p> |
|
22 | 22 | <label><%= l(:field_parent_title) %></label> |
|
23 | 23 | <%= fp.select :parent_id, |
|
24 | 24 | content_tag('option', '', :value => '') + |
|
25 | 25 | wiki_page_options_for_select( |
|
26 | 26 | @wiki.pages.includes(:parent).to_a - |
|
27 | 27 | @page.self_and_descendants, @page.parent) %> |
|
28 | 28 | </p> |
|
29 | 29 | <% end %> |
|
30 | 30 | <% end %> |
|
31 | 31 | |
|
32 | <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p> | |
|
32 | <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120, :maxlength => 1024 %></p> | |
|
33 | 33 | <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> |
|
34 | 34 | </div> |
|
35 | 35 | |
|
36 | 36 | <p><%= submit_tag l(:button_save) %> |
|
37 | 37 | <%= preview_link({:controller => 'wiki', :action => 'preview', :project_id => @project, :id => @page.title }, 'wiki_form') %></p> |
|
38 | 38 | <%= wikitoolbar_for 'content_text' %> |
|
39 | 39 | <% end %> |
|
40 | 40 | |
|
41 | 41 | <div id="preview" class="wiki"></div> |
|
42 | 42 | |
|
43 | 43 | <% content_for :header_tags do %> |
|
44 | 44 | <%= robot_exclusion_tag %> |
|
45 | 45 | <% end %> |
|
46 | 46 | |
|
47 | 47 | <% html_title @page.pretty_title %> |
@@ -1,961 +1,961 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 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 WikiControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, |
|
22 | 22 | :enabled_modules, :wikis, :wiki_pages, :wiki_contents, |
|
23 | 23 | :wiki_content_versions, :attachments, |
|
24 | 24 | :issues, :issue_statuses |
|
25 | 25 | |
|
26 | 26 | def setup |
|
27 | 27 | User.current = nil |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def test_show_start_page |
|
31 | 31 | get :show, :project_id => 'ecookbook' |
|
32 | 32 | assert_response :success |
|
33 | 33 | assert_template 'show' |
|
34 | 34 | assert_select 'h1', :text => /CookBook documentation/ |
|
35 | 35 | |
|
36 | 36 | # child_pages macro |
|
37 | 37 | assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', |
|
38 | 38 | :text => 'Page with an inline image' |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_export_link |
|
42 | 42 | Role.anonymous.add_permission! :export_wiki_pages |
|
43 | 43 | get :show, :project_id => 'ecookbook' |
|
44 | 44 | assert_response :success |
|
45 | 45 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt' |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_show_page_with_name |
|
49 | 49 | get :show, :project_id => 1, :id => 'Another_page' |
|
50 | 50 | assert_response :success |
|
51 | 51 | assert_template 'show' |
|
52 | 52 | assert_select 'h1', :text => /Another page/ |
|
53 | 53 | # Included page with an inline image |
|
54 | 54 | assert_select 'p', :text => /This is an inline image/ |
|
55 | 55 | assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo' |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_show_old_version |
|
59 | 59 | with_settings :default_language => 'en' do |
|
60 | 60 | get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2' |
|
61 | 61 | end |
|
62 | 62 | assert_response :success |
|
63 | 63 | assert_template 'show' |
|
64 | 64 | |
|
65 | 65 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/ |
|
66 | 66 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/ |
|
67 | 67 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/ |
|
68 | 68 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def test_show_old_version_with_attachments |
|
72 | 72 | page = WikiPage.find(4) |
|
73 | 73 | assert page.attachments.any? |
|
74 | 74 | content = page.content |
|
75 | 75 | content.text = "update" |
|
76 | 76 | content.save! |
|
77 | 77 | |
|
78 | 78 | get :show, :project_id => 'ecookbook', :id => page.title, :version => '1' |
|
79 | 79 | assert_kind_of WikiContent::Version, assigns(:content) |
|
80 | 80 | assert_response :success |
|
81 | 81 | assert_template 'show' |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def test_show_old_version_without_permission_should_be_denied |
|
85 | 85 | Role.anonymous.remove_permission! :view_wiki_edits |
|
86 | 86 | |
|
87 | 87 | get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2' |
|
88 | 88 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2' |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | def test_show_first_version |
|
92 | 92 | with_settings :default_language => 'en' do |
|
93 | 93 | get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1' |
|
94 | 94 | end |
|
95 | 95 | assert_response :success |
|
96 | 96 | assert_template 'show' |
|
97 | 97 | |
|
98 | 98 | assert_select 'a', :text => /Previous/, :count => 0 |
|
99 | 99 | assert_select 'a', :text => /diff/, :count => 0 |
|
100 | 100 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/ |
|
101 | 101 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/ |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def test_show_redirected_page |
|
105 | 105 | WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
|
106 | 106 | |
|
107 | 107 | get :show, :project_id => 'ecookbook', :id => 'Old_title' |
|
108 | 108 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def test_show_with_sidebar |
|
112 | 112 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
113 | 113 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
114 | 114 | page.save! |
|
115 | 115 | |
|
116 | 116 | get :show, :project_id => 1, :id => 'Another_page' |
|
117 | 117 | assert_response :success |
|
118 | 118 | assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/ |
|
119 | 119 | end |
|
120 | 120 | |
|
121 | 121 | def test_show_should_display_section_edit_links |
|
122 | 122 | @request.session[:user_id] = 2 |
|
123 | 123 | get :show, :project_id => 1, :id => 'Page with sections' |
|
124 | 124 | |
|
125 | 125 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0 |
|
126 | 126 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
127 | 127 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' |
|
128 | 128 | end |
|
129 | 129 | |
|
130 | 130 | def test_show_current_version_should_display_section_edit_links |
|
131 | 131 | @request.session[:user_id] = 2 |
|
132 | 132 | get :show, :project_id => 1, :id => 'Page with sections', :version => 3 |
|
133 | 133 | |
|
134 | 134 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | def test_show_old_version_should_not_display_section_edit_links |
|
138 | 138 | @request.session[:user_id] = 2 |
|
139 | 139 | get :show, :project_id => 1, :id => 'Page with sections', :version => 2 |
|
140 | 140 | |
|
141 | 141 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0 |
|
142 | 142 | end |
|
143 | 143 | |
|
144 | 144 | def test_show_unexistent_page_without_edit_right |
|
145 | 145 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
146 | 146 | assert_response 404 |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | def test_show_unexistent_page_with_edit_right |
|
150 | 150 | @request.session[:user_id] = 2 |
|
151 | 151 | get :show, :project_id => 1, :id => 'Unexistent page' |
|
152 | 152 | assert_response :success |
|
153 | 153 | assert_template 'edit' |
|
154 | 154 | end |
|
155 | 155 | |
|
156 | 156 | def test_show_specific_version_of_an_unexistent_page_without_edit_right |
|
157 | 157 | get :show, :project_id => 1, :id => 'Unexistent page', :version => 1 |
|
158 | 158 | assert_response 404 |
|
159 | 159 | end |
|
160 | 160 | |
|
161 | 161 | def test_show_unexistent_page_with_parent_should_preselect_parent |
|
162 | 162 | @request.session[:user_id] = 2 |
|
163 | 163 | get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' |
|
164 | 164 | assert_response :success |
|
165 | 165 | assert_template 'edit' |
|
166 | 166 | assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]' |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | def test_show_should_not_show_history_without_permission |
|
170 | 170 | Role.anonymous.remove_permission! :view_wiki_edits |
|
171 | 171 | get :show, :project_id => 1, :id => 'Page with sections', :version => 2 |
|
172 | 172 | |
|
173 | 173 | assert_response 302 |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def test_show_page_without_content_should_display_the_edit_form |
|
177 | 177 | @request.session[:user_id] = 2 |
|
178 | 178 | WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) |
|
179 | 179 | |
|
180 | 180 | get :show, :project_id => 1, :id => 'NoContent' |
|
181 | 181 | assert_response :success |
|
182 | 182 | assert_template 'edit' |
|
183 | 183 | assert_select 'textarea[name=?]', 'content[text]' |
|
184 | 184 | end |
|
185 | 185 | |
|
186 | 186 | def test_create_page |
|
187 | 187 | @request.session[:user_id] = 2 |
|
188 | 188 | assert_difference 'WikiPage.count' do |
|
189 | 189 | assert_difference 'WikiContent.count' do |
|
190 | 190 | put :update, :project_id => 1, |
|
191 | 191 | :id => 'New page', |
|
192 | 192 | :content => {:comments => 'Created the page', |
|
193 | 193 | :text => "h1. New page\n\nThis is a new page", |
|
194 | 194 | :version => 0} |
|
195 | 195 | end |
|
196 | 196 | end |
|
197 | 197 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
|
198 | 198 | page = Project.find(1).wiki.find_page('New page') |
|
199 | 199 | assert !page.new_record? |
|
200 | 200 | assert_not_nil page.content |
|
201 | 201 | assert_nil page.parent |
|
202 | 202 | assert_equal 'Created the page', page.content.comments |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 | def test_create_page_with_attachments |
|
206 | 206 | @request.session[:user_id] = 2 |
|
207 | 207 | assert_difference 'WikiPage.count' do |
|
208 | 208 | assert_difference 'Attachment.count' do |
|
209 | 209 | put :update, :project_id => 1, |
|
210 | 210 | :id => 'New page', |
|
211 | 211 | :content => {:comments => 'Created the page', |
|
212 | 212 | :text => "h1. New page\n\nThis is a new page", |
|
213 | 213 | :version => 0}, |
|
214 | 214 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
215 | 215 | end |
|
216 | 216 | end |
|
217 | 217 | page = Project.find(1).wiki.find_page('New page') |
|
218 | 218 | assert_equal 1, page.attachments.count |
|
219 | 219 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def test_create_page_with_parent |
|
223 | 223 | @request.session[:user_id] = 2 |
|
224 | 224 | assert_difference 'WikiPage.count' do |
|
225 | 225 | put :update, :project_id => 1, :id => 'New page', |
|
226 | 226 | :content => {:text => "h1. New page\n\nThis is a new page", :version => 0}, |
|
227 | 227 | :wiki_page => {:parent_id => 2} |
|
228 | 228 | end |
|
229 | 229 | page = Project.find(1).wiki.find_page('New page') |
|
230 | 230 | assert_equal WikiPage.find(2), page.parent |
|
231 | 231 | end |
|
232 | 232 | |
|
233 | 233 | def test_edit_page |
|
234 | 234 | @request.session[:user_id] = 2 |
|
235 | 235 | get :edit, :project_id => 'ecookbook', :id => 'Another_page' |
|
236 | 236 | |
|
237 | 237 | assert_response :success |
|
238 | 238 | assert_template 'edit' |
|
239 | 239 | |
|
240 | 240 | assert_select 'textarea[name=?]', 'content[text]', |
|
241 | 241 | :text => WikiPage.find_by_title('Another_page').content.text |
|
242 | 242 | end |
|
243 | 243 | |
|
244 | 244 | def test_edit_section |
|
245 | 245 | @request.session[:user_id] = 2 |
|
246 | 246 | get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2 |
|
247 | 247 | |
|
248 | 248 | assert_response :success |
|
249 | 249 | assert_template 'edit' |
|
250 | 250 | |
|
251 | 251 | page = WikiPage.find_by_title('Page_with_sections') |
|
252 | 252 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
253 | 253 | |
|
254 | 254 | assert_select 'textarea[name=?]', 'content[text]', :text => section |
|
255 | 255 | assert_select 'input[name=section][type=hidden][value="2"]' |
|
256 | 256 | assert_select 'input[name=section_hash][type=hidden][value=?]', hash |
|
257 | 257 | end |
|
258 | 258 | |
|
259 | 259 | def test_edit_invalid_section_should_respond_with_404 |
|
260 | 260 | @request.session[:user_id] = 2 |
|
261 | 261 | get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10 |
|
262 | 262 | |
|
263 | 263 | assert_response 404 |
|
264 | 264 | end |
|
265 | 265 | |
|
266 | 266 | def test_update_page |
|
267 | 267 | @request.session[:user_id] = 2 |
|
268 | 268 | assert_no_difference 'WikiPage.count' do |
|
269 | 269 | assert_no_difference 'WikiContent.count' do |
|
270 | 270 | assert_difference 'WikiContent::Version.count' do |
|
271 | 271 | put :update, :project_id => 1, |
|
272 | 272 | :id => 'Another_page', |
|
273 | 273 | :content => { |
|
274 | 274 | :comments => "my comments", |
|
275 | 275 | :text => "edited", |
|
276 | 276 | :version => 1 |
|
277 | 277 | } |
|
278 | 278 | end |
|
279 | 279 | end |
|
280 | 280 | end |
|
281 | 281 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
282 | 282 | |
|
283 | 283 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
284 | 284 | assert_equal "edited", page.content.text |
|
285 | 285 | assert_equal 2, page.content.version |
|
286 | 286 | assert_equal "my comments", page.content.comments |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | def test_update_page_with_parent |
|
290 | 290 | @request.session[:user_id] = 2 |
|
291 | 291 | assert_no_difference 'WikiPage.count' do |
|
292 | 292 | assert_no_difference 'WikiContent.count' do |
|
293 | 293 | assert_difference 'WikiContent::Version.count' do |
|
294 | 294 | put :update, :project_id => 1, |
|
295 | 295 | :id => 'Another_page', |
|
296 | 296 | :content => { |
|
297 | 297 | :comments => "my comments", |
|
298 | 298 | :text => "edited", |
|
299 | 299 | :version => 1 |
|
300 | 300 | }, |
|
301 | 301 | :wiki_page => {:parent_id => '1'} |
|
302 | 302 | end |
|
303 | 303 | end |
|
304 | 304 | end |
|
305 | 305 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
|
306 | 306 | |
|
307 | 307 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
308 | 308 | assert_equal "edited", page.content.text |
|
309 | 309 | assert_equal 2, page.content.version |
|
310 | 310 | assert_equal "my comments", page.content.comments |
|
311 | 311 | assert_equal WikiPage.find(1), page.parent |
|
312 | 312 | end |
|
313 | 313 | |
|
314 | 314 | def test_update_page_with_failure |
|
315 | 315 | @request.session[:user_id] = 2 |
|
316 | 316 | assert_no_difference 'WikiPage.count' do |
|
317 | 317 | assert_no_difference 'WikiContent.count' do |
|
318 | 318 | assert_no_difference 'WikiContent::Version.count' do |
|
319 | 319 | put :update, :project_id => 1, |
|
320 | 320 | :id => 'Another_page', |
|
321 | 321 | :content => { |
|
322 | :comments => 'a' * 300, # failure here, comment is too long | |
|
322 | :comments => 'a' * 1300, # failure here, comment is too long | |
|
323 | 323 | :text => 'edited' |
|
324 | 324 | }, |
|
325 | 325 | :wiki_page => { |
|
326 | 326 | :parent_id => "" |
|
327 | 327 | } |
|
328 | 328 | end |
|
329 | 329 | end |
|
330 | 330 | end |
|
331 | 331 | assert_response :success |
|
332 | 332 | assert_template 'edit' |
|
333 | 333 | |
|
334 | 334 | assert_select_error /Comment is too long/ |
|
335 | 335 | assert_select 'textarea#content_text', :text => "edited" |
|
336 | 336 | assert_select 'input#content_version[value="1"]' |
|
337 | 337 | end |
|
338 | 338 | |
|
339 | 339 | def test_update_page_with_parent_change_only_should_not_create_content_version |
|
340 | 340 | @request.session[:user_id] = 2 |
|
341 | 341 | assert_no_difference 'WikiPage.count' do |
|
342 | 342 | assert_no_difference 'WikiContent.count' do |
|
343 | 343 | assert_no_difference 'WikiContent::Version.count' do |
|
344 | 344 | put :update, :project_id => 1, |
|
345 | 345 | :id => 'Another_page', |
|
346 | 346 | :content => { |
|
347 | 347 | :comments => '', |
|
348 | 348 | :text => Wiki.find(1).find_page('Another_page').content.text, |
|
349 | 349 | :version => 1 |
|
350 | 350 | }, |
|
351 | 351 | :wiki_page => {:parent_id => '1'} |
|
352 | 352 | end |
|
353 | 353 | end |
|
354 | 354 | end |
|
355 | 355 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
356 | 356 | assert_equal 1, page.content.version |
|
357 | 357 | assert_equal WikiPage.find(1), page.parent |
|
358 | 358 | end |
|
359 | 359 | |
|
360 | 360 | def test_update_page_with_attachments_only_should_not_create_content_version |
|
361 | 361 | @request.session[:user_id] = 2 |
|
362 | 362 | assert_no_difference 'WikiPage.count' do |
|
363 | 363 | assert_no_difference 'WikiContent.count' do |
|
364 | 364 | assert_no_difference 'WikiContent::Version.count' do |
|
365 | 365 | assert_difference 'Attachment.count' do |
|
366 | 366 | put :update, :project_id => 1, |
|
367 | 367 | :id => 'Another_page', |
|
368 | 368 | :content => { |
|
369 | 369 | :comments => '', |
|
370 | 370 | :text => Wiki.find(1).find_page('Another_page').content.text, |
|
371 | 371 | :version => 1 |
|
372 | 372 | }, |
|
373 | 373 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
374 | 374 | end |
|
375 | 375 | end |
|
376 | 376 | end |
|
377 | 377 | end |
|
378 | 378 | page = Wiki.find(1).pages.find_by_title('Another_page') |
|
379 | 379 | assert_equal 1, page.content.version |
|
380 | 380 | end |
|
381 | 381 | |
|
382 | 382 | def test_update_stale_page_should_not_raise_an_error |
|
383 | 383 | @request.session[:user_id] = 2 |
|
384 | 384 | c = Wiki.find(1).find_page('Another_page').content |
|
385 | 385 | c.text = 'Previous text' |
|
386 | 386 | c.save! |
|
387 | 387 | assert_equal 2, c.version |
|
388 | 388 | |
|
389 | 389 | assert_no_difference 'WikiPage.count' do |
|
390 | 390 | assert_no_difference 'WikiContent.count' do |
|
391 | 391 | assert_no_difference 'WikiContent::Version.count' do |
|
392 | 392 | put :update, :project_id => 1, |
|
393 | 393 | :id => 'Another_page', |
|
394 | 394 | :content => { |
|
395 | 395 | :comments => 'My comments', |
|
396 | 396 | :text => 'Text should not be lost', |
|
397 | 397 | :version => 1 |
|
398 | 398 | } |
|
399 | 399 | end |
|
400 | 400 | end |
|
401 | 401 | end |
|
402 | 402 | assert_response :success |
|
403 | 403 | assert_template 'edit' |
|
404 | 404 | assert_select 'div.error', :text => /Data has been updated by another user/ |
|
405 | 405 | assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ |
|
406 | 406 | assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' |
|
407 | 407 | |
|
408 | 408 | c.reload |
|
409 | 409 | assert_equal 'Previous text', c.text |
|
410 | 410 | assert_equal 2, c.version |
|
411 | 411 | end |
|
412 | 412 | |
|
413 | 413 | def test_update_page_without_content_should_create_content |
|
414 | 414 | @request.session[:user_id] = 2 |
|
415 | 415 | page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki) |
|
416 | 416 | |
|
417 | 417 | assert_no_difference 'WikiPage.count' do |
|
418 | 418 | assert_difference 'WikiContent.count' do |
|
419 | 419 | put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'} |
|
420 | 420 | assert_response 302 |
|
421 | 421 | end |
|
422 | 422 | end |
|
423 | 423 | assert_equal 'Some content', page.reload.content.text |
|
424 | 424 | end |
|
425 | 425 | |
|
426 | 426 | def test_update_section |
|
427 | 427 | @request.session[:user_id] = 2 |
|
428 | 428 | page = WikiPage.find_by_title('Page_with_sections') |
|
429 | 429 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
430 | 430 | text = page.content.text |
|
431 | 431 | |
|
432 | 432 | assert_no_difference 'WikiPage.count' do |
|
433 | 433 | assert_no_difference 'WikiContent.count' do |
|
434 | 434 | assert_difference 'WikiContent::Version.count' do |
|
435 | 435 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
436 | 436 | :content => { |
|
437 | 437 | :text => "New section content", |
|
438 | 438 | :version => 3 |
|
439 | 439 | }, |
|
440 | 440 | :section => 2, |
|
441 | 441 | :section_hash => hash |
|
442 | 442 | end |
|
443 | 443 | end |
|
444 | 444 | end |
|
445 | 445 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' |
|
446 | 446 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text |
|
447 | 447 | end |
|
448 | 448 | |
|
449 | 449 | def test_update_section_should_allow_stale_page_update |
|
450 | 450 | @request.session[:user_id] = 2 |
|
451 | 451 | page = WikiPage.find_by_title('Page_with_sections') |
|
452 | 452 | section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
|
453 | 453 | text = page.content.text |
|
454 | 454 | |
|
455 | 455 | assert_no_difference 'WikiPage.count' do |
|
456 | 456 | assert_no_difference 'WikiContent.count' do |
|
457 | 457 | assert_difference 'WikiContent::Version.count' do |
|
458 | 458 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
459 | 459 | :content => { |
|
460 | 460 | :text => "New section content", |
|
461 | 461 | :version => 2 # Current version is 3 |
|
462 | 462 | }, |
|
463 | 463 | :section => 2, |
|
464 | 464 | :section_hash => hash |
|
465 | 465 | end |
|
466 | 466 | end |
|
467 | 467 | end |
|
468 | 468 | assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' |
|
469 | 469 | page.reload |
|
470 | 470 | assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text |
|
471 | 471 | assert_equal 4, page.content.version |
|
472 | 472 | end |
|
473 | 473 | |
|
474 | 474 | def test_update_section_should_not_allow_stale_section_update |
|
475 | 475 | @request.session[:user_id] = 2 |
|
476 | 476 | |
|
477 | 477 | assert_no_difference 'WikiPage.count' do |
|
478 | 478 | assert_no_difference 'WikiContent.count' do |
|
479 | 479 | assert_no_difference 'WikiContent::Version.count' do |
|
480 | 480 | put :update, :project_id => 1, :id => 'Page_with_sections', |
|
481 | 481 | :content => { |
|
482 | 482 | :comments => 'My comments', |
|
483 | 483 | :text => "Text should not be lost", |
|
484 | 484 | :version => 3 |
|
485 | 485 | }, |
|
486 | 486 | :section => 2, |
|
487 | 487 | :section_hash => Digest::MD5.hexdigest("wrong hash") |
|
488 | 488 | end |
|
489 | 489 | end |
|
490 | 490 | end |
|
491 | 491 | assert_response :success |
|
492 | 492 | assert_template 'edit' |
|
493 | 493 | assert_select 'div.error', :text => /Data has been updated by another user/ |
|
494 | 494 | assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/ |
|
495 | 495 | assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments' |
|
496 | 496 | end |
|
497 | 497 | |
|
498 | 498 | def test_preview |
|
499 | 499 | @request.session[:user_id] = 2 |
|
500 | 500 | xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
|
501 | 501 | :content => { :comments => '', |
|
502 | 502 | :text => 'this is a *previewed text*', |
|
503 | 503 | :version => 3 } |
|
504 | 504 | assert_response :success |
|
505 | 505 | assert_template 'common/_preview' |
|
506 | 506 | assert_select 'strong', :text => /previewed text/ |
|
507 | 507 | end |
|
508 | 508 | |
|
509 | 509 | def test_preview_new_page |
|
510 | 510 | @request.session[:user_id] = 2 |
|
511 | 511 | xhr :post, :preview, :project_id => 1, :id => 'New page', |
|
512 | 512 | :content => { :text => 'h1. New page', |
|
513 | 513 | :comments => '', |
|
514 | 514 | :version => 0 } |
|
515 | 515 | assert_response :success |
|
516 | 516 | assert_template 'common/_preview' |
|
517 | 517 | assert_select 'h1', :text => /New page/ |
|
518 | 518 | end |
|
519 | 519 | |
|
520 | 520 | def test_history |
|
521 | 521 | @request.session[:user_id] = 2 |
|
522 | 522 | get :history, :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
523 | 523 | assert_response :success |
|
524 | 524 | assert_template 'history' |
|
525 | 525 | assert_not_nil assigns(:versions) |
|
526 | 526 | assert_equal 3, assigns(:versions).size |
|
527 | 527 | |
|
528 | 528 | assert_select "input[type=submit][name=commit]" |
|
529 | 529 | assert_select 'td' do |
|
530 | 530 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2' |
|
531 | 531 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate' |
|
532 | 532 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete' |
|
533 | 533 | end |
|
534 | 534 | end |
|
535 | 535 | |
|
536 | 536 | def test_history_with_one_version |
|
537 | 537 | @request.session[:user_id] = 2 |
|
538 | 538 | get :history, :project_id => 'ecookbook', :id => 'Another_page' |
|
539 | 539 | assert_response :success |
|
540 | 540 | assert_template 'history' |
|
541 | 541 | assert_not_nil assigns(:versions) |
|
542 | 542 | assert_equal 1, assigns(:versions).size |
|
543 | 543 | assert_select "input[type=submit][name=commit]", false |
|
544 | 544 | assert_select 'td' do |
|
545 | 545 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1' |
|
546 | 546 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate' |
|
547 | 547 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0 |
|
548 | 548 | end |
|
549 | 549 | end |
|
550 | 550 | |
|
551 | 551 | def test_diff |
|
552 | 552 | content = WikiPage.find(1).content |
|
553 | 553 | assert_difference 'WikiContent::Version.count', 2 do |
|
554 | 554 | content.text = "Line removed\nThis is a sample text for testing diffs" |
|
555 | 555 | content.save! |
|
556 | 556 | content.text = "This is a sample text for testing diffs\nLine added" |
|
557 | 557 | content.save! |
|
558 | 558 | end |
|
559 | 559 | |
|
560 | 560 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => content.version, :version_from => (content.version - 1) |
|
561 | 561 | assert_response :success |
|
562 | 562 | assert_template 'diff' |
|
563 | 563 | assert_select 'span.diff_out', :text => 'Line removed' |
|
564 | 564 | assert_select 'span.diff_in', :text => 'Line added' |
|
565 | 565 | end |
|
566 | 566 | |
|
567 | 567 | def test_diff_with_invalid_version_should_respond_with_404 |
|
568 | 568 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99' |
|
569 | 569 | assert_response 404 |
|
570 | 570 | end |
|
571 | 571 | |
|
572 | 572 | def test_diff_with_invalid_version_from_should_respond_with_404 |
|
573 | 573 | get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98' |
|
574 | 574 | assert_response 404 |
|
575 | 575 | end |
|
576 | 576 | |
|
577 | 577 | def test_annotate |
|
578 | 578 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
|
579 | 579 | assert_response :success |
|
580 | 580 | assert_template 'annotate' |
|
581 | 581 | |
|
582 | 582 | # Line 1 |
|
583 | 583 | assert_select 'table.annotate tr:nth-child(1)' do |
|
584 | 584 | assert_select 'th.line-num', :text => '1' |
|
585 | 585 | assert_select 'td.author', :text => /John Smith/ |
|
586 | 586 | assert_select 'td', :text => /h1\. CookBook documentation/ |
|
587 | 587 | end |
|
588 | 588 | |
|
589 | 589 | # Line 5 |
|
590 | 590 | assert_select 'table.annotate tr:nth-child(5)' do |
|
591 | 591 | assert_select 'th.line-num', :text => '5' |
|
592 | 592 | assert_select 'td.author', :text => /Redmine Admin/ |
|
593 | 593 | assert_select 'td', :text => /Some updated \[\[documentation\]\] here/ |
|
594 | 594 | end |
|
595 | 595 | end |
|
596 | 596 | |
|
597 | 597 | def test_annotate_with_invalid_version_should_respond_with_404 |
|
598 | 598 | get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99' |
|
599 | 599 | assert_response 404 |
|
600 | 600 | end |
|
601 | 601 | |
|
602 | 602 | def test_get_rename |
|
603 | 603 | @request.session[:user_id] = 2 |
|
604 | 604 | get :rename, :project_id => 1, :id => 'Another_page' |
|
605 | 605 | assert_response :success |
|
606 | 606 | assert_template 'rename' |
|
607 | 607 | |
|
608 | 608 | assert_select 'select[name=?]', 'wiki_page[parent_id]' do |
|
609 | 609 | assert_select 'option[value=""]', :text => '' |
|
610 | 610 | assert_select 'option[selected=selected]', 0 |
|
611 | 611 | end |
|
612 | 612 | end |
|
613 | 613 | |
|
614 | 614 | def test_get_rename_child_page |
|
615 | 615 | @request.session[:user_id] = 2 |
|
616 | 616 | get :rename, :project_id => 1, :id => 'Child_1' |
|
617 | 617 | assert_response :success |
|
618 | 618 | assert_template 'rename' |
|
619 | 619 | |
|
620 | 620 | assert_select 'select[name=?]', 'wiki_page[parent_id]' do |
|
621 | 621 | assert_select 'option[value=""]', :text => '' |
|
622 | 622 | assert_select 'option[value="2"][selected=selected]', :text => /Another page/ |
|
623 | 623 | end |
|
624 | 624 | end |
|
625 | 625 | |
|
626 | 626 | def test_rename_with_redirect |
|
627 | 627 | @request.session[:user_id] = 2 |
|
628 | 628 | post :rename, :project_id => 1, :id => 'Another_page', |
|
629 | 629 | :wiki_page => { :title => 'Another renamed page', |
|
630 | 630 | :redirect_existing_links => 1 } |
|
631 | 631 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
632 | 632 | wiki = Project.find(1).wiki |
|
633 | 633 | # Check redirects |
|
634 | 634 | assert_not_nil wiki.find_page('Another page') |
|
635 | 635 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
636 | 636 | end |
|
637 | 637 | |
|
638 | 638 | def test_rename_without_redirect |
|
639 | 639 | @request.session[:user_id] = 2 |
|
640 | 640 | post :rename, :project_id => 1, :id => 'Another_page', |
|
641 | 641 | :wiki_page => { :title => 'Another renamed page', |
|
642 | 642 | :redirect_existing_links => "0" } |
|
643 | 643 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
|
644 | 644 | wiki = Project.find(1).wiki |
|
645 | 645 | # Check that there's no redirects |
|
646 | 646 | assert_nil wiki.find_page('Another page') |
|
647 | 647 | end |
|
648 | 648 | |
|
649 | 649 | def test_rename_with_parent_assignment |
|
650 | 650 | @request.session[:user_id] = 2 |
|
651 | 651 | post :rename, :project_id => 1, :id => 'Another_page', |
|
652 | 652 | :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } |
|
653 | 653 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
654 | 654 | assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent |
|
655 | 655 | end |
|
656 | 656 | |
|
657 | 657 | def test_rename_with_parent_unassignment |
|
658 | 658 | @request.session[:user_id] = 2 |
|
659 | 659 | post :rename, :project_id => 1, :id => 'Child_1', |
|
660 | 660 | :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } |
|
661 | 661 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
|
662 | 662 | assert_nil WikiPage.find_by_title('Child_1').parent |
|
663 | 663 | end |
|
664 | 664 | |
|
665 | 665 | def test_get_rename_should_show_target_projects_list |
|
666 | 666 | @request.session[:user_id] = 2 |
|
667 | 667 | project = Project.find(5) |
|
668 | 668 | project.enable_module! :wiki |
|
669 | 669 | |
|
670 | 670 | get :rename, :project_id => 1, :id => 'Another_page' |
|
671 | 671 | assert_response :success |
|
672 | 672 | assert_template 'rename' |
|
673 | 673 | |
|
674 | 674 | assert_select 'select[name=?]', 'wiki_page[wiki_id]' do |
|
675 | 675 | assert_select 'option', 2 |
|
676 | 676 | assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/ |
|
677 | 677 | assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/ |
|
678 | 678 | end |
|
679 | 679 | end |
|
680 | 680 | |
|
681 | 681 | def test_rename_with_move |
|
682 | 682 | @request.session[:user_id] = 2 |
|
683 | 683 | project = Project.find(5) |
|
684 | 684 | project.enable_module! :wiki |
|
685 | 685 | |
|
686 | 686 | post :rename, :project_id => 1, :id => 'Another_page', |
|
687 | 687 | :wiki_page => { |
|
688 | 688 | :wiki_id => project.wiki.id.to_s, |
|
689 | 689 | :title => 'Another renamed page', |
|
690 | 690 | :redirect_existing_links => 1 |
|
691 | 691 | } |
|
692 | 692 | assert_redirected_to '/projects/private-child/wiki/Another_renamed_page' |
|
693 | 693 | |
|
694 | 694 | page = WikiPage.find(2) |
|
695 | 695 | assert_equal project.wiki.id, page.wiki_id |
|
696 | 696 | end |
|
697 | 697 | |
|
698 | 698 | def test_destroy_a_page_without_children_should_not_ask_confirmation |
|
699 | 699 | @request.session[:user_id] = 2 |
|
700 | 700 | delete :destroy, :project_id => 1, :id => 'Child_2' |
|
701 | 701 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
702 | 702 | end |
|
703 | 703 | |
|
704 | 704 | def test_destroy_parent_should_ask_confirmation |
|
705 | 705 | @request.session[:user_id] = 2 |
|
706 | 706 | assert_no_difference('WikiPage.count') do |
|
707 | 707 | delete :destroy, :project_id => 1, :id => 'Another_page' |
|
708 | 708 | end |
|
709 | 709 | assert_response :success |
|
710 | 710 | assert_template 'destroy' |
|
711 | 711 | assert_select 'form' do |
|
712 | 712 | assert_select 'input[name=todo][value=nullify]' |
|
713 | 713 | assert_select 'input[name=todo][value=destroy]' |
|
714 | 714 | assert_select 'input[name=todo][value=reassign]' |
|
715 | 715 | end |
|
716 | 716 | end |
|
717 | 717 | |
|
718 | 718 | def test_destroy_parent_with_nullify_should_delete_parent_only |
|
719 | 719 | @request.session[:user_id] = 2 |
|
720 | 720 | assert_difference('WikiPage.count', -1) do |
|
721 | 721 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
|
722 | 722 | end |
|
723 | 723 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
724 | 724 | assert_nil WikiPage.find_by_id(2) |
|
725 | 725 | end |
|
726 | 726 | |
|
727 | 727 | def test_destroy_parent_with_cascade_should_delete_descendants |
|
728 | 728 | @request.session[:user_id] = 2 |
|
729 | 729 | assert_difference('WikiPage.count', -4) do |
|
730 | 730 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
|
731 | 731 | end |
|
732 | 732 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
733 | 733 | assert_nil WikiPage.find_by_id(2) |
|
734 | 734 | assert_nil WikiPage.find_by_id(5) |
|
735 | 735 | end |
|
736 | 736 | |
|
737 | 737 | def test_destroy_parent_with_reassign |
|
738 | 738 | @request.session[:user_id] = 2 |
|
739 | 739 | assert_difference('WikiPage.count', -1) do |
|
740 | 740 | delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
|
741 | 741 | end |
|
742 | 742 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
743 | 743 | assert_nil WikiPage.find_by_id(2) |
|
744 | 744 | assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
|
745 | 745 | end |
|
746 | 746 | |
|
747 | 747 | def test_destroy_version |
|
748 | 748 | @request.session[:user_id] = 2 |
|
749 | 749 | assert_difference 'WikiContent::Version.count', -1 do |
|
750 | 750 | assert_no_difference 'WikiContent.count' do |
|
751 | 751 | assert_no_difference 'WikiPage.count' do |
|
752 | 752 | delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2 |
|
753 | 753 | assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history' |
|
754 | 754 | end |
|
755 | 755 | end |
|
756 | 756 | end |
|
757 | 757 | end |
|
758 | 758 | |
|
759 | 759 | def test_index |
|
760 | 760 | get :index, :project_id => 'ecookbook' |
|
761 | 761 | assert_response :success |
|
762 | 762 | assert_template 'index' |
|
763 | 763 | pages = assigns(:pages) |
|
764 | 764 | assert_not_nil pages |
|
765 | 765 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
766 | 766 | assert_equal pages.first.content.updated_on, pages.first.updated_on |
|
767 | 767 | |
|
768 | 768 | assert_select 'ul.pages-hierarchy' do |
|
769 | 769 | assert_select 'li' do |
|
770 | 770 | assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation' |
|
771 | 771 | assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image' |
|
772 | 772 | end |
|
773 | 773 | assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page' |
|
774 | 774 | end |
|
775 | 775 | end |
|
776 | 776 | |
|
777 | 777 | def test_index_should_include_atom_link |
|
778 | 778 | get :index, :project_id => 'ecookbook' |
|
779 | 779 | assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' |
|
780 | 780 | end |
|
781 | 781 | |
|
782 | 782 | def test_export_to_html |
|
783 | 783 | @request.session[:user_id] = 2 |
|
784 | 784 | get :export, :project_id => 'ecookbook' |
|
785 | 785 | |
|
786 | 786 | assert_response :success |
|
787 | 787 | assert_not_nil assigns(:pages) |
|
788 | 788 | assert assigns(:pages).any? |
|
789 | 789 | assert_equal "text/html", @response.content_type |
|
790 | 790 | |
|
791 | 791 | assert_select "a[name=?]", "CookBook_documentation" |
|
792 | 792 | assert_select "a[name=?]", "Another_page" |
|
793 | 793 | assert_select "a[name=?]", "Page_with_an_inline_image" |
|
794 | 794 | end |
|
795 | 795 | |
|
796 | 796 | def test_export_to_pdf |
|
797 | 797 | @request.session[:user_id] = 2 |
|
798 | 798 | get :export, :project_id => 'ecookbook', :format => 'pdf' |
|
799 | 799 | |
|
800 | 800 | assert_response :success |
|
801 | 801 | assert_not_nil assigns(:pages) |
|
802 | 802 | assert assigns(:pages).any? |
|
803 | 803 | assert_equal 'application/pdf', @response.content_type |
|
804 | 804 | assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition'] |
|
805 | 805 | assert @response.body.starts_with?('%PDF') |
|
806 | 806 | end |
|
807 | 807 | |
|
808 | 808 | def test_export_without_permission_should_be_denied |
|
809 | 809 | @request.session[:user_id] = 2 |
|
810 | 810 | Role.find_by_name('Manager').remove_permission! :export_wiki_pages |
|
811 | 811 | get :export, :project_id => 'ecookbook' |
|
812 | 812 | |
|
813 | 813 | assert_response 403 |
|
814 | 814 | end |
|
815 | 815 | |
|
816 | 816 | def test_date_index |
|
817 | 817 | get :date_index, :project_id => 'ecookbook' |
|
818 | 818 | |
|
819 | 819 | assert_response :success |
|
820 | 820 | assert_template 'date_index' |
|
821 | 821 | assert_not_nil assigns(:pages) |
|
822 | 822 | assert_not_nil assigns(:pages_by_date) |
|
823 | 823 | |
|
824 | 824 | assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1' |
|
825 | 825 | end |
|
826 | 826 | |
|
827 | 827 | def test_not_found |
|
828 | 828 | get :show, :project_id => 999 |
|
829 | 829 | assert_response 404 |
|
830 | 830 | end |
|
831 | 831 | |
|
832 | 832 | def test_protect_page |
|
833 | 833 | page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
|
834 | 834 | assert !page.protected? |
|
835 | 835 | @request.session[:user_id] = 2 |
|
836 | 836 | post :protect, :project_id => 1, :id => page.title, :protected => '1' |
|
837 | 837 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
|
838 | 838 | assert page.reload.protected? |
|
839 | 839 | end |
|
840 | 840 | |
|
841 | 841 | def test_unprotect_page |
|
842 | 842 | page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
|
843 | 843 | assert page.protected? |
|
844 | 844 | @request.session[:user_id] = 2 |
|
845 | 845 | post :protect, :project_id => 1, :id => page.title, :protected => '0' |
|
846 | 846 | assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
|
847 | 847 | assert !page.reload.protected? |
|
848 | 848 | end |
|
849 | 849 | |
|
850 | 850 | def test_show_page_with_edit_link |
|
851 | 851 | @request.session[:user_id] = 2 |
|
852 | 852 | get :show, :project_id => 1 |
|
853 | 853 | assert_response :success |
|
854 | 854 | assert_template 'show' |
|
855 | 855 | assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit' |
|
856 | 856 | end |
|
857 | 857 | |
|
858 | 858 | def test_show_page_without_edit_link |
|
859 | 859 | @request.session[:user_id] = 4 |
|
860 | 860 | get :show, :project_id => 1 |
|
861 | 861 | assert_response :success |
|
862 | 862 | assert_template 'show' |
|
863 | 863 | assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0 |
|
864 | 864 | end |
|
865 | 865 | |
|
866 | 866 | def test_show_pdf |
|
867 | 867 | @request.session[:user_id] = 2 |
|
868 | 868 | get :show, :project_id => 1, :format => 'pdf' |
|
869 | 869 | assert_response :success |
|
870 | 870 | assert_not_nil assigns(:page) |
|
871 | 871 | assert_equal 'application/pdf', @response.content_type |
|
872 | 872 | assert_equal 'attachment; filename="CookBook_documentation.pdf"', |
|
873 | 873 | @response.headers['Content-Disposition'] |
|
874 | 874 | end |
|
875 | 875 | |
|
876 | 876 | def test_show_html |
|
877 | 877 | @request.session[:user_id] = 2 |
|
878 | 878 | get :show, :project_id => 1, :format => 'html' |
|
879 | 879 | assert_response :success |
|
880 | 880 | assert_not_nil assigns(:page) |
|
881 | 881 | assert_equal 'text/html', @response.content_type |
|
882 | 882 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
883 | 883 | @response.headers['Content-Disposition'] |
|
884 | 884 | assert_select 'h1', :text => /CookBook documentation/ |
|
885 | 885 | end |
|
886 | 886 | |
|
887 | 887 | def test_show_versioned_html |
|
888 | 888 | @request.session[:user_id] = 2 |
|
889 | 889 | get :show, :project_id => 1, :format => 'html', :version => 2 |
|
890 | 890 | assert_response :success |
|
891 | 891 | assert_not_nil assigns(:content) |
|
892 | 892 | assert_equal 2, assigns(:content).version |
|
893 | 893 | assert_equal 'text/html', @response.content_type |
|
894 | 894 | assert_equal 'attachment; filename="CookBook_documentation.html"', |
|
895 | 895 | @response.headers['Content-Disposition'] |
|
896 | 896 | assert_select 'h1', :text => /CookBook documentation/ |
|
897 | 897 | end |
|
898 | 898 | |
|
899 | 899 | def test_show_txt |
|
900 | 900 | @request.session[:user_id] = 2 |
|
901 | 901 | get :show, :project_id => 1, :format => 'txt' |
|
902 | 902 | assert_response :success |
|
903 | 903 | assert_not_nil assigns(:page) |
|
904 | 904 | assert_equal 'text/plain', @response.content_type |
|
905 | 905 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
906 | 906 | @response.headers['Content-Disposition'] |
|
907 | 907 | assert_include 'h1. CookBook documentation', @response.body |
|
908 | 908 | end |
|
909 | 909 | |
|
910 | 910 | def test_show_versioned_txt |
|
911 | 911 | @request.session[:user_id] = 2 |
|
912 | 912 | get :show, :project_id => 1, :format => 'txt', :version => 2 |
|
913 | 913 | assert_response :success |
|
914 | 914 | assert_not_nil assigns(:content) |
|
915 | 915 | assert_equal 2, assigns(:content).version |
|
916 | 916 | assert_equal 'text/plain', @response.content_type |
|
917 | 917 | assert_equal 'attachment; filename="CookBook_documentation.txt"', |
|
918 | 918 | @response.headers['Content-Disposition'] |
|
919 | 919 | assert_include 'h1. CookBook documentation', @response.body |
|
920 | 920 | end |
|
921 | 921 | |
|
922 | 922 | def test_edit_unprotected_page |
|
923 | 923 | # Non members can edit unprotected wiki pages |
|
924 | 924 | @request.session[:user_id] = 4 |
|
925 | 925 | get :edit, :project_id => 1, :id => 'Another_page' |
|
926 | 926 | assert_response :success |
|
927 | 927 | assert_template 'edit' |
|
928 | 928 | end |
|
929 | 929 | |
|
930 | 930 | def test_edit_protected_page_by_nonmember |
|
931 | 931 | # Non members cannot edit protected wiki pages |
|
932 | 932 | @request.session[:user_id] = 4 |
|
933 | 933 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
934 | 934 | assert_response 403 |
|
935 | 935 | end |
|
936 | 936 | |
|
937 | 937 | def test_edit_protected_page_by_member |
|
938 | 938 | @request.session[:user_id] = 2 |
|
939 | 939 | get :edit, :project_id => 1, :id => 'CookBook_documentation' |
|
940 | 940 | assert_response :success |
|
941 | 941 | assert_template 'edit' |
|
942 | 942 | end |
|
943 | 943 | |
|
944 | 944 | def test_history_of_non_existing_page_should_return_404 |
|
945 | 945 | get :history, :project_id => 1, :id => 'Unknown_page' |
|
946 | 946 | assert_response 404 |
|
947 | 947 | end |
|
948 | 948 | |
|
949 | 949 | def test_add_attachment |
|
950 | 950 | @request.session[:user_id] = 2 |
|
951 | 951 | assert_difference 'Attachment.count' do |
|
952 | 952 | post :add_attachment, :project_id => 1, :id => 'CookBook_documentation', |
|
953 | 953 | :attachments => { |
|
954 | 954 | '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), |
|
955 | 955 | 'description' => 'test file'} |
|
956 | 956 | } |
|
957 | 957 | end |
|
958 | 958 | attachment = Attachment.order('id DESC').first |
|
959 | 959 | assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container |
|
960 | 960 | end |
|
961 | 961 | end |
General Comments 0
You need to be logged in to leave comments.
Login now