20910-v2.patch

Go MAEDA, 2019-05-06 15:59

Download (4.08 KB)

View differences:

app/helpers/application_helper.rb
371 371
      content << "<ul class=\"pages-hierarchy\">\n"
372 372
      pages[node].each do |page|
373 373
        content << "<li>"
374
        content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
374
        if controller.controller_name == 'wiki' && controller.action_name == 'export'
375
          href = "##{page.title}"
376
        else
377
          href = {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil}
378
        end
379
        content << link_to(h(page.pretty_title), href,
375 380
                           :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
376 381
        content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
377 382
        content << "</li>\n"
app/views/wiki/export_multiple.html.erb
18 18
<body>
19 19

  
20 20
<strong><%= l(:label_index_by_title) %></strong>
21
<ul>
22
<% @pages.each do |page| %>
23
    <li><a href="#<%= page.title %>"><%= page.pretty_title %></a></li>
24
<% end %>
25
</ul>
21
<%= render_page_hierarchy(@pages.group_by(&:parent_id), nil, :timestamp => true) %>
26 22

  
27 23
<% @pages.each do |page| %>
28 24
<hr />
test/helpers/application_helper_test.rb
1463 1463
    end
1464 1464
  end
1465 1465

  
1466
  def test_render_page_hierarchy
1467
    parent_page = WikiPage.find(1)
1468
    child_page = WikiPage.find_by(parent_id: parent_page.id)
1469
    pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
1470
    result = render_page_hierarchy(pages_by_parent_id, nil)
1471
    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 )
1472
    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 )
1473
  end
1474

  
1475
  def test_render_page_hierarchy_with_options_timestamp_should_include_timestamp
1476
    parent_page = WikiPage.find(1)
1477
    child_page = WikiPage.find_by(parent_id: parent_page.id)
1478
    pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
1479
    result = render_page_hierarchy(pages_by_parent_id, nil, :timestamp => true)
1480
    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))
1481
    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))
1482
  end
1483

  
1484
  def test_render_page_hierarchy_when_action_is_export
1485
    parent_page = WikiPage.find(1)
1486
    child_page = WikiPage.find_by(parent_id: parent_page.id)
1487
    pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
1488

  
1489
    # Change controller and action using stub
1490
    controller.stubs(:controller_name).returns('wiki')
1491
    controller.stubs(:action_name).returns("export")
1492

  
1493
    result = render_page_hierarchy(pages_by_parent_id, nil)
1494
    assert_select_in result, 'ul.pages-hierarchy li a[href=?]', "##{parent_page.title}"
1495
    assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}"
1496
  end
1497

  
1466 1498
  def test_avatar_with_user
1467 1499
    with_settings :gravatar_enabled => '1' do
1468 1500
      assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar(User.find_by_mail('jsmith@somenet.foo'))