##// END OF EJS Templates
Hiding the View Differences button when a wiki page's history only has one version....
Eric Davis -
r1748:af6b01f55d96
parent child
Show More
@@ -1,35 +1,35
1 1 <h2><%= @page.pretty_title %></h2>
2 2
3 3 <h3><%= l(:label_history) %></h3>
4 4
5 5 <% form_tag({:action => "diff"}, :method => :get) do %>
6 6 <table class="list">
7 7 <thead><tr>
8 8 <th>#</th>
9 9 <th></th>
10 10 <th></th>
11 11 <th><%= l(:field_updated_on) %></th>
12 12 <th><%= l(:field_author) %></th>
13 13 <th><%= l(:field_comments) %></th>
14 14 <th></th>
15 15 </tr></thead>
16 16 <tbody>
17 17 <% show_diff = @versions.size > 1 %>
18 18 <% line_num = 1 %>
19 19 <% @versions.each do |ver| %>
20 20 <tr class="<%= cycle("odd", "even") %>">
21 21 <td class="id"><%= link_to ver.version, :action => 'index', :page => @page.title, :version => ver.version %></td>
22 22 <td class="checkbox"><%= radio_button_tag('version', ver.version, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < @versions.size) %></td>
23 23 <td class="checkbox"><%= radio_button_tag('version_from', ver.version, (line_num==2), :id => "cbto-#{line_num}", :onclick => "if ($('cb-#{line_num}').checked==true || $('version_from').value > #{ver.version}) {$('cb-#{line_num-1}').checked=true;}") if show_diff && (line_num > 1) %></td>
24 24 <td align="center"><%= format_time(ver.updated_on) %></td>
25 25 <td><em><%= ver.author ? ver.author.name : "anonyme" %></em></td>
26 26 <td><%=h ver.comments %></td>
27 27 <td align="center"><%= link_to l(:button_annotate), :action => 'annotate', :page => @page.title, :version => ver.version %></td>
28 28 </tr>
29 29 <% line_num += 1 %>
30 30 <% end %>
31 31 </tbody>
32 32 </table>
33 <%= submit_tag l(:label_view_diff), :class => 'small' %>
33 <%= submit_tag l(:label_view_diff), :class => 'small' if show_diff %>
34 34 <span class="pagination"><%= pagination_links_full @version_pages, @version_count, :page_param => :p %></span>
35 35 <% end %>
@@ -1,244 +1,254
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'wiki_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class WikiController; def rescue_action(e) raise e end; end
23 23
24 24 class WikiControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26 26
27 27 def setup
28 28 @controller = WikiController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show_start_page
35 35 get :index, :id => 'ecookbook'
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39 39
40 40 # child_pages macro
41 41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 42 :child => { :tag => 'li',
43 43 :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
44 44 :content => 'Page with an inline image' } }
45 45 end
46 46
47 47 def test_show_page_with_name
48 48 get :index, :id => 1, :page => 'Another_page'
49 49 assert_response :success
50 50 assert_template 'show'
51 51 assert_tag :tag => 'h1', :content => /Another page/
52 52 # Included page with an inline image
53 53 assert_tag :tag => 'p', :content => /This is an inline image/
54 54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 55 :alt => 'This is a logo' }
56 56 end
57 57
58 58 def test_show_unexistent_page_without_edit_right
59 59 get :index, :id => 1, :page => 'Unexistent page'
60 60 assert_response 404
61 61 end
62 62
63 63 def test_show_unexistent_page_with_edit_right
64 64 @request.session[:user_id] = 2
65 65 get :index, :id => 1, :page => 'Unexistent page'
66 66 assert_response :success
67 67 assert_template 'edit'
68 68 end
69 69
70 70 def test_create_page
71 71 @request.session[:user_id] = 2
72 72 post :edit, :id => 1,
73 73 :page => 'New page',
74 74 :content => {:comments => 'Created the page',
75 75 :text => "h1. New page\n\nThis is a new page",
76 76 :version => 0}
77 77 assert_redirected_to 'wiki/ecookbook/New_page'
78 78 page = Project.find(1).wiki.find_page('New page')
79 79 assert !page.new_record?
80 80 assert_not_nil page.content
81 81 assert_equal 'Created the page', page.content.comments
82 82 end
83 83
84 84 def test_preview
85 85 @request.session[:user_id] = 2
86 86 xhr :post, :preview, :id => 1, :page => 'CookBook_documentation',
87 87 :content => { :comments => '',
88 88 :text => 'this is a *previewed text*',
89 89 :version => 3 }
90 90 assert_response :success
91 91 assert_template 'common/_preview'
92 92 assert_tag :tag => 'strong', :content => /previewed text/
93 93 end
94 94
95 95 def test_preview_new_page
96 96 @request.session[:user_id] = 2
97 97 xhr :post, :preview, :id => 1, :page => 'New page',
98 98 :content => { :text => 'h1. New page',
99 99 :comments => '',
100 100 :version => 0 }
101 101 assert_response :success
102 102 assert_template 'common/_preview'
103 103 assert_tag :tag => 'h1', :content => /New page/
104 104 end
105 105
106 106 def test_history
107 107 get :history, :id => 1, :page => 'CookBook_documentation'
108 108 assert_response :success
109 109 assert_template 'history'
110 110 assert_not_nil assigns(:versions)
111 111 assert_equal 3, assigns(:versions).size
112 assert_select "input[type=submit][name=commit]"
112 113 end
113
114
115 def test_history_with_one_version
116 get :history, :id => 1, :page => 'Another_page'
117 assert_response :success
118 assert_template 'history'
119 assert_not_nil assigns(:versions)
120 assert_equal 1, assigns(:versions).size
121 assert_select "input[type=submit][name=commit]", false
122 end
123
114 124 def test_diff
115 125 get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
116 126 assert_response :success
117 127 assert_template 'diff'
118 128 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
119 129 :content => /updated/
120 130 end
121 131
122 132 def test_annotate
123 133 get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2
124 134 assert_response :success
125 135 assert_template 'annotate'
126 136 # Line 1
127 137 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
128 138 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
129 139 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
130 140 # Line 2
131 141 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
132 142 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
133 143 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
134 144 end
135 145
136 146 def test_rename_with_redirect
137 147 @request.session[:user_id] = 2
138 148 post :rename, :id => 1, :page => 'Another_page',
139 149 :wiki_page => { :title => 'Another renamed page',
140 150 :redirect_existing_links => 1 }
141 151 assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
142 152 wiki = Project.find(1).wiki
143 153 # Check redirects
144 154 assert_not_nil wiki.find_page('Another page')
145 155 assert_nil wiki.find_page('Another page', :with_redirect => false)
146 156 end
147 157
148 158 def test_rename_without_redirect
149 159 @request.session[:user_id] = 2
150 160 post :rename, :id => 1, :page => 'Another_page',
151 161 :wiki_page => { :title => 'Another renamed page',
152 162 :redirect_existing_links => "0" }
153 163 assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
154 164 wiki = Project.find(1).wiki
155 165 # Check that there's no redirects
156 166 assert_nil wiki.find_page('Another page')
157 167 end
158 168
159 169 def test_destroy
160 170 @request.session[:user_id] = 2
161 171 post :destroy, :id => 1, :page => 'CookBook_documentation'
162 172 assert_redirected_to 'wiki/ecookbook/Page_index/special'
163 173 end
164 174
165 175 def test_page_index
166 176 get :special, :id => 'ecookbook', :page => 'Page_index'
167 177 assert_response :success
168 178 assert_template 'special_page_index'
169 179 pages = assigns(:pages)
170 180 assert_not_nil pages
171 181 assert_equal Project.find(1).wiki.pages.size, pages.size
172 182
173 183 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
174 184 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
175 185 :content => 'CookBook documentation' },
176 186 :child => { :tag => 'ul',
177 187 :child => { :tag => 'li',
178 188 :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
179 189 :content => 'Page with an inline image' } } } },
180 190 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' },
181 191 :content => 'Another page' } }
182 192 end
183 193
184 194 def test_not_found
185 195 get :index, :id => 999
186 196 assert_response 404
187 197 end
188 198
189 199 def test_protect_page
190 200 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
191 201 assert !page.protected?
192 202 @request.session[:user_id] = 2
193 203 post :protect, :id => 1, :page => page.title, :protected => '1'
194 204 assert_redirected_to 'wiki/ecookbook/Another_page'
195 205 assert page.reload.protected?
196 206 end
197 207
198 208 def test_unprotect_page
199 209 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
200 210 assert page.protected?
201 211 @request.session[:user_id] = 2
202 212 post :protect, :id => 1, :page => page.title, :protected => '0'
203 213 assert_redirected_to 'wiki/ecookbook'
204 214 assert !page.reload.protected?
205 215 end
206 216
207 217 def test_show_page_with_edit_link
208 218 @request.session[:user_id] = 2
209 219 get :index, :id => 1
210 220 assert_response :success
211 221 assert_template 'show'
212 222 assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
213 223 end
214 224
215 225 def test_show_page_without_edit_link
216 226 @request.session[:user_id] = 4
217 227 get :index, :id => 1
218 228 assert_response :success
219 229 assert_template 'show'
220 230 assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
221 231 end
222 232
223 233 def test_edit_unprotected_page
224 234 # Non members can edit unprotected wiki pages
225 235 @request.session[:user_id] = 4
226 236 get :edit, :id => 1, :page => 'Another_page'
227 237 assert_response :success
228 238 assert_template 'edit'
229 239 end
230 240
231 241 def test_edit_protected_page_by_nonmember
232 242 # Non members can't edit protected wiki pages
233 243 @request.session[:user_id] = 4
234 244 get :edit, :id => 1, :page => 'CookBook_documentation'
235 245 assert_response 403
236 246 end
237 247
238 248 def test_edit_protected_page_by_member
239 249 @request.session[:user_id] = 2
240 250 get :edit, :id => 1, :page => 'CookBook_documentation'
241 251 assert_response :success
242 252 assert_template 'edit'
243 253 end
244 254 end
General Comments 0
You need to be logged in to leave comments. Login now