Defect #20910 » 0002-Nest-the-exported-html-table-of-contents.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
content << "<ul class=\"pages-hierarchy\">\n"
|
||
|
pages[node].each do |page|
|
||
|
content << "<li>"
|
||
|
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
|
||
|
if controller.controller_name == 'wiki' && controller.action_name == 'export'
|
||
|
href = "##{page.title}"
|
||
|
else
|
||
|
href = {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil}
|
||
|
end
|
||
|
content << link_to(h(page.pretty_title), href,
|
||
|
:title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
||
|
content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
|
||
|
content << "</li>\n"
|
||
| app/views/wiki/export_multiple.html.erb | ||
|---|---|---|
|
<body>
|
||
|
<strong><%= l(:label_index_by_title) %></strong>
|
||
|
<ul>
|
||
|
<% @pages.each do |page| %>
|
||
|
<li><a href="#<%= page.title %>"><%= page.pretty_title %></a></li>
|
||
|
<% end %>
|
||
|
</ul>
|
||
|
<%= render_page_hierarchy(@pages.group_by(&:parent_id), nil, :timestamp => true) %>
|
||
|
<% @pages.each do |page| %>
|
||
|
<hr />
|
||
| test/helpers/application_helper_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_render_page_hierarchy
|
||
|
parent_page = WikiPage.find(1)
|
||
|
child_page = WikiPage.find_by(parent_id: parent_page.id)
|
||
|
pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
|
||
|
result = render_page_hierarchy(pages_by_parent_id, nil)
|
||
|
assert_select_in result, 'ul.pages-hierarchy li a[href=?]', project_wiki_page_path(project_id: parent_page.project, id: parent_page.title, version: nil )
|
||
|
assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', project_wiki_page_path(project_id: child_page.project, id: child_page.title, version: nil )
|
||
|
end
|
||
|
def test_render_page_hierarchy_with_options_timestamp_should_include_timestamp
|
||
|
parent_page = WikiPage.find(1)
|
||
|
child_page = WikiPage.find_by(parent_id: parent_page.id)
|
||
|
pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
|
||
|
result = render_page_hierarchy(pages_by_parent_id, nil, :timestamp => true)
|
||
|
assert_select_in result, 'ul.pages-hierarchy li a[title=?]', l(:label_updated_time, distance_of_time_in_words(Time.now, parent_page.updated_on))
|
||
|
assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[title=?]', l(:label_updated_time, distance_of_time_in_words(Time.now, child_page.updated_on))
|
||
|
end
|
||
|
def test_render_page_hierarchy_when_action_is_export
|
||
|
parent_page = WikiPage.find(1)
|
||
|
child_page = WikiPage.find_by(parent_id: parent_page.id)
|
||
|
pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
|
||
|
# Change controller and action using stub
|
||
|
controller.stubs(:controller_name).returns('wiki')
|
||
|
controller.stubs(:action_name).returns("export")
|
||
|
result = render_page_hierarchy(pages_by_parent_id, nil)
|
||
|
assert_select_in result, 'ul.pages-hierarchy li a[href=?]', "##{parent_page.title}"
|
||
|
assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}"
|
||
|
end
|
||
|
def test_avatar_enabled
|
||
|
tag_for_anonymous_re = %r{src="/images/anonymous.png(\?\d+)?"}
|
||
|
with_settings :gravatar_enabled => '1' do
|
||